Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,12 @@ private AgentResponseUpdate ConvertToAgentResponseUpdate(AssistantMessageDeltaEv

private 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using GitHub.Copilot.SDK;
using Microsoft.Extensions.AI;
Expand Down Expand Up @@ -221,4 +222,33 @@ 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);
MethodInfo method = typeof(GitHubCopilotAgent).GetMethod(
"ConvertToAgentResponseUpdate",
BindingFlags.NonPublic | BindingFlags.Instance,
binder: null,
types: [typeof(AssistantMessageEvent)],
modifiers: null)!;

var result = (AgentResponseUpdate)method.Invoke(agent, [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);
}
}
Loading