How an AI Agent Burns Hundreds of Dollars Overnight, and Five Guardrails That Stop It
The defining property of an agent is that it chooses its own call count. Three failure modes account for nearly every runaway bill, and the five guardrails that prevent them are each about a dozen lines of code.
The context snowball is the one that hides
Runaway loops are obvious in logs — the same call, over and over. The snowball is not. The agent is doing genuinely different work each turn, so nothing looks wrong, but each turn carries everything before it. Cost per turn rises steadily while progress looks normal. Watch cost per step over time, not just total spend, and this becomes visible early instead of on the invoice.
A spend ceiling beats a step limit
Step limits are the obvious guardrail and they are not sufficient, because steps are not uniform in cost. Fifty cheap steps and fifty expensive ones hit the same limit at wildly different bills. A per-task spend ceiling caps the thing you actually care about, and it keeps working when someone later changes the model or the prompt size. Set both, but if you only implement one, make it the spend ceiling.
Tiered models are a safety feature, not just a saving
Routing routine steps to a cheap model is usually framed as cost optimization. It is also containment: when something does spin, it spins at a fraction of the rate, which converts a serious incident into a noticeable one. Reserve the expensive tier for the specific steps that need it and a runaway becomes survivable.
Load test on a small sample before launch
Run the agent against a representative sample and record the token count per task before it touches real volume. This gives you a real per-task cost to set your ceiling from, and it surfaces loops that only appear on inputs you did not think about. An afternoon here is cheaper than the first bad night.
Make anomalies surface themselves
Alert on daily spend and on cost per task, not on monthly totals. Monthly numbers tell you about an incident well after it finished. A simple threshold on daily spend catches the overnight case, which is precisely the one that hurts, because nobody is watching when it happens.
Failure modes and the guardrail that catches each
| Failure mode | How it shows up | Guardrail |
|---|---|---|
| Unbounded retries | Same call repeating in the logs | Hard step limit per task |
| Context snowball | Cost per turn climbing while the work stays the same | Trim or summarize history |
| Agents looping on each other | Two components exchanging messages indefinitely | Spend ceiling per task |