The AI Reader.
The Mechanics

An agent reruns the step that just failed because the transcript still points to it

An agent is a stateless model re-reading a transcript and a harness running what it returns, and that plain design makes repeating a just-failed step the most likely next move.

Why this matters

Agents are the form most new AI products now take. A coding assistant that edits files, a browsing agent that clicks through a site, an autonomous runner you hand a goal: each is a language model placed in a loop and given a way to act. Leave one running and you will eventually watch it get stuck. It reruns the command that just errored, clicks the dead link again, retries the approach that already failed, turn after turn, until something outside it stops the run. This lesson works backward from that stuck agent to the part of the design that produces it, and stops at the point below which nothing you could change would alter the result. By the end you can look at any proposed fix and say whether it touches that part or only decorates it.

Background optional reading
01
A model that calls a tool never runs it: what actually happens when a model "calls" a tool, and who runs it.
02
ReAct searched Wikipedia between thoughts: the reason-act loop as the paper that introduced it.

A coding agent breaks one line and keeps editing it

SWE-agent is an autonomous coding agent that reads a bug report, edits files in a repository, and runs the tests. Its authors name a prominent failure of it plainly: the agent repeatedly edits the same snippet of code. The usual trigger is an errant edit that introduced a syntax error, a wrong indentation or an extra parenthesis, which the agent then keeps trying to fix.1 Failed edits are not rare. Of 2942 SWE-bench task instances, 1185 of the runs, 51.7%, contain at least one failed edit, and the odds of recovery fall as those failed edits pile up.1 These agents do not finish often: this one resolved 12.47% of the test tasks, against a prior non-interactive best of 3.8%.1

51.7%SWE-agent runs with a failed edit
12.47%SWE-bench tasks resolved

The same pattern turns up wherever a model is put in a loop. In ReAct's error analysis of 50 runs on the HotpotQA question set, the authors single out one failure specific to it. The model keeps regenerating its previous thoughts and actions and cannot reason its way to a different next step. They file it under reasoning errors, 47% of ReAct's failures against 16% for plain chain-of-thought, though the repeated loop is only one part of that row.2 AgentBench, which scores models as agents across a range of environments, keeps a tally of why a run ends. One reason it records is that the agent "begins to do repeated generations for many turns," and that category of unfinished run reaches as high as 82.5% of tasks in some environments.3 Outside the papers, a user filed an AutoGPT issue in April 2023 titled "Gets stuck in a loop." Its log shows the runner re-issuing the same Google query at three consecutive timestamps after it had already received results.4 That is one unreplicated report, not a rate, but the pattern is catalogued as a recognized failure of these runners.5

Underneath an agent is a model calling a harness in a loop

To see why the step comes back, take the agent apart. An agent is a language model given a way to act, and the model cannot act on its own. It writes text, and a program outside it does the running and reports back; the mechanics of one such tool call are their own lesson. Put that exchange on repeat and you have the reason-act loop. Four steps, one turn:

  1. The model proposes an action

    Given the transcript so far, the model writes its next reasoning and the action it wants taken, as text.2

  2. The harness runs it

    A program outside the model, the harness, parses that text and performs the action: it runs the command, follows the link, applies the edit.

  3. The result goes back into the transcript

    Whatever came back, an output or an error message, is appended to the transcript as more text.

  4. The model is called again

    With the transcript now one turn longer, the model is called to propose the next action, and the loop turns again.

One fact about the model in step one governs everything downstream. It is stateless: it keeps nothing between calls, so on every turn it re-reads the whole transcript from the top and produces the next action from that text alone. Its only record of what it has already tried is whatever the transcript holds. A model cannot keep a private note of a word it never wrote down, the same reason a chatbot loses a secret it promised to keep in a game of hangman.

The transcript keeps recommending the step that just failed

Now run the loop forward into the stuck state. Suppose the transcript still names the same goal and still shows the same action as the most reasonable next move. The model returns the most probable continuation of that text, so it returns that action again. The error the harness appended is evidence against the action, but it is weak evidence against a strong prior, and a model frequently continues on the prior instead of revising on the error.

How weak that evidence is has been measured. Huang and colleagues separate two settings.6 In intrinsic self-correction the model reviews its own answer with no outside check. Accuracy holds flat or slips: GPT-4 on the GSM8K math set went from 95.5 to 91.5 to 89.0 over two rounds of self-review. Hand the same procedure a correct-label oracle that decides when to stop, and accuracy climbs instead, GPT-3.5 on CommonSenseQA rising from 75.8 to 89.7.6 The finding is not that a model cannot revise. It is that a model cannot reliably judge whether its own reasoning was correct, so feedback it generates about itself is worth little while a reliable signal from outside is worth a great deal.6

Open question

Huang and colleagues give the proximate cause, that the model cannot judge the correctness of its own reasoning.6 Why a model under-weights the error already sitting in its transcript, and whether it could learn to weight that feedback reliably with no outside signal, is not settled by these results.

Statelessness is not the only push toward the repeat. ReAct's own authors attribute part of their loop to greedy decoding, the habit of taking the single most probable token at each step, and suggest a different decoding procedure might address it.2 That is the same force behind the token-level repetition loops an earlier lesson took apart, where a model is made likelier to repeat a phrase by having just repeated it. Some action-level looping shares that decoding-level cause. And the obvious knob does not reach it. Raising the sampling temperature adds randomness to the draw. It does not add a strategy for what to try next, so it can knock the agent off the exact repeat without giving it anywhere better to go.

Below the transcript and the harness, nothing else decides

Follow the chain down and it bottoms out quickly. The action appears because the transcript makes it the most probable continuation.2 The transcript reads that way because the earlier turns, the failed one included, are still in it and still point at the goal. The model re-derives the action because that is what predicting the next token from this text yields, and the harness runs it because running what the model returns is the harness's one job.1

No component in the base loop keeps a list of what was already tried, ranks the alternatives, or decides to explore. Nothing below that line changes the outcome: the loop is the default behavior of a stateless predictor reading a transcript while a harness executes what it says, and not a defect in one product built on that design.

What breaks the loop is a better signal or a harder stop

Because the cause sits in the transcript and the harness, the fixes that work reach for one of those two places. Reflexion adds a step after a failed trial.7 The agent writes a short reflection on what went wrong and stores it in a memory the next trial reads, so the transcript now carries an explicit record of the attempt and not just its failed output. On the AlfWorld task set, ReAct with Reflexion finished 130 of 134 tasks, well above plain ReAct, and on the HumanEval coding set it reached 91.0 pass@1 against an 80.1 GPT-4 baseline.7 The gain is not uniform: on MBPP the same method scored 77.1, below that baseline. What it isolates is the missing ingredient: a memory of past attempts.

SWE-agent's authors changed the harness instead. Recall that the repeated edits begin when an errant edit introduces a syntax error. They added a check to the edit action that applies a change only if it produces no major error, so the broken edit never enters the transcript to be repeated, and performance improves considerably.1 LangGraph takes the bluntest route. Its recursion limit caps how many steps a graph runs in one execution, 1000 by default as of version 1.0.6 and 25 in earlier ones. It raises an error at the cap, noting it "is often due to an infinite loop."8 A cap is not a way out of the loop. It ends the run without solving the task, which makes it a way to bound the damage rather than fix the cause. A person watching supplies what the model cannot: the outside signal Huang and colleagues found to be the difference between self-correction that helps and self-correction that hurts.6

Four ways to stop a repeated action, sorted by where each one acts.7186
Fix Where it acts What it supplies
Reflexion the transcript A written record of past attempts for the next trial to read.
Edit guardrail the harness A check that keeps a broken edit out of the transcript.
Recursion limit the harness A cap that ends the run, without breaking the loop.
Human interrupt outside the loop The judgment the model cannot form about its own work.

One caution sits over all of it. Not every repeated action is an unintended loop. Kapoor and colleagues note that repeating a step on purpose, sampling an answer several times and keeping the best, can match more elaborate agents at lower cost.9 A fix that suppresses all repetition can drop that useful strategy along with the failure. The test is whether the repeat is making progress, not whether it is a repeat. What is settled is the architecture, and that scaffolding of this kind helps: an explicit memory, a harness guardrail, and an outside judge each cut the looping their designers went after.71 What stays open is the layer beneath, why a model under-weights the error already in front of it, and whether it could be trained to correct itself reliably with no outside signal at all.6

The takeaway

A stuck agent is not a broken product. It is what the plain design does by default: a model that knows only what the transcript tells it, reading a transcript that still points at the failed step, while a harness runs whatever comes back. That is why raising the temperature or adding "try something else" to the prompt buys so little. They leave the transcript pointing the same way. The fixes that work change what the model reads or what the harness allows. They add a written record of what was already tried, a check that refuses the broken edit, or a person who supplies the judgment the model cannot form about its own work. When someone shows you an agent that no longer loops, ask which of those they changed. If the answer is none, the loop is still there, waiting for the input that sets it off.

Go deeper optional reading
01
SWE-agent (Yang et al., 2024): the coding-agent interface, its failure analysis, and the edit guardrail, in full.
02
Huang et al., 2023: the intrinsic-versus-oracle self-correction experiments behind the weak-signal step.

Sources

  1. Yang et al. · SWE-agent: Agent-Computer Interfaces Enable Automated Software Engineering (2024)
  2. Yao et al. · ReAct: Synergizing Reasoning and Acting in Language Models (2022)
  3. Liu et al. · AgentBench: Evaluating LLMs as Agents (2023)
  4. Significant Gravitas · AutoGPT issue #1994, "Gets stuck in a loop" (2023)
  5. Vectara · awesome-agent-failures: AutoGPT planning failures
  6. Huang et al. · Large Language Models Cannot Self-Correct Reasoning Yet (2023)
  7. Shinn et al. · Reflexion: Language Agents with Verbal Reinforcement Learning (2023)
  8. LangChain · LangGraph Graph API documentation
  9. Kapoor et al. · AI Agents That Matter (2024)