Loop Detection (Agent)
Watch a stuck agent for a minute and the pattern is unmistakable. It calls the same tool, gets the same error, adjusts an argument slightly, and tries again — indefinitely, with complete confidence. Loop detection is the machinery that spots this from outside the reasoning and intervenes, because the agent inside the loop cannot see it.
What a detector looks at
The signal is repetition without progress, measured across the trajectory rather than within one step:
- Identical actions — the same tool with the same arguments, two or three times running;
- Cycles — a repeating sequence of states, such as edit, test, revert, edit;
- Unchanged observations — the environment returns the same output or error, so nothing new entered the context;
- Semantic repetition — reworded reasoning that restates an earlier step, caught by hashing or embedding similarity on actions and results.
What happens on a trip is a policy choice: warn the agent that it is repeating itself, force a different tool, escalate to a person, or terminate the run. Tracing tools such as LangSmith make these cycles visible afterwards; the detector is what acts during the run.
Why it matters
A step limit will eventually stop a looping agent, but only after it has spent the entire budget producing nothing. Loop detection ends the waste early and, more valuably, converts a silent stall into a reported fault — the difference between a run that failed after burning its whole allowance and a clear message that the agent could not get past one call.
Loop detection is a runtime check that identifies when an agent is repeating actions without making progress — the same tool call with the same arguments, or a cycle of states returning identical observations — and then intervenes by warning, redirecting, escalating or halting. It converts a silent stall that would quietly consume the whole step and token budget into an early, reported failure.
Anyone who has pushed a door marked "pull" knows the feeling — try again, harder, same result. AI agents do this too, except they never get bored. Faced with a tool that keeps failing, an agent will cheerfully make the same request hundreds of times, rewording it slightly, convinced it is nearly there.
Loop detection is the watchdog that notices. It checks whether the software is repeating itself and getting nowhere, and if it is, something steps in: a nudge to try a different approach, a call for a human, or simply stopping the job.
Without it, a stuck agent quietly runs up a bill all night and produces nothing at all.