[BREAKING] Python: Refactor workflow events to unified discriminated union pattern #3690
[BREAKING] Python: Refactor workflow events to unified discriminated union pattern #3690moonbox3 merged 15 commits intomicrosoft:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors Python workflow events from individual event subclasses (like ExecutorCompletedEvent, WorkflowOutputEvent, RequestInfoEvent) to a unified discriminated union pattern using a single generic WorkflowEvent[DataT] class with a type literal discriminator. This aligns with PR #3649 and resolves issues #3528 and #3547.
Changes:
- Replaced event subclasses with
WorkflowEvent[DataT]generic type - Changed event type checking from
isinstance(event, WorkflowOutputEvent)toevent.type == "output" - Updated all samples, tests, and documentation to use the new pattern
- Removed exported event subclasses from public API
Reviewed changes
Copilot reviewed 117 out of 118 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
python/samples/**/*.py |
Updated 50+ sample files to use event.type == pattern instead of isinstance() |
python/packages/core/tests/**/*.py |
Updated 20+ test files with new event checking pattern |
python/packages/orchestrations/**/*.py |
Updated orchestration builders and tests |
python/packages/devui/**/*.py |
Updated DevUI mapper to use event.type discriminator |
python/packages/core/agent_framework/_workflows/*.py |
Core workflow implementation updates |
python/samples/getting_started/workflows/agents/azure_chat_agents_tool_calls_with_feedback.py
Show resolved
Hide resolved
python/samples/autogen-migration/orchestrations/01_round_robin_group_chat.py
Outdated
Show resolved
Hide resolved
python/samples/semantic-kernel-migration/orchestrations/concurrent_basic.py
Show resolved
Hide resolved
python/samples/getting_started/workflows/parallelism/fan_out_fan_in_edges.py
Show resolved
Hide resolved
python/samples/getting_started/workflows/declarative/marketing/main.py
Outdated
Show resolved
Hide resolved
python/samples/getting_started/workflows/declarative/deep_research/main.py
Outdated
Show resolved
Hide resolved
python/samples/getting_started/workflows/control-flow/sequential_streaming.py
Outdated
Show resolved
Hide resolved
python/samples/getting_started/workflows/agents/azure_chat_agents_tool_calls_with_feedback.py
Outdated
Show resolved
Hide resolved
python/samples/getting_started/orchestrations/group_chat_simple_selector.py
Outdated
Show resolved
Hide resolved
python/samples/getting_started/orchestrations/magentic_human_plan_review copy.py
Outdated
Show resolved
Hide resolved
|
@TaoChenOSU, I need these changes in for some other work I am doing - so I don't get stuck fixing conflicts for a day again. Please note anything and we can fast follow in another PR. Thanks. |
| "handoff_sent", # Handoff routing events (use .data as HandoffSentEvent) | ||
| "magentic_orchestrator", # Magentic orchestrator events (use .data as MagenticOrchestratorEvent) |
There was a problem hiding this comment.
These are orchestration related events. We should move them to the orchestration package in a follow up PR
Motivation and Context
ExecutorCompletedEvent,WorkflowOutputEvent,RequestInfoEvent, etc.) with a single genericWorkflowEvent[DataT]class using atypeliteral discriminatorevent.type == "output"pattern instead ofisinstance(event, WorkflowOutputEvent)checksAgentRunEvent/AgentRunUpdateEventExecutorCompletedEvent,ExecutorFailedEvent,ExecutorInvokedEvent,RequestInfoEvent,SuperStepCompletedEvent,SuperStepStartedEvent,WorkflowFailedEvent,WorkflowLifecycleEvent,WorkflowOutputEvent,WorkflowStartedEvent,WorkflowStatusEventevent.type == "..."instead ofisinstance()Migration
Description
Contribution Checklist