You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
.NET: [BREAKING] Refactor ChatMessageStore methods to be similar to AIContextProvider and add filtering support (#2604)
* Refactor ChatMessageStore methods to be similar to AIContextProvider
* Fix file encoding
* Ensure that AIContextProvider messages area also persisted.
* Update formatting and seal context classes
* Improve formatting
* Remove optional messages from constructor and add unit test
* Add ChatMessageStore filtering via a decorator
* Update sample and cosmos message store to store AIContextProvider messages in right order. Fix unit tests.
* Update Workflowmessage store to use aicontext provider messages.
* Apply suggestions from code review
Co-authored-by: Copilot <[email protected]>
* Apply suggestions from code review
Co-authored-by: SergeyMenshykh <[email protected]>
* Improve xml docs messaging
* Address code review comments.
* Also notify message store on failure
---------
Co-authored-by: Copilot <[email protected]>
Co-authored-by: SergeyMenshykh <[email protected]>
Copy file name to clipboardExpand all lines: dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step01_BasicTextRAG/Program.cs
+6-1Lines changed: 6 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -62,7 +62,12 @@
62
62
.CreateAIAgent(newChatClientAgentOptions
63
63
{
64
64
ChatOptions=new(){Instructions="You are a helpful support specialist for Contoso Outdoors. Answer questions using the provided context and cite the source document when available."},
Copy file name to clipboardExpand all lines: dotnet/src/Microsoft.Agents.AI.Abstractions/ChatMessageStore.cs
+107-7Lines changed: 107 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -32,8 +32,9 @@ namespace Microsoft.Agents.AI;
32
32
publicabstractclassChatMessageStore
33
33
{
34
34
/// <summary>
35
-
/// Asynchronously retrieves all messages from the store that should be provided as context for the next agent invocation.
35
+
/// Called at the start of agent invocation to retrieve all messages from the store that should be provided as context for the next agent invocation.
36
36
/// </summary>
37
+
/// <param name="context">Contains the request context including the caller provided messages that will be used by the agent for this invocation.</param>
37
38
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
38
39
/// <returns>
39
40
/// A task that represents the asynchronous operation. The task result contains a collection of <see cref="ChatMessage"/>
@@ -59,20 +60,19 @@ public abstract class ChatMessageStore
/// Asynchronously adds new messages to the store.
66
+
/// Called at the end of the agent invocation to add new messages to the store.
66
67
/// </summary>
67
-
/// <param name="messages">The collection of chat messages to add to the store.</param>
68
+
/// <param name="context">Contains the invocation context including request messages, response messages, and any exception that occurred.</param>
68
69
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
69
70
/// <returns>A task that represents the asynchronous add operation.</returns>
70
-
/// <exception cref="ArgumentNullException"><paramref name="messages"/> is <see langword="null"/>.</exception>
71
71
/// <remarks>
72
72
/// <para>
73
73
/// Messages should be added in the order they were generated to maintain proper chronological sequence.
74
74
/// The store is responsible for preserving message ordering and ensuring that subsequent calls to
75
-
/// <see cref="GetMessagesAsync"/> return messages in the correct chronological order.
75
+
/// <see cref="InvokingAsync"/> return messages in the correct chronological order.
76
76
/// </para>
77
77
/// <para>
78
78
/// Implementations may perform additional processing during message addition, such as:
@@ -83,8 +83,12 @@ public abstract class ChatMessageStore
83
83
/// <item><description>Updating indices or search capabilities</description></item>
84
84
/// </list>
85
85
/// </para>
86
+
/// <para>
87
+
/// This method is called regardless of whether the invocation succeeded or failed.
88
+
/// To check if the invocation was successful, inspect the <see cref="InvokedContext.InvokeException"/> property.
/// Contains extension methods for the <see cref="ChatMessageStore"/> class.
11
+
/// </summary>
12
+
publicstaticclassChatMessageStoreExtensions
13
+
{
14
+
/// <summary>
15
+
/// Adds message filtering to an existing store, so that messages passed to the store and messages produced by the store
16
+
/// can be filtered, updated or replaced.
17
+
/// </summary>
18
+
/// <param name="store">The store to add the message filter to.</param>
19
+
/// <param name="invokingMessagesFilter">An optional filter function to apply to messages produced by the store. If null, no filter is applied at this
20
+
/// stage.</param>
21
+
/// <param name="invokedMessagesFilter">An optional filter function to apply to the invoked context messages before they are passed to the store. If null, no
22
+
/// filter is applied at this stage.</param>
23
+
/// <returns>The <see cref="ChatMessageStore"/> with filtering applied.</returns>
/// Decorates the provided chat message store so that it does not store messages produced by any <see cref="AIContextProvider"/>.
37
+
/// </summary>
38
+
/// <param name="store">The store to add the message filter to.</param>
39
+
/// <returns>A new <see cref="ChatMessageStore"/> instance that filters out <see cref="AIContextProvider"/> messages so they do not get stored.</returns>
0 commit comments