Langchain agent loops over the same tool producing the same result. #20501
Replies: 4 comments 4 replies
-
To address the issue where your
By focusing on these areas, you should be able to diagnose and resolve the looping behavior you're experiencing with the Sources
|
Beta Was this translation helpful? Give feedback.
-
This is also happening to me. Albeit intermittently. |
Beta Was this translation helpful? Give feedback.
-
Do you guys figure it out on how to stop the loop? Looks like the LLM doesnt understand the observation This is my prompt and the agent is making a loop on the same tool forever |
Beta Was this translation helpful? Give feedback.
-
I Solved this issue by changing the prompt while still using Changed from this
To this
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
prompt template:
CHAT_PROMPT_TEMPLATE = """
Respond to the human as helpfully and accurately as possible. You have access to the following tools:
{tools}
Use a json blob to specify a tool by providing an action key (tool name) and an action_input key (tool input).
Valid "action" values: "Final Answer" or {tool_names}
Provide only ONE action per $JSON_BLOB, as shown:
{{
"action": $TOOL_NAME,
"action_input": $INPUT
}}
Follow this format:
Question: input question to answer
Thought: consider previous and subsequent steps
Action:
Observation:
the result of the action
... (Proceed to Final Answer once the tool is executed)
Thought: I know what to respond
Action:
{{
"action": "Final Answer",
"action_input": "Final response to human"
}}
Once the agent is called, run the chosen tool only once. You shouldn't loop over the same tool.
If the tool executed successfully, write a positive response to the user empohasizing success of the action and stop the agent.
Begin! Reminder to ALWAYS respond with a valid json blob of a single action. Use tools if necessary. Respond directly if appropriate. Format is Action:```$JSON_BLOB Observation
Consider the previous chat history:
{chat_history}
New input: {input}
{agent_scratchpad}
"""
function to create agent:
Description
Agent loops over the same tool producing the same result.
Console output:
System Info
langchain==0.1.9
langchain-community==0.0.24
langchain-core==0.1.26
langchain-openai==0.0.7
langchain-anthropic==0.1.4
Beta Was this translation helpful? Give feedback.
All reactions