Skip to content
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

In a Swarm team the tool call output of an agent is not transferred to the next agent. #5045

Open
ekzhu opened this issue Jan 14, 2025 · 1 comment
Assignees
Milestone

Comments

@ekzhu
Copy link
Collaborator

ekzhu commented Jan 14, 2025

Originally discovered via #5038

How to reproduce?

import asyncio
from datetime import datetime
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.teams import Swarm
from autogen_agentchat.messages import HandoffMessage
from autogen_agentchat.ui import Console
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_agentchat.conditions import HandoffTermination, MaxMessageTermination


def execute_git_current_time():
    return datetime.now().strftime("%H:%M:%S")

def get_current_day():
    return datetime.now().strftime("%A")


async def main() -> 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 agents
    handoff_termination = HandoffTermination(target="user")
    max_messages_termination = MaxMessageTermination(max_messages=100)
    termination = handoff_termination | max_messages_termination
    
    team = Swarm(
        participants=[router, time_agent, day_agent, formatter],
        termination_condition=termination,
    )

    await Console(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.

@ekzhu ekzhu added this to the 0.4.2 milestone Jan 14, 2025
@ekzhu ekzhu self-assigned this Jan 14, 2025
@ekzhu 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
@ekzhu
Copy link
Collaborator Author

ekzhu commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants