.NET: fix: avoid local history when service returns conversation id#6141
.NET: fix: avoid local history when service returns conversation id#6141he-yufeng wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates ChatClientAgent to propagate the service-returned conversation id into ChatOptions during a run, and strengthens a unit test to ensure local history is not persisted when no provider is configured in options.
Changes:
- Set
ChatOptions.ConversationIdfrom the chat response conversation id in both non-streaming and streaming paths. - Add an assertion in unit tests that local in-memory history remains empty when no provider is configured via options.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_ChatHistoryManagementTests.cs | Extends a test to verify no local history persistence occurs in the “no provider in options” scenario. |
| dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs | Introduces SetResponseConversationId and applies it so the response conversation id is reflected in ChatOptions. |
| private static ChatOptions? SetResponseConversationId(ChatOptions? chatOptions, string? responseConversationId) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(responseConversationId)) | ||
| { | ||
| return chatOptions; | ||
| } | ||
|
|
||
| chatOptions ??= new(); | ||
| chatOptions.ConversationId ??= responseConversationId; | ||
| return chatOptions; | ||
| } |
| var inMemoryProvider = agent.ChatHistoryProvider as InMemoryChatHistoryProvider; | ||
| Assert.NotNull(inMemoryProvider); | ||
| Assert.Empty(inMemoryProvider.GetMessages(session)); |
| private static ChatOptions? SetResponseConversationId(ChatOptions? chatOptions, string? responseConversationId) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(responseConversationId)) | ||
| { | ||
| return chatOptions; | ||
| } | ||
|
|
||
| chatOptions ??= new(); | ||
| chatOptions.ConversationId ??= responseConversationId; | ||
| return chatOptions; | ||
| } |
33e194b to
3a27cac
Compare
3a27cac to
b11fa10
Compare
|
Rebased this branch onto current I also fixed a rebase fallout in the new Validation run locally from
I used |
|
Rebased this branch onto current main and pushed the updated head $head. I also addressed the open Copilot review threads:
Validation run locally from dotnet/:
|
fdcc011 to
f4db562
Compare
f4db562 to
2bd57bd
Compare
Summary
To verify
Notes: full solution
dotnet build dotnet/agent-framework-dotnet.slnx --no-restorestill fails locally on unrelated projects that have no restored assets and an existing MCP unit-test reference error.