Agentic workflows that don't spiral out of control
Reliable agents come from bounds. Cap turns and time, push predictable steps into a state machine, and keep a human on the irreversible ones.
TL;DRthe 30-second version
- Agents rarely fail by crashing. They fail by never stopping: the same tool, slightly different arguments, over and over, with the cost climbing.
- Cap every run before it starts. Ours stops at 50 model turns and returns its best result so far, and every external call has a wall-clock timeout.
- Put the predictable sequence (research, plan, implement, QA, fix) in deterministic code, and let the model loop only inside a phase.
- Keep a human on the irreversible steps. Our agent stops after planning until someone approves, and it never opens a pull request on its own.
The first time I watched an agent fail, it didn’t crash. It just kept going. Same tool, slightly different arguments, over and over, each step sure it was about to get there, with the cost ticking up in the background and no progress at all. The demo had shown me what the agent could do. It hadn’t shown me what it would do when it got stuck.
Mine was a coding agent: give it a ticket, let it research the codebase, plan a change and implement it. The first time it really got stuck, it was hunting for a symbol that didn’t exist under the name it expected. It searched, read a file, didn’t find it, searched again with a slightly reworded query, read another file, and kept circling, re-deriving the same dead end with no memory that it had been there before. I found it by scrolling a log that had grown to hundreds of tool calls. Nothing had errored. It was never going to stop on its own.
The agent’s job was to take a real engineering task end to end across a live codebase: read the relevant code and tickets, propose a plan, then write the change. The capability was real. The reliability wasn’t, and in production reliability is what counts. An agent that succeeds eighty percent of the time and burns an unbounded amount of money the other twenty is an incident waiting for a trigger.
How it spiralled
The failure was an open-ended search-and-read loop with no hard stop: repeated calls to the same tools, reworded just enough to look like progress, with no convergence and no sense that the world hadn’t changed between attempts. Underneath it was a structural problem. The agent had been handed one big undifferentiated loop and asked to figure it out.
ReAct-style reasoning (think, act, observe, repeat) works because it’s open-ended, and that’s also what makes it dangerous. Self-critique loops in the style of Reflexion can make it worse before they make it better: ask a model to critique its own work and it will usually find something to improve, so without a limit it keeps refining. Reflexion itself caps the number of trials for exactly this reason. Capability without constraint doesn’t fail with an error. It fails by never stopping.
The guardrails that fixed it
I stopped trying to make the agent smarter and started making its environment stricter. The capability was already there; the control was missing.
Hard bounds first. Every run is capped at fifty model turns, and when it hits the ceiling it stops and returns the best result so far. Wall-clock timeouts sit under every external call: the slow tools (search, design fetches, ticket lookups) get three minutes, a repository clone sixty seconds, a diff ten, and each falls back instead of hanging. The turn cap doubles as a cost ceiling. A run that can’t exceed fifty model turns can’t run up a huge bill, however confused it gets. None of this is elegant, and it’s the difference between a bounded system and an unbounded liability.
The gap I’d close next: I bound turns and time, but I don’t detect no-progress directly. A proper circuit breaker would notice the same tool called with no change in state and stop on the spot, without waiting for the turn cap. If an agent takes the same action twice and the world hasn’t changed, it’s stuck, and a third attempt is waste. Today the turn ceiling is the backstop for that. Making the detection explicit is the obvious next step, and I’d rather say so than pretend the breaker exists.
The structural change mattered most: narrowing where the agent gets to be open-ended at all. The run is a state machine with explicit phases: research, plan, wait, implement, visual QA, fix. The model only loops inside a phase, and even there it’s bounded by the turn cap. Most of what an “agent” does is a known sequence that doesn’t need a model deciding what comes next. Encoding that sequence as deterministic code, and keeping open-ended reasoning for the one or two steps that need judgement, removed most of the places where spiralling was even possible. Open-ended loops are for ambiguity. Everything else should be a state machine.
A human on the irreversible steps. After the agent researches and writes a plan, the run stops at an approval gate. It won’t touch code until a person replies “approve”. It also never opens a pull request on its own: it produces changes in a working tree and a diff for someone to review before anything is pushed. Not every step needs a person, but the irreversible ones do, and a checkpoint there turns a potential mess into a pause.
The result
The change wasn’t a cleverer agent; it was a predictable one. Runaway executions went to zero. The model didn’t get better at not getting stuck: it just can’t stay stuck for more than fifty turns, or wait on any single call past its timeout, and it can’t write anything a person hasn’t approved. The trade-off is real. The constrained agent is sometimes less capable on the hardest cases, because it gives up where the unconstrained one would have kept trying, and a person now sits in the critical path of every task. That trade-off is the point. A predictable system that occasionally declines beats an unpredictable one that occasionally costs you a fortune.
The takeaway
Reliable agents come from control. The model was never the bottleneck; the bounds were. Decide the maximum steps and time a task may consume before the agent runs, push every predictable part of the flow into deterministic code, and keep a person on the irreversible steps. The goal isn’t an agent that can do anything. It’s one that can’t do anything catastrophic.