From 863b8d05a29314369f4472571b3520260aa73ec4 Mon Sep 17 00:00:00 2001 From: Eric Zhu Date: Fri, 1 Nov 2024 05:43:02 -0700 Subject: [PATCH 1/2] Remove termination condition from team constructor --- .../autogen_agentchat/teams/_group_chat/_base_group_chat.py | 4 +--- .../teams/_group_chat/_round_robin_group_chat.py | 3 +-- .../teams/_group_chat/_selector_group_chat.py | 4 +--- .../teams/_group_chat/_swarm_group_chat.py | 6 ++---- python/packages/autogen-agentchat/tests/test_group_chat.py | 4 ++-- 5 files changed, 7 insertions(+), 14 deletions(-) diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat.py b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat.py index 78ec5159e36..e035a987436 100644 --- a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat.py +++ b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat.py @@ -33,7 +33,6 @@ def __init__( self, participants: List[ChatAgent], group_chat_manager_class: type[BaseGroupChatManager], - termination_condition: TerminationCondition | None = None, ): if len(participants) == 0: raise ValueError("At least one participant is required.") @@ -42,7 +41,6 @@ def __init__( self._participants = participants self._team_id = str(uuid.uuid4()) self._base_group_chat_manager_class = group_chat_manager_class - self._termination_condition = termination_condition @abstractmethod def _create_group_chat_manager_factory( @@ -133,7 +131,7 @@ async def run_stream( group_topic_type=group_topic_type, participant_topic_types=participant_topic_types, participant_descriptions=participant_descriptions, - termination_condition=termination_condition or self._termination_condition, + termination_condition=termination_condition, ), ) # Add subscriptions for the group chat manager. diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_round_robin_group_chat.py b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_round_robin_group_chat.py index cec47f6e1b1..b2dcdb64029 100644 --- a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_round_robin_group_chat.py +++ b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_round_robin_group_chat.py @@ -103,10 +103,9 @@ async def get_weather(location: str) -> str: """ - def __init__(self, participants: List[ChatAgent], termination_condition: TerminationCondition | None = None): + def __init__(self, participants: List[ChatAgent]): super().__init__( participants, - termination_condition=termination_condition, group_chat_manager_class=RoundRobinGroupChatManager, ) diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_selector_group_chat.py b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_selector_group_chat.py index ed7694d3858..d91d89e26a5 100644 --- a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_selector_group_chat.py +++ b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_selector_group_chat.py @@ -230,9 +230,7 @@ def __init__( """, allow_repeated_speaker: bool = False, ): - super().__init__( - participants, termination_condition=termination_condition, group_chat_manager_class=SelectorGroupChatManager - ) + super().__init__(participants, group_chat_manager_class=SelectorGroupChatManager) # Validate the participants. if len(participants) < 2: raise ValueError("At least two participants are required for SelectorGroupChat.") diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_swarm_group_chat.py b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_swarm_group_chat.py index 0f4ec0e63a4..0afc41afe98 100644 --- a/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_swarm_group_chat.py +++ b/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_swarm_group_chat.py @@ -85,10 +85,8 @@ class Swarm(BaseGroupChat): print(message) """ - def __init__(self, participants: List[ChatAgent], termination_condition: TerminationCondition | None = None): - super().__init__( - participants, termination_condition=termination_condition, group_chat_manager_class=SwarmGroupChatManager - ) + def __init__(self, participants: List[ChatAgent]): + super().__init__(participants, group_chat_manager_class=SwarmGroupChatManager) # The first participant must be able to produce handoff messages. first_participant = self._participants[0] if HandoffMessage not in first_participant.produced_message_types: diff --git a/python/packages/autogen-agentchat/tests/test_group_chat.py b/python/packages/autogen-agentchat/tests/test_group_chat.py index 4e1485ce309..72fdc6bcd68 100644 --- a/python/packages/autogen-agentchat/tests/test_group_chat.py +++ b/python/packages/autogen-agentchat/tests/test_group_chat.py @@ -516,8 +516,8 @@ async def test_swarm_handoff() -> None: second_agent = _HandOffAgent("second_agent", description="second agent", next_agent="third_agent") third_agent = _HandOffAgent("third_agent", description="third agent", next_agent="first_agent") - team = Swarm([second_agent, first_agent, third_agent], termination_condition=MaxMessageTermination(6)) - result = await team.run("task") + team = Swarm([second_agent, first_agent, third_agent]) + result = await team.run("task", termination_condition=MaxMessageTermination(6)) assert len(result.messages) == 6 assert result.messages[0].content == "task" assert result.messages[1].content == "Transferred to third_agent." From 815ef034d5b7e0bfd6bb094768c2becf84263051 Mon Sep 17 00:00:00 2001 From: Eric Zhu Date: Fri, 1 Nov 2024 05:47:47 -0700 Subject: [PATCH 2/2] fix usage --- .../docs/src/user-guide/agentchat-user-guide/quickstart.ipynb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/quickstart.ipynb b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/quickstart.ipynb index 52f4b1baa91..3c37aee209e 100644 --- a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/quickstart.ipynb +++ b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/quickstart.ipynb @@ -81,10 +81,11 @@ ")\n", "\n", "# add the agent to a team\n", - "agent_team = RoundRobinGroupChat([weather_agent], termination_condition=MaxMessageTermination(max_messages=2))\n", + "agent_team = RoundRobinGroupChat([weather_agent])\n", "# Note: if running in a Python file directly you'll need to use asyncio.run(agent_team.run(...)) instead of await agent_team.run(...)\n", "result = await agent_team.run(\n", " task=\"What is the weather in New York?\",\n", + " termination_condition=MaxMessageTermination(max_messages=2),\n", ")\n", "print(\"\\n\", result)" ]