(docs): add examples on recursion counter access and proactive handling in graph-api #1166
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Expanded docs for accessing and handling the recursion counter in LangGraph graphs, enabling developers to implement proactive recursion management before hitting limits.
Type of change
Type: Update existing documentation
Checklist
docs devsrc/docs.jsonif neededAdditional notes
This PR extends the existing "Recursion limit" section in the Graph API documentation with detailed guidance on accessing
config.metadata.langgraph_stepand implementing proactive recursion handling.What's Added
1. How it works - Explains where the step counter is stored and how the recursion limit check logic works in both Python (
config["metadata"]["langgraph_step"]) and TypeScript (config.metadata.langgraph_step).2. Accessing the current step counter - Simple code examples showing how to read the step counter within node functions.
3. Proactive recursion handling - Complete working examples demonstrating:
4. Proactive vs reactive approaches - Side-by-side comparison including:
5. Other available metadata - Documents additional metadata fields available in config (node, triggers, path, checkpoint namespace).
Motivation
Currently, the documentation explains the recursion limit configuration but doesn't cover how developers can access the current step counter or implement proactive handling strategies. This leads developers to only discover reactive error handling (catching
GraphRecursionError) rather than implementing graceful degradation patterns within their graphs. This addition enables better user experiences by allowing graphs to complete normally with partial results rather than throwing exceptions.