Budgets and limits
Every runaway agent story starts the same way: no limit, a loop, and a bill. Budgets are three lines of code and the difference between an experiment and an incident.
How it works
- Cap steps: the number of think-act cycles per run.
- Cap wall clock: an agent that has run for ten minutes is stuck, not thorough.
- Cap tool calls per tool: one search is research, forty is a loop.
- Cap spend per run and per day, and make the daily cap an alert, not a surprise.
- Decide what happens at the limit: partial result, escalation, or clean failure. Never silence.
Optional: load a real model
See it work
When it pays, and when it does not
| Use it when | Skip it when |
|---|---|
| Always | Never. There is no agent that should run without limits |
| You have any loop at all | Single-shot generation with no loop, where a timeout is still worth having |
| Cost is metered per token | You self-host and the cost is time and hardware, which still needs a cap |
| Users are waiting | Batch work overnight, where the caps are money and correctness rather than latency |
How it fails
Silent truncation
Hitting a limit and returning as if finished is the worst outcome. Say the limit was hit, in the output.
Limits only in one dimension
A step cap does not stop a single tool call that costs a fortune. Cap all four.
Retries outside the budget
Retries that reset the counter turn a cap into a suggestion.
What it costs
| Engineering | Minutes. |
|---|---|
| Missed answers | Some legitimate runs get cut off. Log them and tune, rather than removing the cap. |
| Peace of mind | The only pattern here that lets you sleep during a pilot. |
Every stop must produce something. A partial answer with the limit named is useful. Silence looks like a crash and gets debugged for an hour.
Related: Cost control · Guardrails · Retries and idempotency · all patterns · agent jobs
Related: Cost control · Guardrails · Retries and idempotency · all patterns · agent jobs
Free from AI School - no signup, everything runs in your browser.