.NET: fix: coalesce AGUI completion text#6039
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.
Updates the AG-UI event stream conversion logic to coalesce assistant text into a single AG-UI text message even when intermediate ChatResponseUpdate.MessageId values change, and adjusts unit tests to validate the new behavior.
Changes:
- Change text message bracketing to start/end based on role transitions rather than
MessageIdchanges forTextContent. - Add/adjust unit test coverage to validate coalescing assistant text across multiple completion message IDs (including an intervening tool/function call).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI.AGUI/Shared/ChatResponseUpdateAGUIExtensions.cs | Alters message boundary detection to coalesce same-role text updates into a single text message session. |
| dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.UnitTests/ChatResponseUpdateAGUIExtensionsTests.cs | Updates test scenario/assertions to validate coalescing across multiple assistant MessageIds and a tool call. |
| // detect the transition. | ||
| if (currentReasoningMessageId is not null) | ||
| string chatResponseRole = chatResponse.Role!.Value.Value; | ||
| bool startTextMessage = currentMessageId is null || |
Comment on lines
+494
to
+512
| // End the previous message if there was one | ||
| if (currentMessageId is not null) | ||
| { | ||
| MessageId = currentReasoningId! | ||
| }; | ||
| currentReasoningBaseId = null; | ||
| currentReasoningId = null; | ||
| currentReasoningMessageId = null; | ||
| } | ||
| yield return new TextMessageEndEvent | ||
| { | ||
| MessageId = currentMessageId | ||
| }; | ||
| } | ||
|
|
||
| // End the previous message if there was one | ||
| if (currentMessageId is not null) | ||
| { | ||
| yield return new TextMessageEndEvent | ||
| // Start the new message | ||
| yield return new TextMessageStartEvent | ||
| { | ||
| MessageId = currentMessageId | ||
| MessageId = chatResponse.MessageId!, | ||
| Role = chatResponseRole | ||
| }; | ||
| } | ||
|
|
||
| // Start the new message | ||
| yield return new TextMessageStartEvent | ||
| { | ||
| MessageId = chatResponse.MessageId!, | ||
| Role = chatResponse.Role!.Value.Value | ||
| }; | ||
|
|
||
| currentMessageId = chatResponse.MessageId; | ||
| currentMessageId = chatResponse.MessageId; | ||
| currentMessageRole = chatResponseRole; | ||
| } |
| @@ -448,6 +448,7 @@ public static async IAsyncEnumerable<BaseEvent> AsAGUIEventStreamAsync( | |||
| }; | |||
|
|
|||
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 #6010.
Summary
To verify
dotnet run --project dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.UnitTests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.UnitTests.csproj --framework net10.0 -c Release --no-restore -- --filter-class Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.UnitTests.ChatResponseUpdateAGUIExtensionsTestsdotnet run --project dotnet/tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.UnitTests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.UnitTests.csproj --framework net10.0 -c Release --no-build -- --filter-class Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.UnitTests.AGUIEndpointRouteBuilderExtensionsTestsgit diff --check