Find answers from the community

Updated 5 days ago

I was building a multi-agent workflow, where each agent has multiple tools. I started the

@kapa.ai I was building a multi-agent workflow, where each agent has multiple tools. I started the workflow with user query, the query goes to the root agent and calls the relevant tools, after the tool execution, the root agent handoff control to the next agent but not calling the required tools and the code execution stops, I don't see any error and have checked individual agents as well. Can anyone help ?
k
Z
L
18 comments
Please stand by @Zenitsu as I search the knowledge base. I normally take about 15 seconds or so. :wave:
----------------------
Based on the information provided in the knowledge sources, I can offer some insights into your multi-agent workflow issue with LlamaIndex. It seems you're using the AgentWorkflow class to create a multi-agent system, but encountering an issue with tool execution and agent handoff. Let's break down the problem and potential solutions:

  1. Agent and Tool Setup:
    Make sure you've properly set up your agents and their respective tools. Each agent should have a clear definition of its responsibilities and the tools it can use. For example:
Plain Text
   research_agent = FunctionAgent(
       name="ResearchAgent",
       description="Useful for searching the web for information on a given topic and recording notes on the topic.",
       system_prompt="...",
       llm=llm,
       tools=[search_web, record_notes],
       can_handoff_to=["WriteAgent"],
   )
   


Ensure that each agent has the correct can_handoff_to parameter set, indicating which agents it can hand off control to.

  1. AgentWorkflow Configuration:
    Verify that your AgentWorkflow is correctly configured with all the agents and the root agent:
Plain Text
   agent_workflow = AgentWorkflow(
       agents=[research_agent, write_agent, review_agent],
       root_agent=research_agent.name,
       initial_state={
           "research_notes": {},
           "report_content": "Not written yet.",
           "review": "Review required.",
       },
   )
   


  1. Handoff Mechanism:
    The handoff between agents is managed by the AgentWorkflow class. After a tool execution, the workflow should automatically handle the handoff to the next agent. If this isn't happening, there might be an issue with the handoff logic or the way the agents are communicating their intent to hand off control.
  1. Tool Execution:
    Ensure that your tools are properly defined and can be executed by the agents. Each tool should be an async function that can be called by the agent.
  1. Debugging:
    To better understand what's happening during the workflow execution, you can add more detailed logging or use the event streaming feature provided by LlamaIndex. This can help you see exactly where the execution is stopping:
Plain Text
   handler = agent_workflow.run(user_msg="Your query here")

   async for event in handler.stream_events():
       if isinstance(event, AgentOutput):
           print("Agent Output:", event.response.content)
           print("Tool Calls:", [call.tool_name for call in event.tool_calls])
       elif isinstance(event, ToolCallResult):
           print(f"Tool Result ({event.tool_name}):")
           print(f"  Arguments: {event.tool_kwargs}")
           print(f"  Output: {event.tool_output}")
   


  1. Check for Silent Errors:
    Sometimes, errors might be suppressed or not properly propagated. You can try wrapping your workflow execution in a try-except block to catch any potential exceptions:
Plain Text
   try:
       handler = agent_workflow.run(user_msg="Your query here")
       # ... rest of your code
   except Exception as e:
       print(f"An error occurred: {e}")
   


  1. State Management:
    Ensure that the state is being properly managed and passed between agents. The AgentWorkflow uses a Context object to manage state, which should be accessible to all agents.
If you've checked all these points and are still experiencing issues, it might be helpful to review the Multi-agent systems with AgentWorkflow documentation for more detailed information on how the workflow should function.
Remember, the AgentWorkflow is designed to manage the flow of control between agents, including tool execution and handoffs. If it's stopping unexpectedly, there might be an issue with how the agents are deciding to hand off control or how they're processing the results of tool calls.

If you continue to face issues, you may want to consider posting a more detailed description of your setup, including your agent definitions and the specific query you're using, on the LlamaIndex community forums or GitHub issues for more targeted assistance.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
It is doing the handoff properly, but not calling the current agent's tools
Some prompts could be not clear (system prompts, tool names/descriptions). Or, some back and forth might be needed. If its not calling a tool, its responding directly
Thanks for the response @Logan M .....I have tested each agent's tool calling ability and everything was working good. Just wanted to ask, if individual agents are working fine then could the problem be something else ?
I don't think so? What is the agent returning if its not calling a tool? What's the response?
We have three agents, agent_1 is for making a checklist of queries from the input documents say pdf documents, then agent_2 will add certain guidelines for the checklist queries, which will be used by agent_3 to evaluate the documents responses over the query.

agent_1 does the job when inputted the documents, it calls a tool for generating a checklist and prepare an excel sheet. This agent successfully handoff control to agent_2 for adding guidelines for the queries.

agent_2 receives the handoff and instead of calling the tool to ad guidelines, it just say, the guidelines have been added and the new excel sheet is saved, which is it's actual task but tool calling is missing.
Sometimes it says the task has been handed off to the agent_2. Please proceed with the request.
and just like that the file stops executing.
the second response is pretty common by the agent_2
I was reading the below article, this having the same problem and they have overridden the FunctionAgent class for some modifications.
https://www.dataleadsfuture.com/diving-into-llamaindex-agentworkflow-a-nearly-perfect-multi-agent-orchestration-solution/
Now my code is working πŸ™‚
The article is behind a paywall @Zenitsu -- how did you handle it? I'm actually really curious, I wonder if I can improve anything in the framework
This was the reason
Attachment
Screenshot_2025-03-12_at_4.10.57_PM.png
I have appended the user query message to the latest chat memory shared by the agents
Added the below handoff_output_prompt in the worflow :

handoff_output_prompt=(
"handoff_result: Due to {reason}, the user's request has been passed to {to_agent}."
"Please review the conversation history immediately and continue responding to the user's request."
),
ahhhh ok, interesting, I think I can make a change to just include the users original request in the handoff output πŸ‘€ That way it doesn't get lost due to token limits?
Good idea, I believe you can do that as well just test its working. For me appending the user message as the latest message in the chat history works properly.
Add a reply
Sign up and join the conversation on Discord