Skip to Content
Levain LabsLevain Labs

Automation

Run agents on a schedule or in response to external events.

A run is the unit of agent execution. This guide covers the two ways to fire one without a human in the loop: schedules that run on a cron, and triggers that fire on events from your connected integrations.

Where to set them up

Every agent's detail page has a Triggers card. It collapses rows you can expand on demand:

  • API call — always on once the agent is active. The endpoint to call lives behind the row.
  • Schedule — cron-style schedules. The row badge shows how many are active or paused at a glance.
  • Inbound webhook — a unique URL your own systems can POST JSON to whenever something they observe should wake the agent.
  • Slack messages — route a Slack channel, or direct messages to the Levain app, to this agent.
  • GitHub events — runs triggered by GitHub activity, available whenever the GitHub integration is connected.
  • App events — runs triggered by platform-app events (Stripe, Shopify, …), available whenever a platform app is connected.

Open the row you care about, fill in the form, save. The Triggers card shows the current state alongside the agent so you never have to remember what's wired up where.

Running as you

A schedule or an event trigger can run as the person who creates it (Run as me in the form, run_as on the API). Every run it starts then acts for you and reads your person memory and rules, exactly as a run you open would. You can only make one run as yourself, from a signed-in session — never as someone else, and never with an API key. The option is set at creation and shown on the row; without it a schedule or trigger runs with no person scope. What it does and when is yours to change: other members can only switch it off or delete it. If you leave the workspace, its runs stop acting for you.

Schedules

A schedule attaches a cron expression to an agent. Levain fires a run at each matching time and reports its outcome alongside any manually triggered run.

When you create a schedule, you set:

  • A cron expression, evaluated in the timezone you pick (defaults to UTC).
  • What to send the agent — either a prompt for single-turn instructions, or a structured payload matching the agent's state schema.
  • An activity window, optionally (skip_if_active_within_minutes): a due fire is skipped while any run of the agent started within that many minutes, so the scheduled run lands that long after the agent's last activity instead of stacking onto work a trigger or a person just set off.
  • Run as me, optionally (run_as): see Running as you.

Pause a schedule from its row in the Triggers card to stop new runs without losing the setup. Flip it back on when you're ready, or delete it outright when you no longer need it.

Levain also pauses a schedule itself when firing it again could only fail, and the row says why (paused_reason on the API):

  • insufficient_balance, extra_usage_limit_hit, workspace_cap_hit: the workspace's credit or a monthly limit ran out. The schedule resumes when you top up or raise the limit, or on the 1st.
  • model_account_limit: the model account behind the agent refused for want of credit, such as the Claude login on a self-hosted runtime hitting its spend limit. The schedule retries once an hour (resume_at); flip it back on to retry now.
  • no_published_version: the agent has no published version to run, or the schedule is pinned to a draft. Publish a version, then flip the schedule back on.

A trigger isn't paused on the model account's limit, and its event isn't lost to it either. When the refusal says when the limit resets, the run the event started waits (waiting_for: model_limit on the run's queue, with resumes_at) and starts again a couple of minutes after the reset. It keeps the agent's turn while it waits, so on an agent that runs one turn at a time, later events and messages queue behind it. The run fails as any other would when the refusal names no reset time or one more than six hours away, or when the account is still at its limit a day after the run first waited. A run a person starts doesn't wait: it fails, and the error shows in the conversation.

Each pause on a failed run sends one agent_runs_failing notification; see Runs → Notifications.

Inbound webhook

When the event source is your own system — a monitoring script, a CI pipeline, an internal service — give it the agent's inbound webhook. Creating one mints a unique URL with an embedded secret (shown once; rotate it any time from the same row). POST a JSON body to it and the agent runs with that body as its user message and as the payload state field:

curl -X POST '<webhook url>' \
  -H 'Content-Type: application/json' \
  -d '{"message": "PR #42 became mergeable", "pr": 42}'

Two top-level keys are special: message sets the user message the agent sees, and session_id continues one of the agent's existing sessions as a new turn instead of starting a fresh run. Deliveries are rate-limited per agent, and bodies are capped at 1 MB.

Slack messages

By default, Slack mentions and DMs go to the Levain agent. To send them to one of your own agents instead, add a Slack route in the Slack messages section of its Triggers card: a toggle for DMs, and a channel picker. The picker lists public channels and the private channels the Levain app has been invited to. A channel has one agent and the DM surface has one agent per Slack install.

In a routed channel a plain message starts a conversation; no mention is needed. Unrouted channels still need a mention, and thread replies behave the same either way. If the routed agent is deleted or inactive, messages fall back to the Levain agent. Manage routes with the API: list, create, delete.

GitHub events

Once you've connected the GitHub integration, the GitHub events row lists every event type Levain can listen for — pull requests, pushes, issue comments, new issues, and workflow runs — and lets you turn each one into a trigger with one click. The event payload becomes the run's input, so the agent sees the same shape GitHub delivers.

An event type is often broader than what the agent should wake for: pull_request fires on every label and review request as well as on opened, and workflow_run fires for every workflow in the installation. A trigger can carry an event filter that narrows it to the deliveries that matter. The filter is a JSON object whose keys are dotted paths into the payload and whose values are a value or a list of values; every key must match, a list matches any of its entries, and a path the payload does not have matches only null:

{ "action": ["opened", "synchronize"], "pull_request.draft": true }

wakes the agent for new draft pull requests and new pushes to them, and

{
  "action": "completed",
  "workflow.name": "Deploy",
  "workflow_run.head_branch": "production"
}

wakes it once per finished production deploy, with workflow_run.conclusion in the payload saying how it went. workflow.name is the workflow's name as its file declares it; workflow_run.name is the run's title, which a workflow's run-name rewrites per run. Set a filter when you add the trigger, or later from the slider icon on its row: the common fields (actions, draft state, workflow name, branch, conclusion) are offered as fields, and any other payload path goes in the JSON underneath. The API and the MCP server's create_agent_trigger and update_agent_trigger tools take the same object; a delivery a filter rejects costs nothing.

Each trigger's row shows its last delivery: when it arrived, whether it fired a run, was filtered or was skipped, and the one-line event it carried, so a trigger that stays quiet shows what it is turning down.

An agent with a persistent workspace runs one turn at a time, and each delivery normally gets a turn of its own. When one turn could handle several — four pull requests opened in the same minute, say — declare a deliveries state variable in the recipe. A trigger delivery or a scheduled fire then starts with every trigger delivery waiting in the agent's queue folded into that list: each entry carries the delivery's payload and event fields (github_event and delivery_id for GitHub) plus the run_id and trigger_id it arrived as, the turn's own delivery first. The deliveries taken this way show in the run list as cancelled, linking to the run that handled them. A person's message is never folded in; it keeps its own turn. An agent set to run turns at the same time (see persistent workspaces) folds in only what its cap holds back: below the cap each delivery starts its own turn as it arrives, and two deliveries for the same subject still take turns.

You can wire several events to the same agent, and the same event to several agents. Triggers and the integration they belong to are linked: disconnecting the integration drops the triggers, and reconnecting it later means rebuilding them.

App events

Platform apps (Stripe, Shopify, Google Ads, Meta Ads) deliver events to your workspace in real time — a failed payment, a new order, a checkout abandoned. You can fire an agent on any of them.

Once a platform app is connected, an App events row appears in the agent's Triggers card. Expand it to see the available event types for that provider, pick one, and map the incoming payload to the agent's input schema. Examples:

ProviderEventTypical use
Stripeinvoice.payment_failedDunning — email the customer, retry payment
Shopifyorders/createOrder operations — tag, fulfil, notify
Shopifycheckouts/createAbandoned-checkout recovery
Google Ads / Meta Ads(scheduled, not event-driven)Daily spend or performance review

App-event triggers follow the same rules as GitHub triggers: disconnecting the integration drops the triggers; you can wire the same event to several agents.

Watching automated runs

Scheduled and triggered runs use the same lifecycle and the same session log as manual ones. Drill into an agent under Usage → Agents to see everything that ran, regardless of how it started.

From the API

Schedules and triggers are fully scriptable. The Schedules API covers schedule management; trigger endpoints live under the Agents API.

Next

On this page