.NET: fix: skip local history after service conversation ids#6128
Closed
he-yufeng wants to merge 1 commit into
Closed
.NET: fix: skip local history after service conversation ids#6128he-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.
Refactors ResolveChatHistoryProvider in ChatClientAgent to consider the session's ConversationId (in addition to ChatOptions.ConversationId) when deciding whether to use the local ChatHistoryProvider. A new helper IsServiceManagedConversationId centralizes detection of server-side conversations, treating the sentinel LocalHistoryConversationId as local.
Changes:
- Pass the
ChatClientAgentSessiontoResolveChatHistoryProviderfrom all three call sites (notify-new-messages, notify-failure, load-history). - Introduce
IsServiceManagedConversationIdto distinguish service-managed conversation ids from the local sentinel and use it for both provider resolution and the conflict-throw check. - Update unit test name and assertions to verify the default
InMemoryChatHistoryProvideris not populated when the service returns a conversation id.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs | Resolves history provider using session conversation id and the new service-managed id check. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_ChatHistoryManagementTests.cs | Renames test and asserts the default in-memory provider remains empty when a conversation id is returned. |
Comment on lines
+985
to
988
| if (this._agentOptions?.ThrowOnChatHistoryProviderConflict is true && IsServiceManagedConversationId(conversationId)) | ||
| { | ||
| throw new InvalidOperationException( | ||
| $"Only {nameof(ChatClientAgentSession.ConversationId)} or {nameof(this.ChatHistoryProvider)} may be used, but not both. The current {nameof(ChatClientAgentSession)} has a {nameof(ChatClientAgentSession.ConversationId)} indicating server-side chat history management, but an override {nameof(this.ChatHistoryProvider)} was provided via {nameof(AgentRunOptions.AdditionalProperties)}."); |
|
|
||
| private ChatHistoryProvider? ResolveChatHistoryProvider(ChatOptions? chatOptions) | ||
| private ChatHistoryProvider? ResolveChatHistoryProvider(ChatOptions? chatOptions, ChatClientAgentSession? session = null) | ||
| { |
Contributor
Author
|
Closing this in favor of #6141. The newer PR carries the current version of the same service-managed conversation id history handling fix, so keeping both open just splits review attention. |
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
Fixes #6120
To verify