-
Notifications
You must be signed in to change notification settings - Fork 873
.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
Open
westey-m
wants to merge
14
commits into
microsoft:main
Choose a base branch
from
westey-m:chatmessagestore-method-refactor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
14 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 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 filering 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> | ||||||||||
|
Comment on lines
+19
to
+20
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| /// <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> | ||||||||||
|
Comment on lines
+21
to
+22
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| /// <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.