diff --git a/dotnet/src/Microsoft.Agents.AI.GitHub.Copilot/GitHubCopilotAgent.cs b/dotnet/src/Microsoft.Agents.AI.GitHub.Copilot/GitHubCopilotAgent.cs index c966f591fc..bbebd7a312 100644 --- a/dotnet/src/Microsoft.Agents.AI.GitHub.Copilot/GitHubCopilotAgent.cs +++ b/dotnet/src/Microsoft.Agents.AI.GitHub.Copilot/GitHubCopilotAgent.cs @@ -346,14 +346,14 @@ private AgentResponseUpdate ConvertToAgentResponseUpdate(AssistantMessageDeltaEv }; } - private AgentResponseUpdate ConvertToAgentResponseUpdate(AssistantMessageEvent assistantMessage) + internal AgentResponseUpdate ConvertToAgentResponseUpdate(AssistantMessageEvent assistantMessage) { - TextContent textContent = new(assistantMessage.Data?.Content ?? string.Empty) + AIContent content = new() { RawRepresentation = assistantMessage }; - return new AgentResponseUpdate(ChatRole.Assistant, [textContent]) + return new AgentResponseUpdate(ChatRole.Assistant, [content]) { AgentId = this.Id, ResponseId = assistantMessage.Data?.MessageId, diff --git a/dotnet/tests/Microsoft.Agents.AI.GitHub.Copilot.UnitTests/GitHubCopilotAgentTests.cs b/dotnet/tests/Microsoft.Agents.AI.GitHub.Copilot.UnitTests/GitHubCopilotAgentTests.cs index 8a4d3c1068..896f6dd9fc 100644 --- a/dotnet/tests/Microsoft.Agents.AI.GitHub.Copilot.UnitTests/GitHubCopilotAgentTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.GitHub.Copilot.UnitTests/GitHubCopilotAgentTests.cs @@ -221,4 +221,26 @@ public void CopyResumeSessionConfig_WithNullSource_ReturnsDefaults() Assert.Null(result.ConfigDir); Assert.True(result.Streaming); } + + [Fact] + public void ConvertToAgentResponseUpdate_AssistantMessageEvent_DoesNotEmitTextContent() + { + var assistantMessage = new AssistantMessageEvent + { + Data = new AssistantMessageData + { + MessageId = "msg-456", + Content = "Some streamed content that was already delivered via delta events" + } + }; + CopilotClient copilotClient = new(new CopilotClientOptions { AutoStart = false }); + const string TestId = "agent-id"; + var agent = new GitHubCopilotAgent(copilotClient, ownsClient: false, id: TestId, tools: null); + AgentResponseUpdate result = agent.ConvertToAgentResponseUpdate(assistantMessage); + + // result.Text need to be empty because the content was already delivered via delta events, and we want to avoid emitting duplicate content in the response update. + // The content should be delivered through TextContent in the Contents collection instead. + Assert.Empty(result.Text); + Assert.DoesNotContain(result.Contents, c => c is TextContent); + } }