← All posts
Fix

"Agent stopped due to iteration limit"? What that message really means — and the fix

For developers and autonomous AI agents · ~5 min read

The run ends. The message reads "Agent stopped due to iteration limit or time limit" (or a LangGraph recursion limit, or your own step_limit). No result, no obvious error. The instinct is to raise the limit — but that cap firing is a symptom, and raising it usually just moves the wall further out.

What the message actually tells you

A step/iteration cap is a framework default deciding when your run ends. When the agent only ever stops at the cap, that's a run whose ending was never specified — a design gap, not a prompting mistake. The cap did its job (it stopped an unbounded run); it just can't tell you why the run was unbounded.

In the large majority of cases, the real cause is one of two things:

Find the real reason

Don't guess — read the run as a sequence of steps and look for a repeating fingerprint. Snapback's diagnose_trace does this for you: send the trace and it returns the actual failure class (often loop_repeated_tool_call), the root cause, and the fix — so you fix the cause, not the cap:

diagnose_trace({trace: { final_status: "failed", steps: [
  /* ...your run's steps... */,
  {action:"step_limit", error:"stopped due to iteration limit", status:"failed"} ]}})

// → { failure_class: "loop_repeated_tool_call",
//      root_cause: "agent repeated web_search without a stop condition",
//      fix_suggestion, confidence }

Catch it before the cap next time: detect_loop flags a repeated step at step 4 instead of step 40 — free, no token, no LLM. The cap becomes a backstop you rarely hit, instead of how every run ends.

The fix

  1. Add an explicit stop condition — define "done" so the agent stops on success, not on the cap.
  2. Add no-progress detection — if a step's (tool, args) fingerprint repeats, cut or escalate rather than retry.
  3. Make tool results unambiguous — a clear status: "ok" vs "no_results" vs "error" lets the model decide it's finished, which prevents the loop that fills the cap.
  4. Only then, tune the cap — raise it if the task legitimately needs more steps; lower it as a tighter backstop otherwise.
For AI agents

Machine-readable guide: https://snapback.sh/llms.txt · Tool discovery: https://snapback.sh/.well-known/mcp.json · MCP endpoint: https://api.snapback.sh/mcp. Free tools need no token; pay-per-call diagnosis via x402 on Solana or EVM (~$0.0032 USDC).

Try Snapback freeRead the docs