LLM Retries Are a Tax on Productivity
People have been trained to view retries as normal. After all, LLMs make mistakes and retried tasks are par for the course in LLM operations. But steadily and silently, token costs can add up. LLM loops, which result in a prompt being sent repeatedly, and incorrect responses are frustrating, and a cost sink.
Why AI Agents Get Stuck in Loops
LLM looping is defined as when an agent repeatedly attempts the same action because something went wrong and it does not know how to move past it (sometimes this causes an llm to go into an infinte loop). A single long-running loop can consume tens of thousands of tokens before it is noticed.
This is why understanding what an AI agent loop looks like, detection strategies, and how to prevent the LLM from repeating itself are critical cost management skills.
The Cost of AI Agent Loops
In the simulation, the cost of retry loops was measured with variable called the retry multiplier, or the ratio of actual agent turns a task requires to the minimum turns needed to complete it. A retry multiplier of 1.0 means the task was done in the fewest possible turns. A multiplier of 5.0 means the task took five times as many turns as necessary. The chart above compares CPST and monthly cost at these two levels.
A blended CPST rate was calculated for the monthly task set studied in the simulation: i.e., planning, review, bugfix, and feature tasks. This blended rate was then multiplied by the retry multiplier from 1.0 to 5.0. The two bars show CPST and average monthly cost at each extreme.
Simulated users with a low retry rate (1.0) averaged $5.73 per successful task and roughly $232 per month. Users with a high retry rate (5.0) averaged $28.65 per successful task and roughly $1,160 per month, which represents a 5× difference in both metrics, a $928 gap.
Every unnecessary turn adds both input tokens (the re-prompt and the growing context window) and output tokens (the model's new response). The cost compounds with every extra back-and-forth.
This is the largest cost driver the simulation uncovered. Bai and colleagues found the same task can vary up to 30× in token consumption depending on how the agent is used. The retry multiplier isolates one source of that variation: unnecessary agent turns that add tokens, cost, and delay without producing better output.
How to Prevent an LLM Agent from Repeating Itself
Preventing AI agent loops requires understanding why they happen. Three factors dominate.
-
Contaminated context: When an agent fails and retries, the failed attempt stays in the conversation history and makes the next attempt more likely to fail too. A May 2026 study from Rutgers University introduced the Context-Contaminated Restart Model (CCRM) to quantify this, finding that failed attempts raise the per-step error rate by 7.1× over the baseline rate. The model shows this is not a gentle degradation: once a failure contaminates context, every subsequent retry operates in a worse error environment. Clearing context before retrying resolves 21% more tasks on the same budget.
-
Poor prompt design: Ambiguous instructions cause agents to drift over multiple steps, calling tools with bad arguments or forgetting earlier instructions. Without explicit stop conditions, the model will recycle through the same failed attempt because nothing in the prompt told it to accumulate failure state or treat identical consecutive failures as a stopping signal. Nesyona documents that the Action-Loop Guardrail, a four-phase structure requiring the model to observe, reason, act, verify, and check stop conditions at each iteration, prevents this by carrying a no-progress counter in the verify step and triggering a clean exit when consecutive failures are detected.
-
Over-reliance on model judgment: Without explicit budgets, agents will retry indefinitely. The cost amplification is worse than most engineers expect. A 20% retry rate on a 3-step agent produces 1.7 to 1.9× baseline token cost. On a 5-step agent at the same 20% retry rate, costs can ballon 2.2 to 2.5×. Because agent frameworks like LangChain and the OpenAI and Anthropic SDKs replay the full conversation history on each retry, not just the failed step. The cumulative context cost compounds signficantly in context size.
The research points to three matching safeguards:
-
Retry budgets cap the tokens allocated to retries, which prevents runaway agents.
-
Context compaction triggers use rolling summaries and periodic history truncation to prevent contamination from accumulating.
-
Prompt patterns with explicit stop conditions require the model to verify results and track consecutive failures, addressing the root cause rather than treating symptoms.
Together, these three layers form the baseline defense against costly retry loops.