.NET: fix: skip local history after service conversation ids#6128
.NET: fix: skip local history after service conversation ids#6128he-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.
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. |
| 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) | ||
| { |
|
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. |
Summary
Fixes #6120
To verify