Run AI Agents on a Schedule and From Webhooks: A Practical Guide

Run AI agents on a cron schedule in your time zone or from GitHub, Linear and generic webhooks, with the payload folded into the task and daily run caps.

· 5 min read

GUIDE

To run an AI agent on its own, you give it a trigger: that is what turns a one-off task into a job your company runs by itself. On Lark there are three kinds:

  • Schedule: a cron expression read in your time zone, such as 0 7 * * 1-5 for weekdays at 07:00.
  • Webhook: a URL another service POSTs to. What it sends becomes part of the agent's task.
  • Run: starts when another agent's run finishes, with that run as the payload.

Each triggered run happens on the agent's own cloud computer, is billed like any other run, and stops at the trigger's daily cap and your monthly budget. The rest of this guide covers each kind in detail.

Running an AI agent on a schedule

A schedule trigger uses a standard five-field cron expression: minute, hour, day of month, month, day of week. @daily-style shorthands work too.

| Schedule | Cron | |---|---| | Weekdays at 07:00 | 0 7 * * 1-5 | | Every night at 02:00 | 0 2 * * * | | Every 30 minutes | */30 * * * * | | Weekdays at 09:00 | 0 9 * * 1-5 | | Mondays at 08:00 | 0 8 * * 1 |

Time zones

Each schedule is read in an IANA time zone, such as America/New_York or Europe/Berlin. Set it, and 07:00 means 07:00 where you are, not 07:00 UTC. If you leave it out over the API, the default is UTC.

Here's a nightly schedule created with the TypeScript SDK, from the docs:

const nightly = await lark.triggers.create("coder", {
  name: "nightly-tests", kind: "schedule", schedule: "0 2 * * *", timezone: "America/New_York",
  prompt: "Run the test suite and fix anything that's red.",
});

Scheduled runs that remember

A schedule is most useful when the agent knows what it did last time. Agents can keep their machine between runs, and Lark's always-on presets keep a NOTES.md file as memory: they read it first, act only on what's new, and update it before they finish. That's how the morning brief compares today's numbers with yesterday's, and how the competitor pricing page monitor reports only real changes. {{now}} in the prompt becomes the time of the run.

Triggering an AI agent from a webhook

A webhook trigger gives you a URL and a secret (shown once). Hand both to the service that sends events. When it POSTs, Lark answers 202 with the id of the queued run, before the run starts work.

What the payload becomes

The trigger's prompt is a template. When a webhook arrives:

  • {{payload}} becomes the whole request body (if the prompt doesn't use it, the body is appended)
  • {{payload.a.b}} becomes one value from it
  • {{event}} becomes the event name
  • {{now}} becomes the time

So a lead webhook can become a task like this:

New lead: {{payload.name}} at {{payload.company}}. Research the company and write a brief.

Bodies can be up to 1 MB.

Generic webhooks from any service

The default source is generic: anything that can send an HTTP POST. The sender signs the raw body with the trigger's secret in an X-Lark-Signature header:

BODY='{"name":"Ada Lovelace","company":"Analytical Engines"}'
SIG="sha256=$(printf '%s' "$BODY" | openssl dgst -sha256 -hmac "$TRIGGER_SECRET" -hex | sed 's/.* //')"
curl -X POST "$TRIGGER_URL" -H "content-type: application/json" -H "X-Lark-Signature: $SIG" -d "$BODY"
# → 202 {"runId": "run_…", "status": "queued"}

If the sender can't sign (some form builders and no-code tools can't), POST to <url>/<secret> instead. The lead research agent uses a generic webhook from your sign-up form or CRM.

GitHub webhooks

Set the source to github and Lark checks GitHub's own signature scheme and names events GitHub's way. Filter with events, for example pull_request.opened or workflow_run.completed. Two settings matter for public repositories:

  • githubAuthors: team (the default for new GitHub triggers) lets only the repository's owners, members and collaborators start a run, so a stranger's pull request or comment is ignored. anyone accepts every matching event.
  • ignoreBots: skips events sent by bots. On by default.

GitHub's ping is ignored. The CI fixer runs on workflow_run.completed, and P-Rex, the PR reviewer, runs when a pull request is ready for review.

Linear, Stripe and Sentry webhooks

Set the source to linear, stripe or sentry. These services make their own signing secret: paste it into the trigger as its signing secret. Until it has one, the trigger stays off. Event filters can use wildcards, such as invoice.* for Stripe. The Linear ticket to pull request agent starts on Issue.create with a prompt like:

Linear issue {{payload.data.identifier}}: "{{payload.data.title}}". {{payload.data.url}}

{{payload.data.description}}

Jira webhooks

Set the source to jira and events to jira:issue_created (or jira:issue_updated, comment_created). In Jira, open Settings → System → WebHooks → Create a WebHook, paste the trigger's URL, put the trigger's signing secret in Secret, and tick Issue → created. Add a JQL filter like project = SUP to limit it to one project. Lark checks Jira's signature and gives the run the issue in plain form, with its description as text:

Jira issue {{payload.issue.key}} ({{payload.issue.type}}, {{payload.issue.priority}}): "{{payload.issue.summary}}". {{payload.issue.url}}

{{payload.issue.description}}

Chaining agents with run triggers

A run trigger starts one agent when another agent's run finishes. Choose which outcomes count (succeeded, failed, cancelled; succeeded by default), and use {{payload.run.result}} to pass the first agent's result into the second agent's task.

Run limits per day

Every trigger has maxRunsPerDay: the most runs it may start in any 24 hours, from 1 to 1,000, default 24. The ready-made agents set their own: one a day for the morning brief, 48 for a check every 30 minutes, 100 for new leads.

What the webhook URL answers tells the sender what happened:

| Response | Meaning | |---|---| | 202 | A run was queued | | 200 with ignored | An event the trigger doesn't want, a bot event, or GitHub's ping | | 401 | Unknown trigger or bad signature | | 402 | Your budget or plan stops the run | | 409 | The trigger is paused | | 413 | The body is too large | | 429 | Too many requests, or the daily cap is reached |

A repeated delivery starts only one run. Inbound trigger webhooks are also limited to 120 requests per minute per trigger. How many agents run at once depends on your plan; extra runs queue and start as others finish.

Pausing, testing and firing by hand

Triggers can be turned on and off. Ready-made agents' triggers start paused, so you can check the instructions before anything fires. To test, fire a trigger now, whether or not it's on, with POST /api/triggers/:id/fire. Each trigger also shows when it will next run, when it last fired, how many runs it started in the last day, and, if the last fire didn't start a run, why.

FAQ

What time zone does my schedule use?

The one you set on the trigger, as an IANA name like America/Los_Angeles. Over the API, if you don't set one, it's UTC.

Can I filter which GitHub events start a run?

Yes. List them in events, such as pull_request.opened. Leave it empty for all events. Use githubAuthors to decide who may start a run.

What happens if a webhook fires hundreds of times?

The trigger starts at most maxRunsPerDay runs in any 24 hours and answers 429 after that. Your monthly budget is a second stop: past it, the answer is 402.

Are triggered runs billed differently?

No. They cost their model tokens and machine time like any run, and Pro and Team include webhooks and schedules around the clock. See how much AI agents cost to run and the pricing.

Ready to put an agent on a timer? Start free.

KEEP READING

Hand this job to Lark tonighttoday

One less loop for you to run: each Lark agent owns its job on its own cloud computer, starts on a schedule or when something happens, and brings you in only to approve.

Start free