-
Notifications
You must be signed in to change notification settings - Fork 642
Python: [BREAKING] Python: Intro group chat and refactor orchestrations. Fix as_agent(). Standardize orchestration start msg types. #1538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a reusable group chat orchestration framework and refactors Magentic One to build on these shared primitives. The changes eliminate Magentic's bespoke workflow wrapper while maintaining compatibility, consolidate event plumbing through the standard workflow event stream, and add support for as_agent() to accept full conversation payloads.
Key changes:
- Added GroupChat orchestration surface with protocols, builder, and executors for manager-directed multi-agent conversations
- Refactored Magentic to use shared group chat infrastructure while preserving Magentic-specific behavior
- Fixed as_agent() to properly handle conversation histories and improved type safety
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| python/packages/core/agent_framework/_workflows/_group_chat.py | New comprehensive group chat orchestration framework with protocols, executors, and builders |
| python/packages/core/agent_framework/_workflows/_magentic.py | Major refactor to build on group chat primitives while maintaining Magentic-specific functionality |
| python/packages/core/agent_framework/_workflows/_executor.py | Fixed handler decorator return type annotation |
| python/packages/core/agent_framework/_workflows/init.py | Added exports for new group chat components |
| python/packages/core/agent_framework/_workflows/init.pyi | Updated type definitions for new group chat exports |
| python/samples/getting_started/workflows/orchestration/group_chat.py | New sample demonstrating basic group chat usage |
| python/samples/getting_started/workflows/agents/*.py | New samples showing workflows wrapped as agents |
| python/samples/getting_started/workflows/orchestration/magentic*.py | Updated to use new event streaming approach |
| python/packages/core/tests/workflow/test_*.py | Updated tests to reflect new event handling and API changes |
| python/samples/getting_started/workflows/README.md | Added documentation for new samples |
python/samples/getting_started/workflows/orchestration/magentic_human_plan_update.py
Outdated
Show resolved
Hide resolved
|
Before we stabilize the API we should run different orchestration patterns against the GAIA benchmark in the lab package. |
|
We should do a pass to make sure the semantics of GroupChat in .NET are consistent with the Python ones. I am not sure we handle the tools messages the same way. |
python/packages/core/agent_framework/_workflows/_agent_executor.py
Outdated
Show resolved
Hide resolved
python/packages/core/agent_framework/_workflows/_agent_executor.py
Outdated
Show resolved
Hide resolved
python/packages/core/agent_framework/_workflows/_base_group_chat_orchestrator.py
Show resolved
Hide resolved
python/packages/core/agent_framework/_workflows/_base_orchestrator.py
Outdated
Show resolved
Hide resolved
python/packages/core/agent_framework/_workflows/_conversation_history.py
Outdated
Show resolved
Hide resolved
python/packages/core/agent_framework/_workflows/_orchestrator_helpers.py
Outdated
Show resolved
Hide resolved
…ns. Fix as_agent(). Standardize orchestration start msg types. (microsoft#1538) * Intro group chat and refactor magentic. Fix as_agent() * Cleanup and improvements * Add as_agent docstring clarification * Standardize orchestration messages to use agent-style inputs. * Simplify group chat constructs * Further cleanup * Add sk to af group chat migration sample. Update README. * Improvements and simplifications * consolidating shared orchestration logic * Further clean up * Add group chat sample * Improve typing * Fix test imports * Fix readme links * Cleanup per PR Feedback
Motivation and Context
This PR introduces a comprehensive refactoring of the orchestration patterns (GroupChat, Handoff, Magentic) to eliminate code duplication, strengthen architectural consistency, and provide cleaner public APIs.
Architectural Improvements
Unified Base Class: Created
BaseGroupChatOrchestratorwith shared state management (conversation history, termination conditions, round tracking) that all orchestration patterns inherit from, eliminating ~200 lines of duplicated state logic.Shared Utilities Module: Extracted common orchestration helpers into
_orchestrator_helpers.py:clean_conversation_for_handoff()- Removes tool-related content to prevent API errors during agent handoffscheck_round_limit()- Standardized round limit validationcreate_completion_message()- Consistent completion message generationprepare_participant_request()- Unified participant request constructionParticipantRegistry- Clean interface for tracking participant executor IDs and routing infoConsistent Participant Handling: All three orchestration patterns now use the same participant registration and routing patterns, reducing special-case logic.
API Surface Cleanup (Breaking Changes)
Internal Type Naming: Renamed 17 internal implementation types with
_prefix (e.g.,GroupChatRequestMessage→_GroupChatRequestMessage,MagenticProgressLedger→_MagenticProgressLedger) to clearly signal implementation details.Reduced Public Exports: Orchestration package now exports only 16 types (down from ~28), exposing only what users need:
GroupChatBuilder,HandoffBuilder,MagenticBuilderGroupChatStateSnapshot,MagenticPlanReviewRequest,MagenticPlanReviewReply, etc.MagenticOrchestratorMessageEvent,MagenticAgentDeltaEvent, etc.Enhanced GroupChat API: Added
select_speakers()as the primary API for function-based speaker selection, providing cleaner ergonomics than the previousset_speaker_selector()approach. The new method providesGroupChatStateSnapshotwith full context (history, round index, participant names) and enforces mutual exclusivity withset_prompt_based_manager()at build time.Type Safety and Consistency
Fixed Type Annotations:
termination_conditionfromAnytoCallable[[list[ChatMessage]], bool] | NoneinBaseGroupChatOrchestrator(allows for asynchronous use as well)type: ignorecommentsStub File Synchronization: Updated
__init__.pyito match cleaned__init__.pyexportsCode Quality Improvements
Eliminated Duplication: Removed redundant implementations of:
Improved Testability: Internal types remain accessible for testing via direct imports from implementation modules with appropriate
type: ignore[reportPrivateUsage]annotations.Documentation Enhancements:
GroupChatBuilderdocstring with dual pattern examples (function-based and LLM-based selection)select_speakers()APISamples and Documentation
New Samples:
group_chat_simple_selector.py- Demonstrates function-based speaker selection withselect_speakers()Updated README: Corrected orchestration sample links and descriptions (e.g., replaced non-existent
group_chat.pyreference with actual filesgroup_chat_prompt_based_manager.pyandgroup_chat_simple_selector.py)The cleaner API surface and reduced code duplication provide a stronger foundation for future orchestration pattern development.
Description
GroupChatBuilderin workflow API #800Contribution Checklist