# Budgets and limits

> How Convoy bounds a run: a dollar budget, a runtime limit, per-agent turn limits, a process cap, and a stuck timer.

A swarm can run for hours with many agents, so every run is bounded in dollars, time and turns.

| Limit | Set with | Scope | On reaching it |
| --- | --- | --- | --- |
| Dollars | `max_cost_usd` on `swarm` | Whole run, overseer included | Every agent stopped; run Stopped, reason `budget` |
| Wall-clock time | `max_runtime` on `swarm` (required) | Whole run | Every agent stopped; run Stopped, reason `max_runtime` |
| Turns | `max_turns` on `agent` (default 50) | One agent | That agent is Stopped |
| Processes | `convoyd --max-processes` (default 50) | The machine | Extra agents wait in Pending |
| Silence | `--stuck-after` (default 20m) | One Running agent | Marked Stuck; the overseer is woken |

## max_cost_usd

The dollar budget counts every agent and the overseer. After each turn the runner reports token usage; the server prices it and adds it to the run's spend. When spend reaches `max_cost_usd`, every agent is stopped and the run ends Stopped with reason `budget`. Outputs already passed to `finish` are kept.

If `max_cost_usd` is unset, nothing limits spend except `max_runtime`, and `convoy validate` warns.

### Pricing

Spend is computed from token usage and per-model prices in USD per million input, output, cache-read and cache-write tokens. Prices come from each [provider type](/docs/providers/)'s model catalog: the built-in types price the Claude and OpenAI models, and a third-party type prices its own. Validation and the server read the same catalog. A provider's own `price` overrides it for all of its models:

```hcl
provider "local" {
  source   = "openai_compatible"
  base_url = "http://localhost:11434/v1"
  price    = { input = 0, output = 0 }
}
```

`input` and `output` are required; the cache prices default to `input`. `openai_compatible` prices no models, so its providers need a `price` once a budget is set. When `max_cost_usd` is set and any agent's model, or the overseer's, has neither a price in its type's catalog nor a provider `price`, validation fails. The server applies the same check to the overseer chosen by its flags and rejects the run with `unpriced_model`. The server prices every type itself, from the token counts the runner or driver plugin reports, so the SDK's own cost figure is not what the budget uses.

### Overshoot

Turns already in flight finish. Actual spend can therefore exceed the cap by up to one turn per running agent, and the count grows with the number of agents working at the moment the cap is reached. `convoy status` reports the actual spend, which may be above `max_cost_usd`. Turns the server cannot price are counted separately as unpriced. Per-agent budgets are post-MVP.

## max_runtime

A duration string such as `"30s"`, `"10m"` or `"4h"`. When elapsed time reaches it, every agent is stopped and the run ends Stopped with reason `max_runtime`.

## max_turns

An agent is stopped after this many turns. The default is 50. Agents that watch topics should set their own limit, since they take a turn for every wake; validation warns when they do not. The overseer has a fixed limit of 500, and hitting it stops the overseer, not the run.

## --max-processes

One runner process runs per agent, almost always blocked waiting for its next turn. `--max-processes` (default 50) caps how many the machine runs at once, across all runs and counting overseers. Agents beyond it stay Pending, and earlier-declared agents win a scarce slot. The language has no agent-count limit.

## The stuck timer

A Running agent that has not called `report_progress` for 20 minutes is marked Stuck, and the overseer is woken. The controller does not kill or restart it. The agent returns to Running on its next progress report. Idle agents are never Stuck, since waiting is their design. A long tool call can trip the timer, and an agent that reports while repeating itself will not; the other limits still bound it.

## Order of checks

The controller checks the budget first, then `max_runtime`, then `done_when`. A pass that sees the budget crossed and `done_when` true ends the run as `budget`. See [swarms and runs](/docs/concepts/swarms/#run-status-and-end-reasons).
