multi agent system with a supervisor stuck in a loop of endlessly calling the same agent over and over again #17872
Replies: 2 comments 3 replies
-
🤖 Based on the information you've provided, it seems like the supervisor agent is stuck in a loop where it keeps invoking the same agent. This could be due to the logic in your Firstly, I would recommend checking the logic in your Secondly, you might want to consider limiting the number of times an agent can be invoked consecutively. This can be done by adding a counter that increments each time the same agent is invoked and resets when a different agent is invoked. If the counter reaches a certain limit, you can force the supervisor to select a different agent. Here's a rough example of how you could implement this: class AgentExecutor:
def __init__(self, agent, tools, max_iterations=2):
self.agent = agent
self.tools = tools
self.max_iterations = max_iterations
self.iterations = 0
self.last_agent = None
def invoke(self, state):
if self.last_agent == self.agent and self.iterations >= self.max_iterations:
# Force the supervisor to select a different agent
return {"output": "FINISH"}
result = self.agent(state)
if self.last_agent == self.agent:
self.iterations += 1
else:
self.iterations = 0
self.last_agent = self.agent
return result In this code, Please note that this is a simplified example and you might need to adjust it to fit your specific use case. Regarding the changes in the LangChain repository after version 0.1.5, the major change that could potentially affect the behavior of the supervisor agent is the relocation of the I hope this helps! If you have any further questions, feel free to ask. Sources
|
Beta Was this translation helpful? Give feedback.
-
🤖 Based on the code you've shared, it seems like the issue might be related to how the In your Here's a simplified example of how the def route(state):
# Analyze the state of the conversation
# For example, check the last message sent by the user
last_user_message = state["messages"][-1]["content"]
# Based on the last user message, decide the next agent
if "graph" in last_user_message:
return "Graph Retriever"
elif "financial" in last_user_message:
return "Financial Analyst"
elif "presentation" in last_user_message:
return "Presentation Generator"
else:
return "FINISH" In this example, the Please note that this is a very simplified example and the actual implementation of the I hope this helps! If you have any more questions, feel free to ask. Sources
|
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
I am trying to implement the proposed multi-agent with supervisor architecture presented here using LangGraph. The supervisor agent is supposed to take a user's question and decide which agent should go next, the selected agent then reports back with findings and then supervisor agent selects whether to finish or to call another agent and so on until the supervisor returns Finish. My problem is that when I run the graph the supervisor agent keeps on invoking the same agent over and over again and the user never gets a final response back. Here are the functions I am using to define the agents, agent nodes, and the supervisor:
Why is this happening? what am I wrongly implementing the multi-agent with supervisor graph? what do I need to fix about the code to ensure that the graph chain takes a question , calls the right agents, and retrieves the final answer to the user?
System Info
langchain==0.1.5
langchain-community==0.0.17
langchain-core==0.1.16
langchain-experimental==0.0.50
langchain-openai==0.0.5
langchainhub==0.1.14
python==3.10.12
Beta Was this translation helpful? Give feedback.
All reactions