Skip to content

TeamTool fails to execute twice for one Agent #6882

@p-gawluk

Description

@p-gawluk

What happened?

Describe the bug
It seems that Autogen has troubles calling TeamTool twice for one Agent. First execution completes, but second is failing due to team that is already running.

To Reproduce
Following snippet will reproduce bug. Just replace LLM config with yours.

import asyncio

from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.conditions import SourceMatchTermination
from autogen_agentchat.tools import TeamTool
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_agentchat.ui import Console
from autogen_ext.models.openai import AzureOpenAIChatCompletionClient

default_model_client = AzureOpenAIChatCompletionClient(
            azure_endpoint=default_llm_model.azure_endpoint,
            api_version=default_llm_model.api_version,
            azure_deployment=default_llm_model.azure_deployment,
            model=default_llm_model.model,
            api_key=default_llm_model.api_key,
        )

async def main() -> None:
    model_client = default_model_client

    writer = AssistantAgent(name="writer", model_client=model_client, system_message="You are a helpful assistant.")
    reviewer = AssistantAgent(name="reviewer", model_client=model_client, system_message="You are a critical reviewer.")
    summarizer = AssistantAgent(
        name="summarizer",
        model_client=model_client,
        system_message="You combine the review and produce a revised response.",
    )
    team = RoundRobinGroupChat(
        [writer, reviewer, summarizer], termination_condition=SourceMatchTermination(sources=["summarizer"])
    )

    # Create a TeamTool that uses the team to run tasks, returning the last message as the result.
    tool = TeamTool(
        team=team, name="writing_team", description="A tool for writing tasks.", return_value_as_last_message=True
    )

    main_agent = AssistantAgent(
        name="main_agent",
        model_client=model_client,
        system_message="You are a helpful assistant that can use the writing tool.",
        tools=[tool],
    )
    # For handling each events manually.
    # async for message in main_agent.run_stream(
    #     task="Write a short story about a robot learning to love.",
    # ):
    #     print(message)
    # Use Console to display the messages in a more readable format.
    await Console(
        main_agent.run_stream(
            task="Write a two short stories about a robot learning to love.",
        )
    )


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Part of console output:

---------- ToolCallRequestEvent (main_agent) ----------
[FunctionCall(id='call_6zLWv0PuEG8KzKqnku4JT27t', arguments='{"task": "Write a short story about a robot learning to love."}', name='writing_team'), FunctionCall(id='call_nnUcVQJjHF9GTwZCdIDyTLkz', arguments='{"task": "Write another short story about a robot learning to love."}', name='writing_team')]

... team tool output ...

---------- ToolCallExecutionEvent (main_agent) ----------
[FunctionExecutionResult(content='Years passed in Neo-Luna[...]', name='writing_team', call_id='call_6zLWv0PuEG8KzKqnku4JT27t', is_error=False), 


FunctionExecutionResult(content='The team is already running, it cannot run again until it is stopped.', name='writing_team', call_id='call_nnUcVQJjHF9GTwZCdIDyTLkz', is_error=True)]

Full console output:
team-tool-bug-console.txt

Expected behavior
Two stories are printed in Console, no The team is already running, it cannot run again until it is stopped. error reported.

Additional context
Snippet were taken from this official documentation, I've just modified user prompt to include two stories, instead of one.

Which packages was the bug in?

Python AgentChat (autogen-agentchat>=0.4.0)

AutoGen library version.

Python 0.7.1 (but it also occurred in 0.6.1 as well)

Other library version.

No response

Model used

gpt-4o-2024-05-13

Model provider

Azure OpenAI

Other model provider

No response

Python version

3.13

.NET version

None

Operating system

Windows

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions