Skip to content

.NET: Add helpers to more easily access in-memory ChatHistory and make ChatHistoryProvider management more configurable. - #4224

Merged
westey (westey-m) merged 5 commits into
microsoft: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 (westey-m) merged 5 commits into
microsoft:mainfrom
westey-m:message-access-and-chathistoryprovider-management

Conversation

@westey-m

Copy link
Copy Markdown
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.
CopilotAI review requested due to automatic review settings February 24, 2026 19:42
@markwallace-microsoftMark Wallace (markwallace-microsoft) added the .NET Usage: [Issues, PRs], Target: .Net label Feb 24, 2026
@github-actionsgithub-actionsBot 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

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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
FileDescription
dotnet/src/Microsoft.Agents.AI.Abstractions/AgentSessionExtensions.csNew extension methods providing convenient access to in-memory chat history state
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentOptions.csAdded three boolean properties to control ChatHistoryProvider conflict handling behavior with appropriate defaults
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.csChanged ChatHistoryProvider initialization from lazy to eager, updated conflict detection logic to check options instead of instance property
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentLogMessages.csAdded warning log message for ChatHistoryProvider conflicts
dotnet/samples/GettingStarted/Agents/Agent_Step16_ChatReduction/Program.csUpdated to use new TryGetInMemoryChatHistory extension method instead of accessing provider directly
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentSessionExtensionsTests.csComprehensive tests for new extension methods covering all scenarios
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_ChatHistoryManagementTests.csNew tests validating all conflict resolution behaviors
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentOptionsTests.csUpdated tests to verify new properties and their defaults

Comment threaddotnet/src/Microsoft.Agents.AI.Abstractions/AgentSessionExtensions.cs Outdated
westey (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 (westey-m) added this pull request to the merge queueFeb 26, 2026
Merged via the queue into microsoft:main with commit 822a3ebFeb 26, 2026
18 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NETUsage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@westey-m@rogerbarreto@SergeyMenshykh@markwallace-microsoft