-
Notifications
You must be signed in to change notification settings - Fork 15.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add safeguards for infinite loops and unresolvable tasks #28441
Conversation
modified: libs/core/langchain_core/prompts/prompt.py modified: libs/langchain/langchain/agents/react/agent.py - Updated the prompt template to include explicit termination instructions: 1. Avoid generating its own "User Input." 2. Gracefully terminate when progress cannot be made. 3. Use a fallback message for incomplete tasks. - Enhanced the output parser: - Detects repetitive reasoning and circular logic. - Handles invalid outputs and iteration limits. - Returns appropriate error messages for unresolvable scenarios. - Configured the AgentExecutor: - Set a maximum iteration limit to prevent infinite loops. - Ensures the agent stops reasoning after reaching the limit.
…ct agent - Updated `output_parsers/base.py` to detect and handle repetitive reasoning. - Enhanced `prompts/prompt.py` with constraints to avoid infinite loops and user input generation. - Improved `agents/react/agent.py` with logic for graceful termination and fallback handling.
deleted: libs/community/langchain_community/tools/fallback.py new file: libs/core/tests/integration_tests/test_react_agent.py new file: libs/core/tests/unit_tests/output_parsers/test_base.py new file: libs/core/tests/unit_tests/output_parsers/test_prompt.py
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
…hain into react_agent_test
modified: libs/langchain/langchain/agents/react/agent.py
modified: libs/langchain/langchain/agents/react/agent.py
modified: libs/langchain/langchain/agents/react/agent.py
modified: libs/langchain/langchain/agents/output_parsers/react_single_input.py
modified: libs/core/langchain_core/prompts/prompt.py
modified: libs/core/langchain_core/prompts/prompt.py
modified: libs/core/langchain_core/prompts/prompt.py modified: libs/core/tests/unit_tests/output_parsers/test_prompt.py
modified: libs/core/langchain_core/output_parsers/base.py modified: libs/core/langchain_core/prompts/prompt.py
modified: libs/core/langchain_core/agents.py modified: libs/core/langchain_core/output_parsers/base.py modified: libs/core/langchain_core/prompts/prompt.py
modified: libs/core/langchain_core/agents.py modified: libs/core/langchain_core/output_parsers/base.py modified: libs/core/langchain_core/prompts/prompt.py
hey there! I believe this would be better implemented by the user in a langgraph agent: https://langchain-ai.github.io/langgraph/tutorials/introduction/ This out of the box AgentExecutor does have shortcomings, hence the greater degree of control in langgraph. I don't think this change to AgentExecutor and supporting data objects is desirable, so I will close this PR |
Description
In the issue referenced below, the agent generates it's own "User Input" prompts during execution. Rather than using provided tools it requests input data from the user whick it cannot receive. This results in Inifinite loops, ultimately reaching the iteration limit, and provides the following error message. "Agent stopped due to iteration limit". In this PR we provided a proposed solution with associated unit and integration tests, for the specific instances of infinite loops from user input.
Issue: #25696
Dependencies:
No additional dependencies
Twitter Handle:
None