Skip to content

.NET: fix: coalesce AGUI completion text#6039

Open
he-yufeng wants to merge 1 commit into
microsoft:mainfrom
he-yufeng:fix/agui-coalesce-completion-text
Open

.NET: fix: coalesce AGUI completion text#6039
he-yufeng wants to merge 1 commit into
microsoft:mainfrom
he-yufeng:fix/agui-coalesce-completion-text

Conversation

@he-yufeng
Copy link
Copy Markdown
Contributor

Fixes #6010.

Summary

  • keep assistant text in one AG-UI text message even when provider completion chunks carry different MEAI message ids
  • still start a new AG-UI text message when the role changes
  • add a regression with a tool call between two assistant completion text chunks

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.ChatResponseUpdateAGUIExtensionsTests
  • 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-build -- --filter-class Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.UnitTests.AGUIEndpointRouteBuilderExtensionsTests
  • git diff --check

Copilot AI review requested due to automatic review settings May 22, 2026 15:48
@moonbox3 moonbox3 added the .NET label May 22, 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.

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 MessageId changes for TextContent.
  • 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(
};

@github-actions github-actions Bot changed the title fix: coalesce AGUI completion text .NET: fix: coalesce AGUI completion text May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: [Bug]: AG-UI host generates as many text messages as completions

3 participants