Skip to content

Commit 23644ac

Browse files
normalianmarkwallace-microsoftdmytrostruk
authored
.NET: bug fix for duplicate output on GitHubCopilotAgent (#3981)
* bug fix for duplicate output on GitHubCopilotAgent * Add Test code for bug fix of duplicate output on GitHubCopilotAgenttT * update Test code for bug fix of duplicate output on GitHubCopilotAgenttT * update Test for duplicate output of GitHubCopilotAgent --------- Co-authored-by: Mark Wallace <127216156+markwallace-microsoft@users.noreply.github.com> Co-authored-by: Dmytro Struk <13853051+dmytrostruk@users.noreply.github.com>
1 parent fd981da commit 23644ac

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

dotnet/src/Microsoft.Agents.AI.GitHub.Copilot/GitHubCopilotAgent.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,14 +346,14 @@ private AgentResponseUpdate ConvertToAgentResponseUpdate(AssistantMessageDeltaEv
346346
};
347347
}
348348

349-
private AgentResponseUpdate ConvertToAgentResponseUpdate(AssistantMessageEvent assistantMessage)
349+
internal AgentResponseUpdate ConvertToAgentResponseUpdate(AssistantMessageEvent assistantMessage)
350350
{
351-
TextContent textContent = new(assistantMessage.Data?.Content ?? string.Empty)
351+
AIContent content = new()
352352
{
353353
RawRepresentation = assistantMessage
354354
};
355355

356-
return new AgentResponseUpdate(ChatRole.Assistant, [textContent])
356+
return new AgentResponseUpdate(ChatRole.Assistant, [content])
357357
{
358358
AgentId = this.Id,
359359
ResponseId = assistantMessage.Data?.MessageId,

dotnet/tests/Microsoft.Agents.AI.GitHub.Copilot.UnitTests/GitHubCopilotAgentTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,26 @@ public void CopyResumeSessionConfig_WithNullSource_ReturnsDefaults()
221221
Assert.Null(result.ConfigDir);
222222
Assert.True(result.Streaming);
223223
}
224+
225+
[Fact]
226+
public void ConvertToAgentResponseUpdate_AssistantMessageEvent_DoesNotEmitTextContent()
227+
{
228+
var assistantMessage = new AssistantMessageEvent
229+
{
230+
Data = new AssistantMessageData
231+
{
232+
MessageId = "msg-456",
233+
Content = "Some streamed content that was already delivered via delta events"
234+
}
235+
};
236+
CopilotClient copilotClient = new(new CopilotClientOptions { AutoStart = false });
237+
const string TestId = "agent-id";
238+
var agent = new GitHubCopilotAgent(copilotClient, ownsClient: false, id: TestId, tools: null);
239+
AgentResponseUpdate result = agent.ConvertToAgentResponseUpdate(assistantMessage);
240+
241+
// 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.
242+
// The content should be delivered through TextContent in the Contents collection instead.
243+
Assert.Empty(result.Text);
244+
Assert.DoesNotContain(result.Contents, c => c is TextContent);
245+
}
224246
}

0 commit comments

Comments
 (0)