When an agent gets stuck or loops: how to spot it and break out
Every agent user meets this eventually. You asked for something reasonable twenty minutes ago, and the agent is still working, except "working" turns out to mean doing the same thing, slightly differently, over and over. It searches, dislikes the result, searches again with a tweaked query. It fixes a problem, announces success, and the same problem is still there. Or two of its actions quietly undo each other, back and forth. A stuck agent rarely looks broken. It looks busy. This guide is about recognising the difference, stopping the run safely, and restarting in a way that doesn't walk straight back into the same circle.
What stuck actually looks like
Loops have recognisable shapes. Any one of these is a warning sign:
- The same failure returns after a claimed fix, twice or more. The agent says it's sorted; it isn't; it says so again.
- Its fixes undo each other. Successive attempts change the same few things back and forth, like a pendulum, instead of moving somewhere new.
- The explanation never changes, or changes completely every time. Both mean it isn't learning from the last attempt.
- Time and usage drain with no new information. Each lap produces activity but no new fact, no narrowed-down cause, no partial result you could use.
- You've stopped reading its updates and started just letting it run. That's the human half of the loop, and it's the one that makes the others expensive.
The common thread is a lack of progress you can point at. Genuine hard work produces new evidence each round: a cause ruled out, a source found, a step verified. A loop produces motion without evidence.
Why agents loop
Understanding the cause makes the cure obvious, and the causes are refreshingly unmysterious. Developer write-ups on agent reliability name the same few, again and again:
- The agent can't tell it has failed. If nothing in its results clearly says "that didn't work," it has no reason to change course. Anthropic's guidance to builders makes the same point from the other side: an agent needs ground truth from its environment at each step, real tool results, real outcomes, to judge whether it's making progress.
- It has no reliable memory of its own attempts. An agent builds each new step on its previous output. If an early wrong guess is still sitting in that history, later steps keep rebuilding on it, and the guess returns wearing new clothes. Without a record of what was tried and what happened, a repeat doesn't look like a repeat.
- "Done" was never defined. If the agent doesn't know exactly what a finished result looks like, or what "give up and ask" looks like, it can't recognise either state, so it defaults to continuing.
- The goal may be impossible as stated. A task built on a wrong assumption, a file that doesn't exist, a source that never publishes the data requested, can be retried forever without ever succeeding.
First move: stop the run
Before any diagnosis: pause or cancel the run. Two reasons. First, a looping agent with real permissions can keep taking real actions, re-sending, re-saving, re-buying, and you want the actions stopped while you think. Second, on any metered plan, a running agent is a spending agent: as the cost guide explains, usage billing charges for attempts, not just successes. Anthropic's guidance flags the same structural fact, an agent's autonomy means higher costs and the potential for errors to compound across steps. Pausing costs you nothing; the run's history and partial work stay available for the diagnosis. Never let an agent "push through" a loop on the theory that one more try will fix it. One more try is what a loop is made of.
The break-out procedure
- Stop the run using the product's pause or cancel control. Don't approve any pending action it has queued.
- Read the last few steps, not the whole history. You're looking for the repeated action: the same search, the same edit, the same error message appearing again.
- Write down, in plain words, three things: what it was trying to do, the exact error or wrong result it kept hitting, and every approach it already tried. This takes two minutes and is the single most valuable step, it's the record the agent itself was missing.
- Check the assumption underneath. Ask: is the thing it's looking for actually there? Is the goal achievable as phrased? A large share of loops die here, because the task, not the agent, was broken.
- Change something structural before retrying. Never restart with "try again." Restart with a different approach, a smaller scope, a clearer definition of done, or a missing piece of information supplied. Reliability practitioners put it as a rule: a failed action should trigger a different strategy, not a retry of the same one.
- Shrink the task. Ask for the smallest useful piece first, one source checked, one section drafted, one record updated, and verify it before allowing the rest. A small success you can check beats a large run you can't.
- If two structured retries still fail, start a fresh session, but hand it the note from step 3. A brand-new session with no notes forgets everything the old one ruled out and walks back into the same wrong idea. With the note, goal, exact error, approaches tried and why they failed, and what has been proven not to be the cause, the new session starts ahead of the loop instead of at the beginning of it.
- Cap the new run. Tell the agent, in the brief itself, how many attempts are allowed before it must stop and report back, and what "report back" should contain.
What success looks like: the restarted agent produces something measurably new within its first few steps, a cause ruled out with evidence, a partial result you can verify, or a clear statement of exactly what is blocking it. If step three of the new run already resembles the old loop, it isn't a fresh start; stop it and use the decision check below.
Prevention: set the job up so it can't spin
Most loops are preventable at brief time, with habits drawn from how the professionals build these systems:
- Define "done" and "give up" in the brief. State what a finished result contains, and instruct the agent to stop and report after a set number of failed attempts instead of continuing indefinitely.
- Know that real products have a built-in version of this. In OpenAI's Agents SDK, for example, a run proceeds in a loop of model calls and tool calls, and exceeding a maximum-turns limit stops the run with a MaxTurnsExceeded error, the limit can be disabled, which is exactly what you don't want. Anthropic gives builders the same advice: include stopping conditions, such as a maximum number of iterations, to maintain control.
- Ask for a visible plan and progress notes. An agent that lists its steps and ticks them off is maintaining the tried-and-outcome record whose absence causes loops, and you can spot a repeat in its list far earlier than in its prose.
- Require a difference before a retry. Make it a standing instruction: never attempt the same approach twice in a row; state what will be different first. Bounded retries with escalation, try, try differently, then hand it back to you, beat open-ended persistence.
- Keep consequential actions behind approval, as covered in staying safe with agents, and prefer read-only tasks while a new agent earns trust. A loop that can only read is an annoyance; a loop that can send or spend is an incident.
- Test on a small, safe version first. Anthropic recommends extensive testing in sandboxed environments before trusting an agent with real work. The home version of that advice: first run on a copy, a draft, or a single record, never the whole mailbox.
When to stop delegating and do it yourself
Sometimes the right break-out is out, of the agent entirely. Do the task yourself, or split off the stuck part and do only that by hand, when: the same goal has looped in two separate sessions despite a proper handoff note; the task turns out to need a judgment call the agent keeps guessing at; the cost of further attempts, in usage, time, or risk to real data, exceeds the cost of just doing it; or the agent's partial output is good enough that finishing manually is faster than supervising another run. None of these is a failure of the tool or of you. Agents are goal-seeking text machines, as the first guide in this series puts it, and recognising the boundary of a task that fits them is a skill, not a surrender. Note what made the task a bad fit, that note is the start of a better brief next time.
FAQ
Is a long-running agent always stuck? No. Long is fine; circular is not. Check for new evidence: ruled-out causes, found sources, verified steps. If each update contains something genuinely new, it's working. If updates repeat, it's looping.
Should I just start a new chat when it gets stuck? Eventually, but not first, and never empty-handed. Write the handoff note (goal, exact error, approaches tried, what's been ruled out) in the old session before you leave it, and paste it into the new one.
Can a stuck agent do damage? It can waste usage and time, and, if it has action permissions, repeat a real action, which is why the first move is always to stop the run and why approvals and read-only starts matter. Keep its permissions at the minimum the task needs, and a loop stays a nuisance instead of becoming a cleanup job.