Skip to content

.NET: Forward Magentic participant replies to manager#6156

Merged
lokitoth merged 3 commits into
microsoft:mainfrom
ghominejad:fix/magentic-forward-replies
May 29, 2026
Merged

.NET: Forward Magentic participant replies to manager#6156
lokitoth merged 3 commits into
microsoft:mainfrom
ghominejad:fix/magentic-forward-replies

Conversation

@ghominejad
Copy link
Copy Markdown
Contributor

@ghominejad ghominejad commented May 28, 2026

Fixes #6172 , #6173

Motivation and Context

The .NET MagenticOrchestrator does not feed the participant agents'
responses back into the manager's chat history. The manager builds its
progress-ledger prompt from MagenticTaskContext.ChatHistory, so it
never sees any participant replies and keeps re-picking the same speaker
until MaxRounds terminates the run.

The Python port handles this in _MagenticOrchestratorExecutor._handle_response,
which extends magentic_context.chat_history with the participant's
messages 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, the messages parameter on
subsequent turns carries the participant agent's reply (forwarded by
AIAgentHostExecutor and accumulated by ChatProtocolExecutor). The
first-turn branch consumes messages when constructing the initial
MagenticTaskContext, but the subsequent-turn branch ignored it and went
straight to RunCoordinationRoundAsync, so the reply was dropped.

The fix appends the incoming messages to _taskContext.ChatHistory
before invoking the coordination round, mirroring the Python orchestrator's
chat_history.extend(messages) step. No public API change, no behavior
change on the first turn or on terminated contexts.

Tests

  • Added RunCoordinationRound_Forwards_Participant_Reply_To_ManagerAsync in
    MagenticOrchestrationTests — runs a 2-round scenario and asserts the
    worker's reply appears in the manager's round-2 progress-ledger input.
    Verified to fail without the fix.
  • Added RecordingReplayAgent test helper (sibling of TestReplayAgent)
    that captures input messages per call, for any future test that needs to
    assert what the manager was actually handed.
  • All MagenticOrchestrationTests pass

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.

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.
Copilot AI review requested due to automatic review settings May 28, 2026 15:53
Copy link
Copy Markdown
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

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 messages to _taskContext.ChatHistory before running coordination rounds on subsequent turns.
  • Add a RecordingReplayAgent test 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.

@moonbox3 moonbox3 added .NET workflows Related to Workflows in agent-framework labels May 28, 2026
@ghominejad
Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@lokitoth lokitoth enabled auto-merge May 29, 2026 18:18
@lokitoth lokitoth added this pull request to the merge queue May 29, 2026
@lokitoth lokitoth self-assigned this May 29, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 29, 2026
@lokitoth lokitoth added this pull request to the merge queue May 29, 2026
Merged via the queue into microsoft:main with commit 07a1e83 May 29, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET workflows Related to Workflows in agent-framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: [Bug]: MagenticOrchestrator loses participant replies between rounds — manager loops to MaxRounds

5 participants