.NET: fix Magentic participant message routing#6230
Open
he-yufeng wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
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
RecordingAgenttest 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; | ||
| } |
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.
Summary
Fixes #6223
To verify
dotnet restore dotnet\tests\Microsoft.Agents.AI.Workflows.UnitTests\Microsoft.Agents.AI.Workflows.UnitTests.csprojdotnet build dotnet\tests\Microsoft.Agents.AI.Workflows.UnitTests\Microsoft.Agents.AI.Workflows.UnitTests.csproj --no-restoredotnet 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-progressdotnet 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-progressdotnet 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-progressgit diff --check