[PR #6889] fix(prebuilt): detect infinite tool call loops in create_react_agent #5378

Closed
opened 2026-02-20 17:51:37 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langchain-ai/langgraph/pull/6889

State: closed
Merged: No


Description: Add loop detection to create_react_agent's routing logic to prevent agents from entering infinite loops when the LLM repeatedly requests the same tool call with the same arguments (e.g., due to persistent tool failures). The should_continue function now inspects the last 3 AIMessage tool calls and raises a GraphRecursionError early if they are semantically identical, providing a clear error message to the developer.

Issue: #6731

Dependencies: None

**Original Pull Request:** https://github.com/langchain-ai/langgraph/pull/6889 **State:** closed **Merged:** No --- Description: Add loop detection to create_react_agent's routing logic to prevent agents from entering infinite loops when the LLM repeatedly requests the same tool call with the same arguments (e.g., due to persistent tool failures). The should_continue function now inspects the last 3 AIMessage tool calls and raises a GraphRecursionError early if they are semantically identical, providing a clear error message to the developer. Issue: #6731 Dependencies: None
yindo added the pull-request label 2026-02-20 17:51:37 -05:00
yindo closed this issue 2026-02-20 17:51:37 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#5378