Skip to content

.NET: fix Magentic participant message routing#6230

Open
he-yufeng wants to merge 1 commit into
microsoft:mainfrom
he-yufeng:fix/magentic-route-selected-speaker
Open

.NET: fix Magentic participant message routing#6230
he-yufeng wants to merge 1 commit into
microsoft:mainfrom
he-yufeng:fix/magentic-route-selected-speaker

Conversation

@he-yufeng
Copy link
Copy Markdown
Contributor

Summary

  • target Magentic progress-ledger instructions only to the selected next speaker
  • broadcast a participant's reply to the other participants before the next coordination round
  • add a regression test that verifies WorkerB receives WorkerA's reply but not WorkerA's private instruction

Fixes #6223

To verify

  • dotnet restore dotnet\tests\Microsoft.Agents.AI.Workflows.UnitTests\Microsoft.Agents.AI.Workflows.UnitTests.csproj
  • dotnet build dotnet\tests\Microsoft.Agents.AI.Workflows.UnitTests\Microsoft.Agents.AI.Workflows.UnitTests.csproj --no-restore
  • dotnet dotnet\tests\Microsoft.Agents.AI.Workflows.UnitTests\bin\Debug\net10.0\Microsoft.Agents.AI.Workflows.UnitTests.dll --filter-method Microsoft.Agents.AI.Workflows.UnitTests.MagenticOrchestrationTests.Participant_Response_Is_Shared_With_Next_SpeakerAsync --no-progress
  • dotnet dotnet\tests\Microsoft.Agents.AI.Workflows.UnitTests\bin\Debug\net10.0\Microsoft.Agents.AI.Workflows.UnitTests.dll --filter-method Microsoft.Agents.AI.Workflows.UnitTests.MagenticOrchestrationTests.Task_Delegates_To_Correct_AgentAsync --no-progress
  • dotnet dotnet\tests\Microsoft.Agents.AI.Workflows.UnitTests\bin\Debug\net10.0\Microsoft.Agents.AI.Workflows.UnitTests.dll --filter-class Microsoft.Agents.AI.Workflows.UnitTests.MagenticOrchestrationTests --no-progress
  • git diff --check

Copilot AI review requested due to automatic review settings June 1, 2026 07:05
@moonbox3 moonbox3 added .NET workflows Related to Workflows in agent-framework labels Jun 1, 2026
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.

Adds participant-to-participant message propagation in Magentic orchestration so that a participant’s response can be seen by subsequent participants, and updates tests to validate this routing behavior.

Changes:

  • Broadcast inbound turn messages to other participants during orchestration turns.
  • Send “private instruction” messages only to the selected next participant.
  • Add a new unit test plus a RecordingAgent test helper to capture participant inputs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/MagenticOrchestrationTests.cs Adds a regression test for cross-participant routing and a RecordingAgent to record received turns.
dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/Magentic/MagenticOrchestrator.cs Tracks current speaker executor id and broadcasts inbound messages to other participants; targets instructions to the next speaker.

Comment on lines 92 to +93
private PortBinding? _planReviewPort;
private string? _currentSpeakerExecutorId;
Comment on lines +306 to +321
private ValueTask BroadcastToOtherParticipantsAsync(List<ChatMessage> messages, IWorkflowContext context, CancellationToken cancellationToken)
{
List<Task>? sendTasks = null;
foreach (AIAgent participant in team)
{
string participantId = AIAgentHostExecutor.IdFor(participant);
if (string.Equals(participantId, this._currentSpeakerExecutorId, StringComparison.Ordinal))
{
continue;
}

(sendTasks ??= []).Add(context.SendMessageAsync(messages, participantId, cancellationToken).AsTask());
}

return sendTasks is null ? default : new ValueTask(Task.WhenAll(sendTasks));
}
Comment on lines +1393 to +1394
protected override ValueTask<JsonElement> SerializeSessionCoreAsync(AgentSession session, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) =>
default;
Comment on lines +1402 to +1414
protected override async IAsyncEnumerable<AgentResponseUpdate> RunCoreStreamingAsync(IEnumerable<ChatMessage> messages, AgentSession? session = null, AgentRunOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
ChatMessage response = this.RecordAndCreateResponse(messages);
yield return new AgentResponseUpdate(ChatRole.Assistant, response.Contents)
{
AuthorName = this.Name,
MessageId = response.MessageId,
ResponseId = Guid.NewGuid().ToString("N"),
CreatedAt = response.CreatedAt,
};

await Task.CompletedTask;
}
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]: Magentic participant message routing is the opposite of GroupChatHost and the Python reference

3 participants