.NET: bug fix for duplicate output on GitHubCopilotAgent#3981
.NET: bug fix for duplicate output on GitHubCopilotAgent#3981alliscode merged 6 commits intomicrosoft:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in GitHubCopilotAgent where the final assistant message output was duplicated during streaming. The issue occurred because both AssistantMessageDeltaEvent (streaming incremental text) and AssistantMessageEvent (completion signal) were emitting text content, causing downstream consumers to render the same text twice.
Changes:
- Modified
ConvertToAgentResponseUpdate(AssistantMessageEvent)to emitAIContentinstead ofTextContent, preserving metadata without duplicating text output.
|
Copilot is handing this issue microsoft/semantic-kernel#13570 to fix the PR build |
|
@normalian Thanks for your contribution, wondering if you would be able to add some tests to verify this behavior? Please let me know, thanks! |
|
HI @dmytrostruk, thanks for your reply. I just created the test code and push here. Please review it. |
dotnet/tests/Microsoft.Agents.AI.GitHub.Copilot.UnitTests/GitHubCopilotAgentTests.cs
Outdated
Show resolved
Hide resolved
|
Thanks for your review, @dmytrostruk. I just update the source code files by following your suggestion. Please check again. |
Motivation and Context
When using GitHubCopilotAgent, the final assistant message output was duplicated. The AssistantMessageDeltaEvent handlers already stream text content incrementally via TextContent, but the AssistantMessageEvent handler was also emitting a TextContent with the full message. This caused downstream consumers to render the same text twice.
Description
Changed the ConvertToAgentResponseUpdate(AssistantMessageEvent) method in GitHubCopilotAgent.cs to emit a plain AIContent instead of a TextContent. The AssistantMessageEvent is a completion signal that carries metadata (message ID, timestamp, raw representation) — it should not re-emit the text content that was already streamed through AssistantMessageDeltaEvent. By using AIContent instead of TextContent, the event still preserves its RawRepresentation for inspection without producing duplicate text output.
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