Agent Loops That Don't Spiral
Most agent failures are loop-design failures. Here is how to bound an agentic run so it finishes, reports, and stays cheap.

An agent is a loop: observe, decide, act, repeat. The model gets most of the attention, but the loop is where runs go wrong — infinite retries, forgotten goals, tool calls that repeat with the same failing arguments, and cost graphs that climb while nothing useful happens.
Give every loop three exits
- Success: an explicit, checkable completion condition, not the model's opinion that it is done.
- Budget: a hard cap on steps, tokens, wall-clock time, and tool calls.
- Escalation: a path that hands the task back to a human with what was tried and what is blocked.
If a loop has only the first exit, you have not built an agent — you have built a way to spend money unpredictably.
Make the state explicit
Do not rely on conversation history as the agent's memory of the plan. Keep a small structured state object the loop rewrites each step, and put it in the prompt verbatim.
state:
goal: "<one sentence, unchanged all run>"
done: ["step already completed"]
next: "the single next action"
blocked_by: null | "what is missing"
steps_used: 4 / 12Two things improve immediately: the agent stops re-doing finished work, and you get a log you can read when a run misbehaves.
One action per step
Letting a model plan five actions and execute them blind removes the observation half of the loop. Ask for one action, run it, feed back the real result. Slower per step, dramatically fewer wasted steps overall.
Fail loudly on repeats
- 1Hash each tool call with its arguments.
- 2If the same hash appears twice with the same error, stop retrying.
- 3Inject the failure into the prompt as a fact: this call does not work, choose a different approach or escalate.
An agent that stops and says why is more valuable than one that keeps going and cannot say what it did.
Where to start
Take your current agent, cap it at eight steps, log the state object every step, and read ten real runs end to end. Almost every fix you need will be visible in those logs — and almost none of them will be a different model.



