-
Notifications
You must be signed in to change notification settings - Fork 2k
.NET: [BREAKING] Refactor ChatMessageStore methods to be similar to AIContextProvider and add filtering support #2604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
westey-m
merged 19 commits into
microsoft:main
from
westey-m:chatmessagestore-method-refactor
Jan 5, 2026
Merged
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1f6fa9c
Refactor ChatMessageStore methods to be similar to AIContextProvider
westey-m 8bb114e
Merge from main
westey-m fdee491
Fix file encoding
westey-m 137a514
Ensure that AIContextProvider messages area also persisted.
westey-m ba63612
Update formatting and seal context classes
westey-m cf6956d
Improve formatting
westey-m e5669a4
Merge branch 'main' into chatmessagestore-method-refactor
westey-m 9e1e8e0
Merge branch 'main' into chatmessagestore-method-refactor
westey-m c894d61
Remove optional messages from constructor and add unit test
westey-m 3bd5fb9
Add ChatMessageStore filtering via a decorator
westey-m 446001b
Update sample and cosmos message store to store AIContextProvider mes…
westey-m 9f6d0f5
Update Workflowmessage store to use aicontext provider messages.
westey-m ca503e1
Merge branch 'main' into chatmessagestore-method-refactor
westey-m cc4f51c
Apply suggestions from code review
westey-m 5bf38b1
Apply suggestions from code review
westey-m 5862cfe
Improve xml docs messaging
westey-m 5709d7e
Merge branch 'main' into chatmessagestore-method-refactor
westey-m 32ac83c
Address code review comments.
westey-m ba985a0
Also notify message store on failure
westey-m File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
50 changes: 50 additions & 0 deletions
50
dotnet/src/Microsoft.Agents.AI.Abstractions/ChatMessageStoreExtensions.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using Microsoft.Extensions.AI; | ||
|
|
||
| namespace Microsoft.Agents.AI; | ||
|
|
||
| /// <summary> | ||
| /// Contains extension methods for the <see cref="ChatMessageStore"/> class. | ||
| /// </summary> | ||
| public static class ChatMessageStoreExtensions | ||
| { | ||
| /// <summary> | ||
| /// Adds message filtering to an existing store, so that messages passed to the store and messages produced by the store | ||
| /// can be filtered, updated or replaced. | ||
| /// </summary> | ||
| /// <param name="store">The store to add the message filter to.</param> | ||
| /// <param name="invokingMessagesFilter">An optional filter function to apply to messages before they are invoked. If null, no filter is applied at this | ||
| /// stage.</param> | ||
| /// <param name="invokedMessagesFilter">An optional filter function to apply to the invocation context after messages have been invoked. If null, no | ||
| /// filter is applied at this stage.</param> | ||
|
westey-m marked this conversation as resolved.
Outdated
|
||
| /// <returns>The <see cref="ChatMessageStore"/> with filtering applied.</returns> | ||
| public static ChatMessageStore WithMessageFilters( | ||
| this ChatMessageStore store, | ||
| Func<IEnumerable<ChatMessage>, IEnumerable<ChatMessage>>? invokingMessagesFilter = null, | ||
| Func<ChatMessageStore.InvokedContext, ChatMessageStore.InvokedContext>? invokedMessagesFilter = null) | ||
| { | ||
| return new ChatMessageStoreMessageFilter( | ||
| innerChatMessageStore: store, | ||
| invokingMessagesFilter: invokingMessagesFilter, | ||
| invokedMessagesFilter: invokedMessagesFilter); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Decorates the provided chat message store so that it does not store messages produced by any <see cref="AIContextProvider"/>. | ||
| /// </summary> | ||
| /// <param name="store">The store to add the message filter to.</param> | ||
| /// <returns>A new <see cref="ChatMessageStore"/> instance that filters out <see cref="AIContextProvider"/> messages so they do not get stored.</returns> | ||
| public static ChatMessageStore WithAIContextProviderMessageRemoval(this ChatMessageStore store) | ||
| { | ||
| return new ChatMessageStoreMessageFilter( | ||
| innerChatMessageStore: store, | ||
| invokedMessagesFilter: (ctx) => | ||
| { | ||
| ctx.AIContextProviderMessages = null; | ||
| return ctx; | ||
| }); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.