[BREAKING] Python: Add factory pattern to GroupChat and Magentic (#3224)

* group chat

* magentic

* Fix tests

* AI comments

* Unifiy error message and add warning

* misc

* Add overload

* Collapse orchestrator params
This commit is contained in:
Tao Chen
2026-01-28 09:00:20 -08:00
committed by GitHub
Unverified
parent a7d924a7d2
commit 739edc7307
24 changed files with 1488 additions and 365 deletions
@@ -69,7 +69,7 @@ async def main() -> None:
# Build the group chat workflow
workflow = (
GroupChatBuilder()
.with_agent_orchestrator(orchestrator_agent)
.with_orchestrator(agent=orchestrator_agent)
.participants([researcher, writer])
# Set a hard termination condition: stop after 4 assistant messages
# The agent orchestrator will intelligently decide when to end before this limit but just in case
@@ -212,7 +212,7 @@ Share your perspective authentically. Feel free to:
workflow = (
GroupChatBuilder()
.with_agent_orchestrator(moderator)
.with_orchestrator(agent=moderator)
.participants([farmer, developer, teacher, activist, spiritual_leader, artist, immigrant, doctor])
.with_termination_condition(lambda messages: sum(1 for msg in messages if msg.role == Role.ASSISTANT) >= 10)
.build()
@@ -18,7 +18,7 @@ from azure.identity import AzureCliCredential
Sample: Group Chat with a round-robin speaker selector
What it does:
- Demonstrates the with_select_speaker_func() API for GroupChat orchestration
- Demonstrates the with_orchestrator() API for GroupChat orchestration
- Uses a pure Python function to control speaker selection based on conversation state
Prerequisites:
@@ -85,7 +85,7 @@ async def main() -> None:
workflow = (
GroupChatBuilder()
.participants([expert, verifier, clarifier, skeptic])
.with_select_speaker_func(round_robin_selector)
.with_orchestrator(selection_func=round_robin_selector)
# Set a hard termination condition: stop after 6 messages (user task + one full rounds + 1)
# One round is expert -> verifier -> clarifier -> skeptic, after which the expert gets to respond again.
# This will end the conversation after the expert has spoken 2 times (one iteration loop)
@@ -81,7 +81,7 @@ async def main() -> None:
workflow = (
MagenticBuilder()
.participants([researcher_agent, coder_agent])
.with_standard_manager(
.with_manager(
agent=manager_agent,
max_round_count=10,
max_stall_count=3,
@@ -84,7 +84,7 @@ def build_workflow(checkpoint_storage: FileCheckpointStorage):
MagenticBuilder()
.participants([researcher, writer])
.with_plan_review()
.with_standard_manager(
.with_manager(
agent=manager_agent,
max_round_count=10,
max_stall_count=3,
@@ -64,7 +64,7 @@ async def main() -> None:
workflow = (
MagenticBuilder()
.participants([researcher_agent, analyst_agent])
.with_standard_manager(
.with_manager(
agent=manager_agent,
max_round_count=10,
max_stall_count=1,