HANDOFF
Reporting on autonomous software

Agent stuck in a loop? LangGraph's step cap went from 25 to 10,007

An AI agent stuck in a loop runs until a step cap stops it. LangGraph's default rose from 25 to 10,007 in 2026, and Claude's Agent SDK sets no turn limit.

Reported figures
10,007
DEFAULT_RECURSION_LIMIT in langgraph/_internal/_config.py, read 21 October 2026 (release 1.2.16). Raised from 25 to 10,000 in commit a5827c5 on 12 January 2026 and to 10,007 in commit 2fb367e on 30 March 2026. Not our measurement.
By , Handoff Published 8 min read

Key takeaways

  • LangGraph raised its default recursion limit from 25 to 10,000 on 12 January 2026, and to 10,007 in March. The commit message says the burden should be on the user to enforce a limit for their application.
  • Defaults now disagree by three orders of magnitude: OpenAI's Agents SDK stops at 10 turns, LangGraph at 10,007 steps, and the Claude Agent SDK sets no turn or budget limit unless you pass one.
  • Step repetition was the most common failure mode in the MAST study of multi-agent systems, at 15.7% of annotated failures across 1,642 traces from 7 frameworks.
  • A step cap catches a loop late. Detect it early by hashing each tool call's name and arguments and stopping when the same hash recurs 3 times without a state change, a threshold that is our editorial judgement.
  • Cap spend as well as steps. The Claude Agent SDK's max_budget_usd can overshoot by up to one response, because cost is known only after the response returns.

LangGraph changed one default on 12 January 2026. Its recursion limit, the number of steps a graph may take before the framework raises an error, went from 25 to 10,000. In March it became 10,007. The commit message put the reasoning plainly: the burden should be on the user to enforce a limit for their application.

If your agent loops today, the framework may let it run for ten thousand steps. Whatever stops it sooner is code you have to write.

How long will a looping agent run before anything stops it?

That depends entirely on the framework default, and the defaults no longer agree.

Default step and spend limits in three agent frameworks, and what each raises when the limit is reached. Sources: LangGraph and OpenAI Agents SDK source, Claude Agent SDK documentation, all read 21 October 2026. Defaults change between releases; check the version you run.
FrameworkDefault step limitDefault spend limitOn limit
LangGraph 1.2.1610,007 stepsNoneGraphRecursionError
LangGraph before January 202625 stepsNoneGraphRecursionError
OpenAI Agents SDK 0.24.010 turnsNoneMaxTurnsExceeded
Claude Agent SDKNo limitNo limiterror_max_turns, error_max_budget_usd when set

The old LangGraph default of 25 stopped plenty of legitimate long runs, which is why it changed. The side effect is that a graph which used to fail fast in a loop now fails after about 400 times as many steps. Each of those steps is a model call that resends the whole context.

The Claude Agent SDK documentation states that without limits the loop runs until Claude finishes on its own, and recommends setting a budget as a default for production agents. OpenAI’s 10 turns is the only default here that will stop a loop within seconds, and it will also stop many honest tasks.

How common is step repetition?

Common enough to be the first thing to check.

The MAST study (Cemri et al., arXiv:2503.13657) annotated 1,642 execution traces from 7 open-source multi-agent frameworks and sorted failures into 14 modes, with inter-annotator agreement of 0.88. Step repetition was the largest single mode, at 15.7% of annotated failures. Being unaware of termination conditions accounted for 12.4%. Premature termination, the opposite problem, was 6.2%.

Those two leading modes describe the same loop from two sides. The agent repeats a step, and nothing in its instructions or state tells it that repeating will not help or that the job is already done.

What does a loop look like in the trace?

Mostly like repetition without change. These are the signals worth checking, cheapest first.

Signals that an agent run is looping, with how to detect each from the trace. The signals and thresholds are our editorial judgement, not a published benchmark.
SignalHow to detectCatches
Same call, same argumentsHash tool name plus canonical arguments; count repeatsRetrying a failing call unchanged
Same error, different wordingGroup tool errors by type and targetRephrasing around a hard failure
A-B-A-B alternationLook for a cycle of 2 to 3 hashes repeatingEdit, test, revert, test
No state changeCompare a digest of the state the task should changeBusy runs that make no progress
Steps far above the task medianCompare step count with the median for the task typeSlow loops that vary each step

The first row catches most loops for the price of one hash per step. The last row needs history, which is one reason to record steps per run as a defined metric rather than reading it from logs after the fact.

Where should the guard live?

In the orchestrator, below the model, with three limits rather than one.

A repeat detector stops the cheap, obvious loops early. A step cap stops the loops the detector misses. A spend cap stops the runs that vary every step and so never trip either, which is why run-level token budgets belong to the orchestrator and not to the prompt.

Set the step cap from data, not from the framework. A cap around three times the median step count for that task type leaves room for honest hard cases. That multiple is our judgement; the point is that 10,007 is nobody’s judgement about your workload.

The spend cap needs headroom. The Claude Agent SDK checks spend after each response arrives, so the response that crosses max_budget_usd still completes, and subagents still running can add more before they stop.

What should happen when the guard trips?

Stop the loop, keep the evidence, and hand the decision to something that can make it.

A tripped repeat detector is new information the model did not have. One option is to tell the model, once, that it has made the same call three times with the same result, and let it choose a different approach. If it repeats again, stop. Feeding the same error back a fourth time is what a loop already does.

When the run stops, save its state so a person or a later run can resume instead of starting over. Which state to persist at each step decides whether a stopped loop costs a restart or a resume.

The question to ask of any agent in production: if this run looped right now, which line of our code, not the framework’s, would stop it?

Frequently asked questions

Why is my AI agent stuck in a loop?

Usually because a tool keeps returning the same result and the model keeps trying the same call, or because nothing tells it the task is done. The MAST study found step repetition and unclear termination conditions among the most common failures.

What is the default recursion limit in LangGraph?

10,007 steps in current releases, set by DEFAULT_RECURSION_LIMIT and overridable with the LANGGRAPH_DEFAULT_RECURSION_LIMIT environment variable or recursion_limit in the run config. Before January 2026 it was 25.

What is the default max_turns in the OpenAI Agents SDK?

10. When a run exceeds it, the SDK raises MaxTurnsExceeded. You can pass a different max_turns to the runner.

Does the Claude Agent SDK stop an agent loop by default?

No. Both max_turns and max_budget_usd default to no limit, and the loop runs until Claude finishes. Anthropic's documentation recommends setting a budget as a default for production agents.

Method and sources

  1. LangChain, LangGraph source and history, read 21 October 2026: DEFAULT_RECURSION_LIMIT = 10007 in libs/langgraph/langgraph/_internal/_config.py; commit a5827c5 (PR #6676, 12 January 2026) changing 25 to 10000; commit 2fb367e (PR #7355, 30 March 2026) changing 10000 to 10007; GraphRecursionError in errors.py. Latest release at reading: 1.2.16.
  2. OpenAI, Agents SDK for Python source, read 21 October 2026: DEFAULT_MAX_TURNS = 10 in src/agents/run_config.py and the MaxTurnsExceeded exception. Latest release at reading: 0.24.0.
  3. Anthropic, How the agent loop works, Claude Agent SDK documentation, read 21 October 2026. Source of the no-limit defaults for max_turns and max_budget_usd, the error_max_turns and error_max_budget_usd result subtypes, and the budget overshoot of up to one response.
  4. Cemri et al., Why Do Multi-Agent LLM Systems Fail?, arXiv:2503.13657, v3, October 2025. Source of the MAST taxonomy of 14 failure modes, 1,642 annotated traces, 7 frameworks, kappa 0.88, and the 15.7%, 12.4% and 6.2% shares for step repetition, unawareness of termination conditions and premature termination.
  5. The detection signals, the repeat threshold of 3 and the guard actions are our editorial judgement. We ran no loop-detection experiment of our own.
OD

, Handoff at Handoff

The Orchestration desk of Handoff. Every figure here carries a source, a sample size and a date, and we say plainly what we have not measured ourselves.