.NET: Forward Magentic participant replies to manager#6156
Merged
lokitoth merged 3 commits intoMay 29, 2026
Conversation
MagenticOrchestrator.TakeTurnAsync dropped the `messages` parameter on subsequent turns, so participant replies never reached the manager's ChatHistory. The manager kept re-dispatching the same speaker every round until MaxRounds. Append the incoming messages to taskContext.ChatHistory before running the coordination round (matches Python's _handle_response). Adds RecordingReplayAgent + regression test that asserts the worker's reply reaches round-2's progress-ledger call.
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Fixes a bug in MagenticOrchestrator.TakeTurnAsync where participant replies on subsequent turns were dropped instead of being appended to the manager's chat history, causing the orchestrator to repeatedly dispatch the same speaker until MaxRounds.
Changes:
- Append incoming
messagesto_taskContext.ChatHistorybefore running coordination rounds on subsequent turns. - Add a
RecordingReplayAgenttest helper that captures input messages on each call. - Add a regression test verifying round-2 progress ledger sees the worker's reply.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/Magentic/MagenticOrchestrator.cs | Forwards participant reply messages into the manager's chat history on subsequent turns. |
| dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/RecordingReplayAgent.cs | New test agent that records inputs while replaying scripted responses. |
| dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/MagenticOrchestrationTests.cs | Adds regression test asserting participant replies reach the manager. |
Contributor
Author
|
@microsoft-github-policy-service agree |
3 tasks
lokitoth
approved these changes
May 29, 2026
peibekwe
approved these changes
May 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6172 , #6173
Motivation and Context
The .NET
MagenticOrchestratordoes not feed the participant agents'responses back into the manager's chat history. The manager builds its
progress-ledger prompt from
MagenticTaskContext.ChatHistory, so itnever sees any participant replies and keeps re-picking the same speaker
until
MaxRoundsterminates the run.The Python port handles this in
_MagenticOrchestratorExecutor._handle_response,which extends
magentic_context.chat_historywith the participant'smessages before re-entering the inner loop. This PR restores parity.
with a two-participant workflow where both participants reply with a short status token, the Python sample terminates in 3 rounds with the expected verdict, while .NET loops until MaxRounds without ever incorporating either reply.
Description
In
MagenticOrchestrator.TakeTurnAsync, themessagesparameter onsubsequent turns carries the participant agent's reply (forwarded by
AIAgentHostExecutorand accumulated byChatProtocolExecutor). Thefirst-turn branch consumes
messageswhen constructing the initialMagenticTaskContext, but the subsequent-turn branch ignored it and wentstraight to
RunCoordinationRoundAsync, so the reply was dropped.The fix appends the incoming
messagesto_taskContext.ChatHistorybefore invoking the coordination round, mirroring the Python orchestrator's
chat_history.extend(messages)step. No public API change, no behaviorchange on the first turn or on terminated contexts.
Tests
RunCoordinationRound_Forwards_Participant_Reply_To_ManagerAsyncinMagenticOrchestrationTests— runs a 2-round scenario and asserts theworker's reply appears in the manager's round-2 progress-ledger input.
Verified to fail without the fix.
RecordingReplayAgenttest helper (sibling ofTestReplayAgent)that captures input messages per call, for any future test that needs to
assert what the manager was actually handed.
MagenticOrchestrationTestspassContribution Checklist