Skip to content

GraphRecursionError: Recursion limit of … reached without hitting a stop condition

Cause: Your LangGraph agent ran the maximum number of steps without reaching an end state, usually because it keeps calling the same tool or bouncing between nodes.

Copy-paste fix

Catch the error, and add a guard that stops when the agent repeats the same tool call with the same arguments.

import json
from collections import Counter
from langgraph.errors import GraphRecursionError

calls = Counter()

def guard_tool_call(name, args, max_repeats=2):
    key = (name, json.dumps(args, sort_keys=True, default=str))
    calls[key] += 1
    if calls[key] > max_repeats:
        raise RuntimeError(f"Tool loop: {name} called {calls[key]} times "
                           "with the same arguments")

try:
    result = graph.invoke(inputs, {"recursion_limit": 40})
except GraphRecursionError:
    # log the last steps and return a clear failure instead of retrying
    raise

See what each extra agent step costs on TokenCenter

What the error means

LangGraph raises GraphRecursionError with the message “Recursion limit of N reached without hitting a stop condition. You can increase the limit by setting the recursion_limit config key.”

LangGraph's docs say this is often an infinite loop, though complex graphs can reach the limit naturally. Raising the limit hides a loop and multiplies the tokens it burns, so look for the loop first.

Checklist

  1. Make sure every path through the graph can reach END.
  2. Give tools clear success and failure results, so the model doesn't retry a tool that already answered.
  3. Stop on repeated identical tool calls.
  4. Cap total steps and total tokens per run, not just recursion depth.
  5. Log each step's node and tool name so a loop is easy to see.
  6. Raise recursion_limit only for graphs you know are long and loop-free.

Related

Sources

All guides · All errors