Essays
What Happens When an Agent Loops
May 24, 2026
I have been building small agent loops as side projects and every one of them has surprised me in some way. The first time I ran one, I thought I was mostly writing a wrapper around a model. By the third time, I realized I was writing a small operating system, and the model was one process inside it.
The basic shape of an agent loop is simple. The model reads some state. It picks an action, usually a tool call. The action runs. The result gets added to the state. Then the model runs again. Repeat until it says it is done.
What I did not appreciate at first is how many things can go wrong inside that loop. The model can hallucinate a tool that does not exist. It can call a real tool with the wrong arguments. It can succeed at the tool but misread the result. It can loop forever if the exit condition is even slightly ambiguous. It can also just get confused and repeat itself.
Most of these failures are not bugs in the model. They are gaps in how I set up the loop. Every time something breaks, I usually end up realizing that I trusted the model with a decision that should have been made outside the loop.
One thing I have started doing is being much more explicit about state. Instead of letting the model manage context through the conversation, I try to keep the important pieces of state separate. What has been tried. What has been verified. What is still open. This makes the loop feel less like a chat and more like a small state machine that happens to consult a model for the hard steps.
I have also started to notice how much of an agent loop is about deciding when to stop. That sounds trivial but it is not. A loop that runs too many steps burns tokens and time. A loop that stops too early does not finish the task. Getting this right feels closer to writing a good termination condition in a search algorithm than anything about language models.
I do not have a clean philosophy of agent loops yet. What I have is a growing pile of small heuristics. Never let the model decide something you can verify cheaply. Log everything, even when it feels excessive. Make the loop as boring as possible, so the interesting behavior is only where it actually needs to be.
Maybe in a year I will look back and see this as a very early view of the problem. But right now, agent loops feel to me like the place where a lot of the practical hard work of AI is going to happen. Not in the model, and not in the interface, but in the quiet layer in between.