.NET: Create a sample to show bounded chat history with overflow into chat history memory#4136
Merged
westey-m merged 8 commits intomicrosoft:mainfrom Mar 6, 2026
Conversation
Contributor
There was a problem hiding this comment.
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
TruncatingChatReducerto truncate chat history and expose removed messages - Implements
BoundedChatHistoryProviderto 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 |
...02-agents/AgentWithMemory/AgentWithMemory_Step05_BoundedChatHistory/TruncatingChatReducer.cs
Show resolved
Hide resolved
...ents/AgentWithMemory/AgentWithMemory_Step05_BoundedChatHistory/BoundedChatHistoryProvider.cs
Show resolved
Hide resolved
...t/samples/GettingStarted/AgentWithMemory/AgentWithMemory_Step05_BoundedChatHistory/README.md
Outdated
Show resolved
Hide resolved
...02-agents/AgentWithMemory/AgentWithMemory_Step05_BoundedChatHistory/TruncatingChatReducer.cs
Show resolved
Hide resolved
...ents/AgentWithMemory/AgentWithMemory_Step05_BoundedChatHistory/BoundedChatHistoryProvider.cs
Show resolved
Hide resolved
...ents/AgentWithMemory/AgentWithMemory_Step05_BoundedChatHistory/BoundedChatHistoryProvider.cs
Show resolved
Hide resolved
...ents/AgentWithMemory/AgentWithMemory_Step05_BoundedChatHistory/BoundedChatHistoryProvider.cs
Show resolved
Hide resolved
...02-agents/AgentWithMemory/AgentWithMemory_Step05_BoundedChatHistory/TruncatingChatReducer.cs
Show resolved
Hide resolved
SergeyMenshykh
approved these changes
Feb 23, 2026
markwallace-microsoft
approved these changes
Mar 6, 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
#3955
Description
Contribution Checklist