Skip to content

A programming framework for agentic AI

Remove termination condition from team constructor (#4025)

Eric Zhu369ffb511bb8
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 78ec5159e..e035a9874 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 @@ class BaseGroupChat(Team, ABC):
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 @@ class BaseGroupChat(Team, ABC):
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 @@ class BaseGroupChat(Team, ABC):
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 cec47f6e1..b2dcdb640 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 @@ class RoundRobinGroupChat(BaseGroupChat):
"""
- 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 ed7694d38..d91d89e26 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 @@ Read the above conversation. Then select the next role from {participants} to pl
""",
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 0f4ec0e63..0afc41afe 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 4e1485ce3..72fdc6bcd 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."
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 52f4b1baa..3c37aee20 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)"
]