The difference between a chatbot and an agent is that the agent decides what to do next. That decision is the product and also the liability. Every iteration of the loop costs a model call, possibly several, plus whatever the tool call itself costs in time, money, or side effects. An agent that runs until it succeeds is an agent that runs until it runs out of budget, and the two are indistinguishable from the outside until the invoice arrives.
The short version: caps are not a safety feature bolted on at the end. They are the mechanism that makes an agent economically defined. No cap, no product.
What a loop actually does per step
A single step in a typical agent loop reads the accumulated context, decides on an action, emits a tool call, waits for the result, and appends the result to the context. The context grows with each step, so the cost of step ten is higher than the cost of step one. Over a twenty-step run the input token count can easily triple or quadruple, which means the bill grows faster than the step count.
This is why step caps save more money than they appear to. Halving the maximum number of steps does not halve the cost of a runaway run; it cuts it by considerably more, because it removes the most expensive tail of the loop. The same arithmetic applies to latency, which users notice before they notice the bill.
Step cap, time cap, and cost cap are three different things
A step cap bounds iterations. A time cap bounds wall-clock duration, which matters when a tool is slow or an external service hangs. A cost cap bounds spend, which is the only one that maps directly to the budget you were given. Most production agents need all three, and they need them enforced somewhere the model cannot talk its way around.
Enforce them in the harness, not in the prompt. A model told to stop after eight steps will usually comply and occasionally will not, and the occasional case is exactly the one that costs three figures. The harness counts steps, checks the clock, and sums token usage; when any threshold is hit, it returns whatever partial state exists and marks the run as truncated so downstream code can handle it explicitly.
Stop conditions that are worth writing down
Loops fail in a small number of recognisable ways: the model repeats the same tool call with the same arguments, the tool keeps returning an error the model does not adapt to, the model oscillates between two actions, or the task is quietly impossible and the model keeps trying variations. Each has a cheap detector.
A repetition detector that compares the last two tool calls is nearly free and catches the most common runaway. An oscillation detector that tracks the last four actions catches the second. An error-streak counter that stops after three consecutive failures of the same tool catches the third. And a goal check that asks, once, whether the original request has been satisfied, catches the fourth before it burns another ten steps.
Budget-aware planning
Give the agent a notion of what a step costs before it starts. If a run has a budget of forty cents and each step costs roughly two, the plan should not have fifteen steps in it. This sounds like over-engineering and is simply the same discipline any field service team applies when quoting a job: know the rate before you decide how long to work.
In practice this means two numbers passed into the context: remaining budget, and the estimated cost of the action about to be taken. Models handle this well when the numbers are explicit. They handle it badly when the instruction is a vague warning about being efficient, which is read as advice rather than as a constraint.
The truncated run is a product decision
When a run hits a cap, something has to happen. The three options are: return partial results with an honest status, hand off to a human, or fail loudly. All three are legitimate; the mistake is returning partial results as if they were complete, which trains users to distrust everything the agent produces.
Design the partial-result contract at the same time as the loop. What does the caller receive when four of six sub-tasks finished? Usually a structured object with per-task status, so the interface can show what happened rather than a single ambiguous answer. That contract is what makes an agent usable in a business process, where a half-done job is fine if it is labelled and useless if it is disguised.
A worked example of a runaway loop
A research agent is asked to compile figures from a set of public documents. It searches, reads, decides a page is not authoritative, searches again, and repeats. Each step costs a search plus a model call over an accumulating context. By step twelve the context is large enough that each call costs about double what step one cost. Without a cap the run continues until the model declares satisfaction, which on ambiguous tasks it may never do.
With an eight-step cap, the run ends with four of six figures sourced and a status flag saying so. The interface shows which numbers are missing and offers a retry with a narrower scope. The user’s second attempt succeeds because the task is now smaller. Total spend across both runs is well below the cost of the single unbounded run it replaced, and the outcome is more honest.

What to check before you commit
- Set a step cap, a time cap, and a cost cap, and enforce all three in the harness.
- Add a repetition detector on the last two tool calls.
- Stop after three consecutive failures of the same tool rather than retrying indefinitely.
- Pass remaining budget into context so planning is cost-aware.
- Define the partial-result contract before shipping.
- Log steps, tokens, and duration per run so the caps can be tuned from evidence.
Autonomy is not a binary. It is a dial you set per task class, and the setting is decided by what a failed run costs you rather than by what the model is capable of. An agent with tight caps that always finishes is worth more than a clever one that sometimes finishes and sometimes spends your afternoon.

