Skip to content

[BREAKING] Python: Adjust magentic event types raised. No need for custom events.#2215

Merged
moonbox3 merged 6 commits intomicrosoft:mainfrom
moonbox3:fix-2213
Nov 25, 2025
Merged

[BREAKING] Python: Adjust magentic event types raised. No need for custom events.#2215
moonbox3 merged 6 commits intomicrosoft:mainfrom
moonbox3:fix-2213

Conversation

@moonbox3
Copy link
Contributor

@moonbox3 moonbox3 commented Nov 14, 2025

Motivation and Context

Right now there are custom even types raised from the magentic orchestration pattern. These aren't needed, and aren't actually picked up/raised to the caller while running the workflow as an agent. Since the orchestration pattern uses agents, we should simply yield the underlying agent types to the caller. To help distinguish what is going on in the magentic flow, metadata around the event type is added to the AgentRunResponseUpdate.

Caution

No rush in merging this - fine to do after Ignite because it's breaking.

Important

Once this is in, I will update the learn site docs.

Description

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings November 14, 2025 06:18
@moonbox3 moonbox3 added squad: workflows Agent Framework Workflows Squad agent orchestration Issues related to agent orchestration workflows Related to Workflows in agent-framework breaking change Introduces changes that are not backward compatible and may require updates to dependent code. labels Nov 14, 2025
@github-actions github-actions bot changed the title [BREAKING] Python: Adjust magentic event types raised. No need for custom events. Python: [BREAKING] Python: Adjust magentic event types raised. No need for custom events. Nov 14, 2025
@moonbox3 moonbox3 changed the title Python: [BREAKING] Python: Adjust magentic event types raised. No need for custom events. [BREAKING] Python: Adjust magentic event types raised. No need for custom events. Nov 14, 2025
Copy link
Contributor

Copilot AI left a 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 refactors the Magentic orchestration pattern to eliminate custom event types (MagenticOrchestratorMessageEvent, MagenticAgentDeltaEvent, MagenticAgentMessageEvent, MagenticFinalResultEvent) and instead emit standard AgentRunUpdateEvent objects with metadata to distinguish event types. This allows workflows to work seamlessly as agents and unifies the event handling pattern across the framework.

Key changes:

  • Replaced custom Magentic event types with AgentRunUpdateEvent containing metadata fields (magentic_event_type, orchestrator_message_kind, agent_id)
  • Exported new constants (MAGENTIC_EVENT_TYPE_AGENT_DELTA, MAGENTIC_EVENT_TYPE_ORCHESTRATOR, ORCH_MSG_KIND_*) for event type identification
  • Updated sample code to use metadata-based event handling instead of type checking custom events

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
python/packages/core/agent_framework/_workflows/_magentic.py Core implementation: removes custom event classes and emits AgentRunUpdateEvent with metadata; updates documentation
python/packages/core/agent_framework/_workflows/init.py Exports new event type constants and removes custom event types from public API
python/packages/core/agent_framework/_workflows/init.pyi Updates type stubs to reflect new constants and removed event types
python/packages/core/agent_framework/_workflows/_agent.py Updates documentation to clarify that workflow-internal events are ignored
python/packages/core/tests/workflow/test_magentic.py Updates test to handle AgentRunUpdateEvent instead of MagenticAgentMessageEvent; re-enables previously skipped tests
python/samples/getting_started/workflows/orchestration/magentic_human_plan_update.py Updates sample to use AgentRunUpdateEvent with metadata checks instead of custom event types
python/samples/getting_started/workflows/agents/magentic_workflow_as_agent.py Simplifies sample to demonstrate workflow-as-agent pattern using metadata-based event handling

@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Nov 14, 2025

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@moonbox3 moonbox3 enabled auto-merge November 25, 2025 08:23
@moonbox3 moonbox3 added this pull request to the merge queue Nov 25, 2025
Merged via the queue into microsoft:main with commit 27b3a51 Nov 25, 2025
23 checks passed
arisng pushed a commit to arisng/agent-framework that referenced this pull request Feb 2, 2026
…stom events. (microsoft#2215)

* Adjust magentic event types raised. No need for custom events.

* Cleanup

* Fix test

* Update python/packages/core/agent_framework/_workflows/_magentic.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent orchestration Issues related to agent orchestration breaking change Introduces changes that are not backward compatible and may require updates to dependent code. python squad: workflows Agent Framework Workflows Squad workflows Related to Workflows in agent-framework

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Python: running Magentic orchestration as_agent() doesn't raise custom events

5 participants