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

  1. Cap steps: the number of think-act cycles per run.
  2. Cap wall clock: an agent that has run for ten minutes is stuck, not thorough.
  3. Cap tool calls per tool: one search is research, forty is a loop.
  4. Cap spend per run and per day, and make the daily cap an alert, not a surprise.
  5. 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 whenSkip it when
AlwaysNever. There is no agent that should run without limits
You have any loop at allSingle-shot generation with no loop, where a timeout is still worth having
Cost is metered per tokenYou self-host and the cost is time and hardware, which still needs a cap
Users are waitingBatch 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

EngineeringMinutes.
Missed answersSome legitimate runs get cut off. Log them and tune, rather than removing the cap.
Peace of mindThe 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

Free from AI School - no signup, everything runs in your browser.