Skip to content

.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
westey-m:message-access-and-chathistoryprovider-management
Feb 26, 2026
Merged

.NET: Add helpers to more easily access in-memory ChatHistory and make ChatHistoryProvider management more configurable.#4224
westey-m merged 5 commits intomicrosoft:mainfrom
westey-m:message-access-and-chathistoryprovider-management

Conversation

@westey-m
Copy link
Contributor

Motivation and Context

#4140

Description

  • Add helpers to more easily access in-memory ChatHistory.
  • Make ChatHistoryProvider management on ChatClientAgent more configurable.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

…HistoryProvider management more configurable.
Copilot AI review requested due to automatic review settings February 24, 2026 19:42
@github-actions github-actions bot changed the title Add helpers to more easily access in-memory ChatHistory and make ChatHistoryProvider management more configurable. .NET: Add helpers to more easily access in-memory ChatHistory and make ChatHistoryProvider management more configurable. Feb 24, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 TryGetInMemoryChatHistory and SetInMemoryChatHistory extension methods on AgentSession for easier access to in-memory chat history
  • Introduced three new configuration options on ChatClientAgentOptions to control behavior when ChatHistoryProvider conflicts with server-side chat history: ThrowOnChatHistoryProviderConflict, WarnOnChatHistoryProviderConflict, and ClearOnChatHistoryProviderConflict
  • Modified ChatClientAgent constructor to eagerly initialize ChatHistoryProvider with InMemoryChatHistoryProvider when 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

westey-m and others added 2 commits February 25, 2026 10:23
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@westey-m westey-m enabled auto-merge February 26, 2026 14:16
@westey-m westey-m added this pull request to the merge queue Feb 26, 2026
Merged via the queue into microsoft:main with commit 822a3eb Feb 26, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants