Skip to content

Comments

.NET: Create a sample to show bounded chat history with overflow into chat history memory#4136

Open
westey-m wants to merge 3 commits intomicrosoft:mainfrom
westey-m:bounded-chat-history-with-overflow-sample
Open

.NET: Create a sample to show bounded chat history with overflow into chat history memory#4136
westey-m wants to merge 3 commits intomicrosoft:mainfrom
westey-m:bounded-chat-history-with-overflow-sample

Conversation

@westey-m
Copy link
Contributor

Motivation and Context

#3955

Description

  • Create a sample that combines InMemoryChatHistoryStore with ChatHistoryMemoryProvider to keep a configurable number of messages in the session state, and offload any further messages into a vector store. On Run, the in-session messages will be augmented with a vector store search.

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.

Copilot AI review requested due to automatic review settings February 20, 2026 18:16
@markwallace-microsoft markwallace-microsoft added documentation Improvements or additions to documentation .NET labels Feb 20, 2026
@github-actions github-actions bot changed the title Create a sample to show bounded chat history with overflow into chat history memory .NET: Create a sample to show bounded chat history with overflow into chat history memory Feb 20, 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 introduces a new sample (AgentWithMemory_Step05_BoundedChatHistory) that demonstrates how to combine InMemoryChatHistoryProvider with ChatHistoryMemoryProvider to implement a bounded chat history with vector store overflow. The sample keeps a configurable number of recent messages in session state and automatically archives older messages to a vector store, where they can be recalled via semantic search.

Changes:

  • Adds a new sample showing bounded chat history with automatic overflow to vector store
  • Implements TruncatingChatReducer to truncate chat history and expose removed messages
  • Implements BoundedChatHistoryProvider to coordinate between in-memory and vector-based storage
  • Updates the AgentWithMemory README to include the new sample

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
dotnet/samples/GettingStarted/AgentWithMemory/README.md Adds entry for the new Step05 sample in the table of contents
dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step05_BoundedChatHistory/TruncatingChatReducer.cs Implements IChatReducer to keep N most recent messages and expose removed messages
dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step05_BoundedChatHistory/README.md Documents the sample's purpose, prerequisites, configuration, and how it works
dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step05_BoundedChatHistory/Program.cs Sample demonstrating bounded chat history with 4-message session window and vector overflow
dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step05_BoundedChatHistory/BoundedChatHistoryProvider.cs Custom ChatHistoryProvider coordinating InMemoryChatHistoryProvider and ChatHistoryMemoryProvider
dotnet/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step05_BoundedChatHistory/AgentWithMemory_Step05_BoundedChatHistory.csproj Project file with required package references (Azure.AI.OpenAI, Azure.Identity, SemanticKernel.Connectors.InMemory)
dotnet/agent-framework-dotnet.slnx Adds the new sample project to the solution

/// (via <see cref="ChatHistoryMemoryProvider"/>). When providing chat history, it searches the vector
/// store for relevant older messages and prepends them as a memory context message.
/// </summary>
internal sealed class BoundedChatHistoryProvider : ChatHistoryProvider, IDisposable
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

The BoundedChatHistoryProvider does not override the StateKey property. This means it will default to "BoundedChatHistoryProvider" according to the base class behavior. However, it internally uses InMemoryChatHistoryProvider which will use "InMemoryChatHistoryProvider" as its state key, and ChatHistoryMemoryProvider which uses "ChatHistoryMemoryProvider" by default. Since BoundedChatHistoryProvider doesn't store any state itself, this might not be an issue. However, consider whether overriding StateKey to return the InMemoryChatHistoryProvider's StateKey would be more appropriate, or documenting that this provider composes two others with their own state keys.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation .NET

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants