Skip to content

Commit

Permalink
Remove termination condition from team constructor (microsoft#4025)
Browse files Browse the repository at this point in the history
* Remove termination condition from team constructor

* fix usage
  • Loading branch information
ekzhu authored Nov 1, 2024
1 parent cff7d84 commit 369ffb5
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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(
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions python/packages/autogen-agentchat/tests/test_group_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
]
Expand Down

0 comments on commit 369ffb5

Please sign in to comment.