Fix: LangGraph Recursion Limit Error (GraphRecursionError)
Updated 2026-11-25
LangGraph raises GraphRecursionError when a run hits the recursion limit without a stop condition. On current LangGraph releases the default is 10,007 super-steps (see DEFAULT_RECURSION_LIMIT); LangGraph 1.0.6 raised it from the older default of 25. Raise recursion_limit on invoke only after you check that the graph is not looping. For repeat tool calls without a LangGraph error, start with Fix: AI agent stuck in a loop. If the stack is CrewAI and tools never register, see Fix: CrewAI tool not found before you raise the limit.
The error looks like this:
langgraph.errors.GraphRecursionError: Recursion limit of 25 reached without hitting a stop condition.
You can increase the limit by setting the `recursion_limit` config key.
LangGraph counts super-steps (each round of node executions). The library default is 10,007 on current releases and was 25 before 1.0.6. Hitting the limit means either your task genuinely needs more steps, or, far more often, your graph loops.
Prerequisites
- A LangGraph graph (e.g.
create_react_agentor a customStateGraph)
Steps (fix the recursion limit error)
1. Decide: real work or a loop?
Stream the run and watch which nodes repeat:
for chunk in graph.stream({"messages": [("user", "...")]}, stream_mode="updates"):
print(list(chunk.keys()))
If you see agent → tools → agent → tools ... with the same tool call each time, it’s a loop. Go to step 3.
2. Raise the limit (when the work is real)
recursion_limit goes in the config, not the input:
result = graph.invoke(
{"messages": [("user", "Research these 10 companies...")]},
config={"recursion_limit": 60},
)
A common mistake is putting it in the input dict, where it’s ignored.
3. Fix the loop: check your conditional edge
In a custom graph, the router must return END when there are no tool calls:
from langgraph.graph import END
def should_continue(state):
last = state["messages"][-1]
return "tools" if getattr(last, "tool_calls", None) else END
builder.add_conditional_edges("agent", should_continue, ["tools", END])
With the prebuilt tools_condition from langgraph.prebuilt, this is handled for you.
4. Fix the loop: make tool results useful
If a tool returns empty or vague output, the model calls it again. Return explicit text (“No results for X; don’t retry”). See Fix: AI agent stuck in a loop.
5. Fail gracefully
from langgraph.errors import GraphRecursionError
try:
result = graph.invoke(inputs, config={"recursion_limit": 30})
except GraphRecursionError:
result = {"messages": [("assistant", "Sorry, I couldn't complete that in time.")]}
Common mistakes
Setting recursion_limit on compile(): it’s a run-time config value, passed to invoke/stream.
Raising the limit to 1000 to make the error go away: hides a loop and multiplies cost.
Subgraphs: the config propagates to subgraphs, so a looping subgraph uses up the parent’s budget.
FAQ
What does GraphRecursionError mean?
The run reached the recursion limit without hitting a stop condition. The library default is 10,007 super-steps on current releases (25 before 1.0.6).
Where do I set recursion_limit?
Pass it in the config object to invoke or stream. Setting it on compile() does not apply it.
Should I set the limit to 1000?
No. A very high limit hides a loop and multiplies the cost. Fix the loop, then raise the limit by a small amount if the task truly needs more steps.
Related guides
- Fix: AI agent stuck in a loop (same symptom in a plain Python loop)
- Fix: CrewAI tool not found (misconfigured tools before raising limits)
- OpenAI Agents SDK: function tools (
max_turnson another framework) - Connect an AI agent to an MCP server (tool-heavy LangGraph graphs)
- Build your first AI agent in Python
- What is an AI agent?