# Runaway Agent Loops Need Budgets, Not Better Prompts

An agent that keeps calling tools until it is satisfied will eventually never be satisfied. Hard limits on steps, spend and time belong in the runtime, not the prompt.

Published 2026-11-16. https://falnoa.com/en/blog/runaway-agent-loops-need-budgets-not-better-prompts

Most agents are built around a loop: ask the model what to do, run the tool it chose, hand the result back, repeat until the model says it is done. That loop is the whole appeal of agents. It is also where the worst bills and the strangest incidents come from, because nothing in it guarantees that "done" ever arrives.

The usual first response is to write a firmer prompt. "Do not repeat yourself. Stop after three attempts." That helps on a good day and does nothing on the day the model misreads a tool error and decides the fix is to try again, differently, forever. A limit that lives inside the thing being limited is a suggestion. This post is opinion, drawn from how we think about runtime design, and it argues for putting the limits outside the model.

## What a runaway loop looks like

Runaway loops rarely look like an infinite loop in the textbook sense. They look like work:

- **The polite retry.** A search tool returns nothing, so the agent rephrases the query and searches again, dozens of times, each call plausible on its own.
- **The ping-pong.** Two agents, or an agent and a human-facing tool, hand the same task back and forth, each convinced the other owns the next step.
- **The growing context.** Every iteration appends tool output to the conversation. The prompt gets longer, each call costs more than the last, and the model gets worse at noticing it is repeating itself.
- **The slow burn.** A thousand runs a day each use a few steps more than they need, and nobody sees it until the invoice.

None of these trip an error. Every individual call succeeds. That is why ordinary alerting on failures misses them.

## Put the limits in the runtime

A budget is a hard ceiling enforced by the code that drives the loop, independent of what the model says. The model is never asked for permission to exceed it. We think four ceilings cover most of the ground.

1. **Steps.** A maximum number of model calls and tool calls per run. Pick it from the longest legitimate run you have seen, plus some margin, not from a guess.
2. **Spend.** A maximum token or currency cost per run, and a separate one per agent per day. The per-run limit catches a loop. The daily limit catches the slow burn.
3. **Wall-clock time.** A deadline for the whole run, not only per call. A run that is technically progressing but has been going for an hour is usually stuck.
4. **Repetition.** A check for the same tool called with the same normalized arguments more than a small number of times. This is the cheapest and most precise detector for the polite retry.

When a limit is hit, the runtime stops the run and records why. The stop reason should be a first-class state such as `budget_exceeded`, not a generic failure, so that it can be counted, alerted on and reviewed.

## Decide what stopping means

Stopping is easy. Stopping safely is the part that needs design.

An agent halted halfway through a multi-step action may leave work in an awkward state. Before choosing limits, decide what each agent does on a stop. Read-only agents can usually just end with a partial answer and a clear message. Agents that write to other systems need a defined next state: roll back what can be rolled back, mark the rest as needing attention, and hand the run to a person with the history attached.

This connects to two other things we have written about. Steps that change the outside world should be safe to repeat, which we covered in [retrying agent tool calls without doing things twice](/blog/retrying-agent-tool-calls-without-doing-things-twice), because a budget stop followed by a resume is just another retry. And the handover to a person only works if the record of what happened is complete, the subject of [an agent audit trail is not a log file](/blog/an-agent-audit-trail-is-not-a-log-file).

## Make limits visible and adjustable

Budgets set once and forgotten tend to fail in one of two ways. Set too tight, they cut off legitimate long tasks and people learn to work around the agent. Set too loose, they never fire.

A few habits keep them honest:

- Track how often each agent ends in `budget_exceeded` and how close successful runs come to the ceiling. Both numbers tell you whether the limit is right.
- Treat a rising average step count for an agent as a signal worth investigating, even when nothing has failed. It often means a tool changed or a prompt regressed.
- Let owners raise a limit for a specific agent through a reviewed change, with the reason recorded, rather than editing a global default.
- Keep a manual stop. Someone on call should be able to halt a single agent or all agents immediately, and the system should treat that exactly like a budget stop.

## Do not use the model to police itself

It is tempting to ask the model, every few steps, whether it is stuck. Sometimes it will say yes. A model that has talked itself into a bad path is also the model least equipped to notice. Use it for what it is good at, choosing the next action, and use deterministic code for counting, timing and comparing.

Telling the agent how many steps remain can improve behaviour, but treat that as an optimisation on top of the runtime limit, never a replacement for it.

Agents are valuable because they can keep going without being told what to do next. The same property means somebody has to decide how far they may go. That decision should be made by your engineering and risk owners, in code, before the first production run.

## Where Falnoa fits

Blue Falnoa is built around the idea that agents should run inside limits that people can see, review and change. If you are working out how to bound what your agents can do, we would be glad to compare notes. [Get in touch](https://www.falnoa.com/#contact).
