← All guides

When an agent gets stuck or loops: how to spot it and break out

Troubleshooting · 8 min read

Flat illustration of a dizzy orange robot walking in a circle around a rug, its teal footprints forming a complete loop.
A loop looks busy, the footprints show it going nowhere.

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 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:

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

  1. Stop the run using the product's pause or cancel control. Don't approve any pending action it has queued.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. 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:

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.