.NET: fix: avoid local history when service returns conversation id#6141
Open
he-yufeng wants to merge 1 commit into
Open
.NET: fix: avoid local history when service returns conversation id#6141he-yufeng wants to merge 1 commit into
he-yufeng wants to merge 1 commit into
Conversation
Contributor
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. |
Comment on lines
+1011
to
+1021
| private static ChatOptions? SetResponseConversationId(ChatOptions? chatOptions, string? responseConversationId) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(responseConversationId)) | ||
| { | ||
| return chatOptions; | ||
| } | ||
|
|
||
| chatOptions ??= new(); | ||
| chatOptions.ConversationId ??= responseConversationId; | ||
| return chatOptions; | ||
| } |
Comment on lines
+412
to
+414
| var inMemoryProvider = agent.ChatHistoryProvider as InMemoryChatHistoryProvider; | ||
| Assert.NotNull(inMemoryProvider); | ||
| Assert.Empty(inMemoryProvider.GetMessages(session)); |
Comment on lines
+1011
to
+1021
| 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.