The runner
How a run is claimed under a lease, stepped through model and tool calls, parked for people, split into sub-agents and held to budgets.
On this page
The runner is the part of the API process that executes agents. It is deliberately a plain loop over rows in PostgreSQL and events in the session log, so it is easy to reason about when something goes wrong. This page follows one run from start to finish, then goes through the parts.
The life of a run
<figure class="diagram" data-diagram="run"> <div class="diagram-scroll" role="region" aria-label="Figure 3, scrolls sideways" tabindex="0"> <svg class="d-w800" viewBox="0 0 800 610" role="img" aria-labelledby="dg-run-t dg-run-d" focusable="false"> <title id="dg-run-t">The life of a run</title> <desc id="dg-run-d">A client starts a session and the API stores the session, its first event and a queued run in one transaction. The client opens an event stream. A runner claims the run under a lease, rebuilds its state from the log, calls the model provider directly, and for each tool call checks the policy and calls the tool server. Every step is appended to the log in PostgreSQL; a notification wakes the API, which sends the new events to the client over the stream. The run ends with a completed event.</desc> <defs><marker id="dg-run-head" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="d-headfill" d="M0 0L10 5L0 10z"/></marker></defs> <rect class="d-box d-argus" x="20" y="14" width="100" height="40" rx="6"/> <text class="d-t" x="70" y="29" text-anchor="middle">Client</text> <text class="d-s" x="70" y="45" text-anchor="middle">app, CLI or API</text> <line class="d-life" x1="70" y1="54" x2="70" y2="596"/> <rect class="d-box d-argus" x="170" y="14" width="100" height="40" rx="6"/> <text class="d-t" x="220" y="29" text-anchor="middle">API</text> <text class="d-s" x="220" y="45" text-anchor="middle">stream hub</text> <line class="d-life" x1="220" y1="54" x2="220" y2="596"/> <rect class="d-box d-argus" x="320" y="14" width="100" height="40" rx="6"/> <text class="d-t" x="370" y="29" text-anchor="middle">PostgreSQL</text> <text class="d-s" x="370" y="45" text-anchor="middle">log and queue</text> <line class="d-life" x1="370" y1="54" x2="370" y2="596"/> <rect class="d-box d-argus" x="470" y="14" width="100" height="40" rx="6"/> <text class="d-t" x="520" y="29" text-anchor="middle">Runner</text> <text class="d-s" x="520" y="45" text-anchor="middle">any process</text> <line class="d-life" x1="520" y1="54" x2="520" y2="596"/> <rect class="d-box d-argus" x="590" y="14" width="100" height="40" rx="6"/> <text class="d-t" x="640" y="29" text-anchor="middle">Provider</text> <text class="d-s" x="640" y="45" text-anchor="middle">Anthropic</text> <line class="d-life" x1="640" y1="54" x2="640" y2="596"/> <rect class="d-box d-argus" x="695" y="14" width="100" height="40" rx="6"/> <text class="d-t" x="745" y="29" text-anchor="middle">Tool server</text> <text class="d-s" x="745" y="45" text-anchor="middle">MCP</text> <line class="d-life" x1="745" y1="54" x2="745" y2="596"/> <rect class="d-frame" x="30" y="262" width="762" height="282" rx="6"/> <text class="d-s" x="84" y="278" text-anchor="start">repeat for each step</text> <line class="d-line" x1="72" y1="88" x2="218" y2="88" marker-end="url(#dg-run-head)"/> <text class="d-m" x="145" y="82" text-anchor="middle">1. start session</text> <line class="d-line" x1="222" y1="118" x2="368" y2="118" marker-end="url(#dg-run-head)"/> <text class="d-m" x="295" y="112" text-anchor="middle">2. session, run, event</text> <line class="d-line d-dash" x1="218" y1="148" x2="72" y2="148" marker-end="url(#dg-run-head)"/> <text class="d-m" x="145" y="142" text-anchor="middle">3. 201, session id</text> <line class="d-line" x1="72" y1="178" x2="218" y2="178" marker-end="url(#dg-run-head)"/> <text class="d-m" x="145" y="172" text-anchor="middle">4. open event stream</text> <line class="d-line" x1="518" y1="214" x2="372" y2="214" marker-end="url(#dg-run-head)"/> <text class="d-m" x="445" y="208" text-anchor="middle">5. claim, take lease</text> <line class="d-line" x1="518" y1="244" x2="372" y2="244" marker-end="url(#dg-run-head)"/> <text class="d-m" x="445" y="238" text-anchor="middle">6. read log, rebuild</text> <line class="d-line" x1="522" y1="304" x2="638" y2="304" marker-end="url(#dg-run-head)"/> <text class="d-m" x="580" y="298" text-anchor="middle">7. model call</text> <line class="d-line d-dash" x1="638" y1="334" x2="522" y2="334" marker-end="url(#dg-run-head)"/> <text class="d-m" x="580" y="328" text-anchor="middle">8. text, usage</text> <line class="d-line" x1="518" y1="364" x2="372" y2="364" marker-end="url(#dg-run-head)"/> <text class="d-m" x="445" y="358" text-anchor="middle">9. append events</text> <line class="d-line d-dash" x1="368" y1="394" x2="222" y2="394" marker-end="url(#dg-run-head)"/> <text class="d-m" x="295" y="388" text-anchor="middle">10. notify</text> <line class="d-line d-dash" x1="218" y1="424" x2="72" y2="424" marker-end="url(#dg-run-head)"/> <text class="d-m" x="145" y="418" text-anchor="middle">11. events over SSE</text> <line class="d-line" x1="522" y1="454" x2="743" y2="454" marker-end="url(#dg-run-head)"/> <text class="d-m" x="632.5" y="448" text-anchor="middle">12. tool call</text> <line class="d-line d-dash" x1="743" y1="490" x2="522" y2="490" marker-end="url(#dg-run-head)"/> <text class="d-m" x="632.5" y="484" text-anchor="middle">13. result</text> <line class="d-line" x1="518" y1="526" x2="372" y2="526" marker-end="url(#dg-run-head)"/> <text class="d-m" x="445" y="520" text-anchor="middle">14. append, renew lease</text> <line class="d-line" x1="518" y1="560" x2="372" y2="560" marker-end="url(#dg-run-head)"/> <text class="d-m" x="445" y="554" text-anchor="middle">15. completed, finish</text> <rect class="d-note" x="452" y="410" width="136" height="26" rx="4"/> <text class="d-s" x="520" y="427" text-anchor="middle">policy: allow, ask, deny</text> </svg> </div> <figcaption>Figure 3. The life of a run as a sequence. Dashed arrows are responses or notifications. Steps 7 to 14 repeat for each model step.</figcaption> </figure>- A client posts to
.../sessionswith anIdempotency-Key. The API authorizes the caller for the project and checks the project's start quota. - In one transaction the API stores the session, its first events and a queued run. Only then does it answer.
- The client gets the session id back immediately. The run continues whether or not anyone is watching.
- The client opens the event stream. See Event-sourced sessions.
- A runner claims the queued run and takes a lease on it.
- It reads the session's events and rebuilds the run's state: the messages so far, the steps taken, the tool calls made.
- It calls the model provider directly, streaming the answer.
- Text and usage come back; text is shown live as deltas.
- The runner appends the step's events and a ledger row for the cost.
- PostgreSQL notifies the API processes.
- The hubs send the new events to every open stream.
- If the model asked for tools, each call first passes the policy check (allow, ask, deny) and then goes to the tool server.
- The result returns.
- The runner appends the result and renews its lease, then takes the next step until the agent answers.
- The run records
run.completedand the runner finishes it.
Claiming a run
A run is a row. A runner claims the oldest queued run with FOR UPDATE SKIP LOCKED, so runners never contend for the same row, and the claim also covers a run still marked working whose lease has expired. Each claim bumps an attempt counter and issues a new lease token from a sequence.
- The lease is short (30 seconds by default) and renewed every third of that while the run is worked.
- Every write that finishes, renews or releases a run is fenced by the lease token. A runner that lost its lease, because it stalled or its process died, cannot overwrite what the new holder does: its next fenced write finds no row, and it stops at once.
- Renewals also carry stop requests. A cancel from a person is delivered to the runner on its next renewal and ends the context of the model or tool call in flight.
- On shutdown a runner releases its in-flight runs back to the queue.
- Runners are plain workers: a process runs a number of them (eight by default) and the process role decides whether it also serves HTTP.
Crash safety is the product of these rules plus the log. If a runner dies mid-step, the lease runs out, another runner claims the run and rebuilds its state from the events, and the work continues from the last completed step. The end-to-end tests include a run resumed by another runner after a lease expires and a run cancelled mid model call.
Steps
An agent run is a loop of steps. Each step builds the model request from the agent version (instructions, model, granted tools, the messages so far), calls the model, and acts on the answer. Defaults apply when a definition sets none: 25 steps, a 15-minute attempt timeout and a bounded size for each tool result. A definition can also declare fallback models.
Which model a step uses is decided in a fixed order, most specific first: a workflow step that started the run may pin the model; otherwise the first true model.select rule for that call; otherwise the route's model; otherwise model.default. The rules are compiled when the definition is saved, read only a few counters of the run and no model or tool output, and are evaluated by the same small package that code outside the runner can use. The one choice that depends on cost and time, a select rule, is written to the log (model.routed) before the call starts, so a run that crashes in between replays the recorded choice. The chosen model starts its own chain: it is followed by the declared fallbacks, never by the default, and the credential rules cut the chain exactly as for the default model.
A definition can instead declare a workflow: fixed steps built from a few primitives (an agent call, parallel calls, a map over a list, a judge, a loop and a human step). The runner executes the workflow instead of the model loop, and the judge step can use a model judge and deterministic tool checks, passing only when every part passes.
Tool calls and approvals
Every tool call the model asks for goes through the policy engine before it leaves Argus. Grants are default-deny: a tool that is not allowed or asked is not shown to the model and is refused if called anyway. The decision is recorded as a tool.policy event next to the call. See Tools, tokens and the egress guard.
A call that needs a person's approval does not hold a runner. The run records a human.requested event, moves to input_required and waits without holding a runner. Any device can answer with POST .../human/{request_id}, which wakes the run; a runner claims it again and continues. The same mechanism serves decision cards, questions and client-side tools that the calling app answers. A human step has a timeout, and the run records it if it passes.
A tool call that was in flight at a crash is retried only if the tool is declared idempotent. Otherwise the run records tool.outcome_unknown and asks, rather than risking a second effect.
Sub-agents
A coordinator agent can be granted the platform tool argus.agents.call to call a declared sub-agent as if it were a tool. The runner starts a sub-run, a child in the session's run tree, parks the caller, and resumes it with the sub-run's output when it ends.
- The sub-run's identifier is derived from the caller's run and the call id, so a caller that crashed after starting one finds it again and never starts two.
- A sub-run starts clean: its input is the call's input, and it sees only the session variables its own definition declares.
- Budgets are inherited and capped. A sub-run may spend at most its own per-run ceiling and its share of what is left of its caller's, and what it spends counts against the caller. A sub-run that overspends fails, so the caller can carry on.
- The run tree is at most four levels deep, which stops agents that call each other in a loop.
- When a caller stops, its unfinished sub-runs are cancelled.
The run map in the app draws this tree from the log.
Budgets and quotas
Argus assumes agents cost real money and can loop, so limits apply at four layers.
| Layer | What it limits | What happens |
|---|---|---|
| Per run | Steps, cost, tokens and time, set in the agent's definition. | The run stops with a clear reason. |
| Budgets | Spend per project, agent, session or end user, per day, month or total, in dollars or tokens. | Checked before every model call. warn records a warning at a fraction; pause stops the next call, and the run moves to paused_budget and resumes when the budget is raised. |
| Project quotas | Runs queued or working at once (4 by default) and session starts a minute (20 by default). | Over the limit the API answers 429 and queues nothing. A run parked on a person, a login or a budget does not count. |
| Object caps | How many agents, versions, tool sources, schedules, triggers, webhooks, suites and artifact megabytes a project may hold. | The call is refused with a plain sentence and nothing is stored. |
Spend is recorded in the ledger, one row per model call (the call that writes a summary of older turns included). A call made on a project's own provider key is recorded at zero cost to the platform and is excluded from the spend budgets. The trial cap is enforced here, by the budget check before each call, and not at the provider: the provider's own monthly workspace limit is only a second wall behind it. Argus also keeps platform-wide monthly caps on model spend, one for customers' trials and one for its own use. A run that meets one of them parks with a platform-limit message (budget scope platform, not the project's) and is requeued by the runner every ten minutes until the limit is lifted.
Compaction
Long runs would otherwise carry every old tool result in every request. A definition can declare compaction: tool results older than a number of steps are replaced in the model's request by a short stub that tells it to call the tool again if it needs the data, and a maximum size can cap each result. Only the request is compacted. The log keeps every result whole, so history, replay and audit are unaffected.
Summarising on overflow
Compaction trims what a run did; a long conversation also grows between runs, because every request carries the session's earlier turns. A definition sets a ceiling on a request (context.max_input_tokens_per_step, estimated before the call) and a strategy for passing it. With the default, truncate, the step fails with context_ceiling. With summarize, the runner writes a summary of the oldest earlier turns and goes on:
- It finds the earlier turns older than the last
keep_lastthat no summary covers yet. If there are none, the run fails withcontext_overflow. - It asks the summary model (the definition's
summary_model, else the model of the step) for one summary, at temperature 0, handing it the previous summary, if any, and only the turns to add. The call is not streamed into the session. - It appends one
context.summarizedevent in the same way as any other: the summary text, the range of turns, the estimated tokens before and after, and the usage and cost of the call. The store costs that event into the ledger in the transaction that appends it, as it does formodel.completed, so the call has exactly one ledger row, attributed to the run. A call on a project's own key is recorded at zero cost to the platform. - It rebuilds the request around the summary. If that still passes the ceiling, the run fails with
context_overflow. A step summarises at most once, so there is no loop to guard.
Replay needs nothing more than the log. State is rebuilt from events, and the latest context.summarized says that earlier turns 1 to N are stood in for by its text, so a resumed or replayed run sends the same messages, and a later run reuses the summary without a model call. The summary is conversation content: retention removes its text and keeps the figures.
What this design gives up
The runner is code Argus owns rather than a workflow engine's, so its crash behaviour needs its own tests; they exist and are part of CI. Exactly-once effects depend on tools honouring the idempotency key Argus sends with each call.