.NET: Add helpers to more easily access in-memory ChatHistory and make ChatHistoryProvider management more configurable.#4224
Merged
westey-m merged 5 commits intomicrosoft:mainfrom Feb 26, 2026
Conversation
…HistoryProvider management more configurable.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds helper methods to access in-memory chat history from agent sessions and introduces configurable ChatHistoryProvider management options for ChatClientAgent, addressing issue #4140 where users could no longer easily access session messages in RC1.
Changes:
- Added
TryGetInMemoryChatHistoryandSetInMemoryChatHistoryextension methods onAgentSessionfor easier access to in-memory chat history - Introduced three new configuration options on
ChatClientAgentOptionsto control behavior when ChatHistoryProvider conflicts with server-side chat history:ThrowOnChatHistoryProviderConflict,WarnOnChatHistoryProviderConflict, andClearOnChatHistoryProviderConflict - Modified
ChatClientAgentconstructor to eagerly initializeChatHistoryProviderwithInMemoryChatHistoryProviderwhen none is provided, and updated conflict detection to distinguish between user-provided and default providers
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI.Abstractions/AgentSessionExtensions.cs | New extension methods providing convenient access to in-memory chat history state |
| dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentOptions.cs | Added three boolean properties to control ChatHistoryProvider conflict handling behavior with appropriate defaults |
| dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs | Changed ChatHistoryProvider initialization from lazy to eager, updated conflict detection logic to check options instead of instance property |
| dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentLogMessages.cs | Added warning log message for ChatHistoryProvider conflicts |
| dotnet/samples/GettingStarted/Agents/Agent_Step16_ChatReduction/Program.cs | Updated to use new TryGetInMemoryChatHistory extension method instead of accessing provider directly |
| dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentSessionExtensionsTests.cs | Comprehensive tests for new extension methods covering all scenarios |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_ChatHistoryManagementTests.cs | New tests validating all conflict resolution behaviors |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentOptionsTests.cs | Updated tests to verify new properties and their defaults |
dotnet/src/Microsoft.Agents.AI.Abstractions/AgentSessionExtensions.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
rogerbarreto
approved these changes
Feb 26, 2026
SergeyMenshykh
approved these changes
Feb 26, 2026
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.
Motivation and Context
#4140
Description
Contribution Checklist