You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importasynciofromdatetimeimportdatetimefromautogen_agentchat.agentsimportAssistantAgentfromautogen_agentchat.teamsimportSwarmfromautogen_agentchat.messagesimportHandoffMessagefromautogen_agentchat.uiimportConsolefromautogen_ext.models.openaiimportOpenAIChatCompletionClientfromautogen_agentchat.conditionsimportHandoffTermination, MaxMessageTerminationdefexecute_git_current_time():
returndatetime.now().strftime("%H:%M:%S")
defget_current_day():
returndatetime.now().strftime("%A")
asyncdefmain() ->None:
model_client=OpenAIChatCompletionClient(model="gpt-4o")
router=AssistantAgent(
name="router",
system_message="""You are a router agent that analyzes user questions and directs them to the appropriate agent. Your role is to: 1. Analyze the user's input 2. Determine if they're asking about: - handoff to time_agent for questions about time - handoff to day_agent for questions about date """,
model_client=model_client,
handoffs=["day_agent", "time_agent"],
)
time_agent=AssistantAgent(
name="time_agent",
system_message="""You are a time agent that provides the current time. Send the time information to the formatter agent.""",
model_client=model_client,
tools=[execute_git_current_time],
handoffs=["formatter"],
)
day_agent=AssistantAgent(
name="day_agent",
system_message="""You are a day agent that provides the current day. Send the day information to the formatter agent.""",
model_client=model_client,
tools=[get_current_day],
handoffs=["formatter"],
)
formatter=AssistantAgent(
name="formatter",
system_message="""You are a formatter agent that formats time and day information. Send the formatted information to the user.""",
model_client=model_client,
handoffs=["user"],
)
# Create a team with all agentshandoff_termination=HandoffTermination(target="user")
max_messages_termination=MaxMessageTermination(max_messages=100)
termination=handoff_termination|max_messages_terminationteam=Swarm(
participants=[router, time_agent, day_agent, formatter],
termination_condition=termination,
)
awaitConsole(team.run_stream(
task=HandoffMessage(
source="user",
target="router",
content="What time is it?",
)
))
asyncio.run(main())
---------- user ----------
What time is it?
---------- router ----------
[FunctionCall(id='call_5KY9tHOOWodejGtz4nYYoL0R', arguments='{}', name='transfer_to_time_agent')]
---------- router ----------
[FunctionExecutionResult(content='Transferred to time_agent, adopting the role of time_agent immediately.', call_id='call_5KY9tHOOWodejGtz4nYYoL0R')]
---------- router ----------
Transferred to time_agent, adopting the role of time_agent immediately.
---------- time_agent ----------
[FunctionCall(id='call_NonawoVdSBG55rBC83cdBFiB', arguments='{}', name='execute_git_current_time'), FunctionCall(id='call_H77Mry5mJmoqCt6jkYjjAYX9', arguments='{}', name='transfer_to_formatter')]
---------- time_agent ----------
[FunctionExecutionResult(content='10:40:07', call_id='call_NonawoVdSBG55rBC83cdBFiB'), FunctionExecutionResult(content='Transferred to formatter, adopting the role of formatter immediately.', call_id='call_H77Mry5mJmoqCt6jkYjjAYX9')]
---------- time_agent ----------
Transferred to formatter, adopting the role of formatter immediately.
---------- formatter ----------
[FunctionCall(id='call_1zPjDwrcRMZggaJ84inYbjOg', arguments='{}', name='transfer_to_user')]
---------- formatter ----------
[FunctionExecutionResult(content='Transferred to user, adopting the role of user immediately.', call_id='call_1zPjDwrcRMZggaJ84inYbjOg')]
---------- formatter ----------
Transferred to user, adopting the role of user immediately.
You can see the tool call result of getting the current time is not transferred to the formatter in the handoff.
The text was updated successfully, but these errors were encountered:
ekzhu
changed the title
Swarm team with parallel function call is causing the tool call output not transferred to the next agent.
In a Swarm team the tool call output of an agent is not transferred to the next agent.
Jan 14, 2025
Note, this problem will still arise when parallel tool call is disabled, as the transfer message doesn't let agent reflect on the tool call.
Actually this is False, the tool result summary message will share the context. We just need to handle the case when tool calls happen in the same turn when handoff happens.
Originally discovered via #5038
How to reproduce?
You can see the tool call result of getting the current time is not transferred to the formatter in the handoff.
The text was updated successfully, but these errors were encountered: