Skip to content

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

Merged
westey-m merged 8 commits into
microsoft:mainfrom
westey-m:bounded-chat-history-with-overflow-sample
Mar 6, 2026
Merged

.NET: Create a sample to show bounded chat history with overflow into chat history memory#4136
westey-m merged 8 commits into
microsoft:mainfrom
westey-m:bounded-chat-history-with-overflow-sample

Conversation

@westey-m

Copy link
Copy Markdown
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 Usage: [Issues, PRs], Target: documentation in the code base and learn docs .NET Usage: [Issues, PRs], Target: .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

Copilot AI 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 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs .NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants