diff --git a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_CustomImplementation/Program.cs b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_CustomImplementation/Program.cs index 16fca255e2..940b0981e8 100644 --- a/dotnet/samples/GettingStarted/AgentProviders/Agent_With_CustomImplementation/Program.cs +++ b/dotnet/samples/GettingStarted/AgentProviders/Agent_With_CustomImplementation/Program.cs @@ -65,10 +65,7 @@ protected override async Task RunCoreAsync(IEnumerable responseMessages = CloneAndToUpperCase(messages, this.Name).ToList(); // Notify the session of the input and output messages. - var invokedContext = new ChatHistoryProvider.InvokedContext(this, session, messages) - { - ResponseMessages = responseMessages - }; + var invokedContext = new ChatHistoryProvider.InvokedContext(this, session, messages, responseMessages); await this.ChatHistoryProvider.InvokedAsync(invokedContext, cancellationToken); return new AgentResponse @@ -97,10 +94,7 @@ protected override async IAsyncEnumerable RunCoreStreamingA List responseMessages = CloneAndToUpperCase(messages, this.Name).ToList(); // Notify the session of the input and output messages. - var invokedContext = new ChatHistoryProvider.InvokedContext(this, session, messages) - { - ResponseMessages = responseMessages - }; + var invokedContext = new ChatHistoryProvider.InvokedContext(this, session, messages, responseMessages); await this.ChatHistoryProvider.InvokedAsync(invokedContext, cancellationToken); foreach (var message in responseMessages) diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/AIContextProvider.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/AIContextProvider.cs index c7c17c4122..5e1af20ad0 100644 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/AIContextProvider.cs +++ b/dotnet/src/Microsoft.Agents.AI.Abstractions/AIContextProvider.cs @@ -230,20 +230,43 @@ public InvokingContext( public sealed class InvokedContext { /// - /// Initializes a new instance of the class with the specified request messages. + /// Initializes a new instance of the class for a successful invocation. /// - /// The agent being invoked. + /// The agent that was invoked. + /// The session associated with the agent invocation. + /// The messages that were used by the agent for this invocation. + /// The response messages generated during this invocation. + /// , , or is . + public InvokedContext( + AIAgent agent, + AgentSession? session, + IEnumerable requestMessages, + IEnumerable responseMessages) + { + this.Agent = Throw.IfNull(agent); + this.Session = session; + this.RequestMessages = Throw.IfNull(requestMessages); + this.ResponseMessages = Throw.IfNull(responseMessages); + } + + /// + /// Initializes a new instance of the class for a failed invocation. + /// + /// The agent that was invoked. /// The session associated with the agent invocation. /// The messages that were used by the agent for this invocation. - /// is . + /// The exception that caused the invocation to fail. + /// , , or is . public InvokedContext( AIAgent agent, AgentSession? session, - IEnumerable requestMessages) + IEnumerable requestMessages, + Exception invokeException) { this.Agent = Throw.IfNull(agent); this.Session = session; this.RequestMessages = Throw.IfNull(requestMessages); + this.InvokeException = Throw.IfNull(invokeException); } /// @@ -262,16 +285,16 @@ public InvokedContext( /// /// A collection of instances representing all messages that were used by the agent for this invocation. /// - public IEnumerable RequestMessages { get; set { field = Throw.IfNull(value); } } + public IEnumerable RequestMessages { get; } /// /// Gets the collection of response messages generated during this invocation if the invocation succeeded. /// /// /// A collection of instances representing the response, - /// or if the invocation failed or did not produce response messages. + /// or if the invocation failed. /// - public IEnumerable? ResponseMessages { get; set; } + public IEnumerable? ResponseMessages { get; } /// /// Gets the that was thrown during the invocation, if the invocation failed. @@ -279,6 +302,6 @@ public InvokedContext( /// /// The exception that caused the invocation to fail, or if the invocation succeeded. /// - public Exception? InvokeException { get; set; } + public Exception? InvokeException { get; } } } diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/ChatHistoryProvider.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/ChatHistoryProvider.cs index 408732162a..8f66278eca 100644 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/ChatHistoryProvider.cs +++ b/dotnet/src/Microsoft.Agents.AI.Abstractions/ChatHistoryProvider.cs @@ -260,20 +260,43 @@ public InvokingContext( public sealed class InvokedContext { /// - /// Initializes a new instance of the class with the specified request messages. + /// Initializes a new instance of the class for a successful invocation. /// - /// The agent being invoked. + /// The agent that was invoked. /// The session associated with the agent invocation. /// The caller provided messages that were used by the agent for this invocation. - /// is . + /// The response messages generated during this invocation. + /// , , or is . public InvokedContext( AIAgent agent, AgentSession? session, - IEnumerable requestMessages) + IEnumerable requestMessages, + IEnumerable responseMessages) { this.Agent = Throw.IfNull(agent); this.Session = session; this.RequestMessages = Throw.IfNull(requestMessages); + this.ResponseMessages = Throw.IfNull(responseMessages); + } + + /// + /// Initializes a new instance of the class for a failed invocation. + /// + /// The agent that was invoked. + /// The session associated with the agent invocation. + /// The caller provided messages that were used by the agent for this invocation. + /// The exception that caused the invocation to fail. + /// , , or is . + public InvokedContext( + AIAgent agent, + AgentSession? session, + IEnumerable requestMessages, + Exception invokeException) + { + this.Agent = Throw.IfNull(agent); + this.Session = session; + this.RequestMessages = Throw.IfNull(requestMessages); + this.InvokeException = Throw.IfNull(invokeException); } /// @@ -293,16 +316,16 @@ public InvokedContext( /// A collection of instances representing new messages that were provided by the caller. /// This does not include any supplied messages. /// - public IEnumerable RequestMessages { get; set { field = Throw.IfNull(value); } } + public IEnumerable RequestMessages { get; } /// /// Gets the collection of response messages generated during this invocation if the invocation succeeded. /// /// /// A collection of instances representing the response, - /// or if the invocation failed or did not produce response messages. + /// or if the invocation failed. /// - public IEnumerable? ResponseMessages { get; set; } + public IEnumerable? ResponseMessages { get; } /// /// Gets the that was thrown during the invocation, if the invocation failed. @@ -310,6 +333,6 @@ public InvokedContext( /// /// The exception that caused the invocation to fail, or if the invocation succeeded. /// - public Exception? InvokeException { get; set; } + public Exception? InvokeException { get; } } } diff --git a/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs b/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs index 2c840e0323..66b9e7db99 100644 --- a/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs +++ b/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs @@ -455,7 +455,7 @@ private async Task NotifyAIContextProviderOfSuccessAsync( { if (this.AIContextProviders is { Count: > 0 } contextProviders) { - AIContextProvider.InvokedContext invokedContext = new(this, session, inputMessages) { ResponseMessages = responseMessages }; + AIContextProvider.InvokedContext invokedContext = new(this, session, inputMessages, responseMessages); foreach (var contextProvider in contextProviders) { @@ -475,7 +475,7 @@ private async Task NotifyAIContextProviderOfFailureAsync( { if (this.AIContextProviders is { Count: > 0 } contextProviders) { - AIContextProvider.InvokedContext invokedContext = new(this, session, inputMessages) { InvokeException = ex }; + AIContextProvider.InvokedContext invokedContext = new(this, session, inputMessages, ex); foreach (var contextProvider in contextProviders) { @@ -798,10 +798,7 @@ private Task NotifyChatHistoryProviderOfFailureAsync( // If we don't have one, it means that the chat history is service managed and the underlying service is responsible for storing messages. if (provider is not null) { - var invokedContext = new ChatHistoryProvider.InvokedContext(this, session, requestMessages) - { - InvokeException = ex - }; + var invokedContext = new ChatHistoryProvider.InvokedContext(this, session, requestMessages, ex); return provider.InvokedAsync(invokedContext, cancellationToken).AsTask(); } @@ -822,10 +819,7 @@ private Task NotifyChatHistoryProviderOfNewMessagesAsync( // If we don't have one, it means that the chat history is service managed and the underlying service is responsible for storing messages. if (provider is not null) { - var invokedContext = new ChatHistoryProvider.InvokedContext(this, session, requestMessages) - { - ResponseMessages = responseMessages - }; + var invokedContext = new ChatHistoryProvider.InvokedContext(this, session, requestMessages, responseMessages); return provider.InvokedAsync(invokedContext, cancellationToken).AsTask(); } diff --git a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AIContextProviderTests.cs b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AIContextProviderTests.cs index 04d4059932..14a0f81e08 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AIContextProviderTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AIContextProviderTests.cs @@ -25,7 +25,7 @@ public async Task InvokedAsync_ReturnsCompletedTaskAsync() var messages = new ReadOnlyCollection([]); // Act - ValueTask task = provider.InvokedAsync(new(s_mockAgent, s_mockSession, messages)); + ValueTask task = provider.InvokedAsync(new(s_mockAgent, s_mockSession, messages, [])); // Assert Assert.Equal(default, task); @@ -42,7 +42,7 @@ public void InvokingContext_Constructor_ThrowsForNullMessages() public void InvokedContext_Constructor_ThrowsForNullMessages() { // Act & Assert - Assert.Throws(() => new AIContextProvider.InvokedContext(s_mockAgent, s_mockSession, null!)); + Assert.Throws(() => new AIContextProvider.InvokedContext(s_mockAgent, s_mockSession, null!, [])); } #endregion @@ -238,42 +238,15 @@ public void InvokingContext_Constructor_ThrowsForNullAgent() #region InvokedContext Tests - [Fact] - public void InvokedContext_RequestMessages_SetterThrowsForNull() - { - // Arrange - var messages = new ReadOnlyCollection([new(ChatRole.User, "Hello")]); - var context = new AIContextProvider.InvokedContext(s_mockAgent, s_mockSession, messages); - - // Act & Assert - Assert.Throws(() => context.RequestMessages = null!); - } - - [Fact] - public void InvokedContext_RequestMessages_SetterRoundtrips() - { - // Arrange - var initialMessages = new ReadOnlyCollection([new(ChatRole.User, "Hello")]); - var newMessages = new List { new(ChatRole.User, "New message") }; - var context = new AIContextProvider.InvokedContext(s_mockAgent, s_mockSession, initialMessages); - - // Act - context.RequestMessages = newMessages; - - // Assert - Assert.Same(newMessages, context.RequestMessages); - } - [Fact] public void InvokedContext_ResponseMessages_Roundtrips() { // Arrange var requestMessages = new ReadOnlyCollection([new(ChatRole.User, "Hello")]); var responseMessages = new List { new(ChatRole.Assistant, "Response message") }; - var context = new AIContextProvider.InvokedContext(s_mockAgent, s_mockSession, requestMessages); // Act - context.ResponseMessages = responseMessages; + var context = new AIContextProvider.InvokedContext(s_mockAgent, s_mockSession, requestMessages, responseMessages); // Assert Assert.Same(responseMessages, context.ResponseMessages); @@ -285,10 +258,9 @@ public void InvokedContext_InvokeException_Roundtrips() // Arrange var requestMessages = new ReadOnlyCollection([new(ChatRole.User, "Hello")]); var exception = new InvalidOperationException("Test exception"); - var context = new AIContextProvider.InvokedContext(s_mockAgent, s_mockSession, requestMessages); // Act - context.InvokeException = exception; + var context = new AIContextProvider.InvokedContext(s_mockAgent, s_mockSession, requestMessages, exception); // Assert Assert.Same(exception, context.InvokeException); @@ -301,7 +273,7 @@ public void InvokedContext_Agent_ReturnsConstructorValue() var requestMessages = new ReadOnlyCollection([new(ChatRole.User, "Hello")]); // Act - var context = new AIContextProvider.InvokedContext(s_mockAgent, s_mockSession, requestMessages); + var context = new AIContextProvider.InvokedContext(s_mockAgent, s_mockSession, requestMessages, []); // Assert Assert.Same(s_mockAgent, context.Agent); @@ -314,7 +286,7 @@ public void InvokedContext_Session_ReturnsConstructorValue() var requestMessages = new ReadOnlyCollection([new(ChatRole.User, "Hello")]); // Act - var context = new AIContextProvider.InvokedContext(s_mockAgent, s_mockSession, requestMessages); + var context = new AIContextProvider.InvokedContext(s_mockAgent, s_mockSession, requestMessages, []); // Assert Assert.Same(s_mockSession, context.Session); @@ -327,7 +299,7 @@ public void InvokedContext_Session_CanBeNull() var requestMessages = new ReadOnlyCollection([new(ChatRole.User, "Hello")]); // Act - var context = new AIContextProvider.InvokedContext(s_mockAgent, null, requestMessages); + var context = new AIContextProvider.InvokedContext(s_mockAgent, null, requestMessages, []); // Assert Assert.Null(context.Session); @@ -340,7 +312,27 @@ public void InvokedContext_Constructor_ThrowsForNullAgent() var requestMessages = new ReadOnlyCollection([new(ChatRole.User, "Hello")]); // Act & Assert - Assert.Throws(() => new AIContextProvider.InvokedContext(null!, s_mockSession, requestMessages)); + Assert.Throws(() => new AIContextProvider.InvokedContext(null!, s_mockSession, requestMessages, [])); + } + + [Fact] + public void InvokedContext_SuccessConstructor_ThrowsForNullResponseMessages() + { + // Arrange + var requestMessages = new ReadOnlyCollection([new(ChatRole.User, "Hello")]); + + // Act & Assert + Assert.Throws(() => new AIContextProvider.InvokedContext(s_mockAgent, s_mockSession, requestMessages, (IEnumerable)null!)); + } + + [Fact] + public void InvokedContext_FailureConstructor_ThrowsForNullException() + { + // Arrange + var requestMessages = new ReadOnlyCollection([new(ChatRole.User, "Hello")]); + + // Act & Assert + Assert.Throws(() => new AIContextProvider.InvokedContext(s_mockAgent, s_mockSession, requestMessages, (Exception)null!)); } #endregion diff --git a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/ChatHistoryProviderTests.cs b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/ChatHistoryProviderTests.cs index 42f2dd65f1..7fccca8d1b 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/ChatHistoryProviderTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/ChatHistoryProviderTests.cs @@ -172,33 +172,7 @@ public void InvokingContext_Constructor_ThrowsForNullAgent() public void InvokedContext_Constructor_ThrowsForNullRequestMessages() { // Arrange & Act & Assert - Assert.Throws(() => new ChatHistoryProvider.InvokedContext(s_mockAgent, s_mockSession, null!)); - } - - [Fact] - public void InvokedContext_RequestMessages_SetterThrowsForNull() - { - // Arrange - var requestMessages = new List { new(ChatRole.User, "Hello") }; - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, s_mockSession, requestMessages); - - // Act & Assert - Assert.Throws(() => context.RequestMessages = null!); - } - - [Fact] - public void InvokedContext_RequestMessages_SetterRoundtrips() - { - // Arrange - var initialMessages = new List { new(ChatRole.User, "Hello") }; - var newMessages = new List { new(ChatRole.User, "New message") }; - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, s_mockSession, initialMessages); - - // Act - context.RequestMessages = newMessages; - - // Assert - Assert.Same(newMessages, context.RequestMessages); + Assert.Throws(() => new ChatHistoryProvider.InvokedContext(s_mockAgent, s_mockSession, null!, [])); } [Fact] @@ -207,10 +181,9 @@ public void InvokedContext_ResponseMessages_Roundtrips() // Arrange var requestMessages = new List { new(ChatRole.User, "Hello") }; var responseMessages = new List { new(ChatRole.Assistant, "Response message") }; - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, s_mockSession, requestMessages); // Act - context.ResponseMessages = responseMessages; + var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, s_mockSession, requestMessages, responseMessages); // Assert Assert.Same(responseMessages, context.ResponseMessages); @@ -222,10 +195,9 @@ public void InvokedContext_InvokeException_Roundtrips() // Arrange var requestMessages = new List { new(ChatRole.User, "Hello") }; var exception = new InvalidOperationException("Test exception"); - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, s_mockSession, requestMessages); // Act - context.InvokeException = exception; + var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, s_mockSession, requestMessages, exception); // Assert Assert.Same(exception, context.InvokeException); @@ -238,7 +210,7 @@ public void InvokedContext_Agent_ReturnsConstructorValue() var requestMessages = new List { new(ChatRole.User, "Hello") }; // Act - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, s_mockSession, requestMessages); + var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, s_mockSession, requestMessages, []); // Assert Assert.Same(s_mockAgent, context.Agent); @@ -251,7 +223,7 @@ public void InvokedContext_Session_ReturnsConstructorValue() var requestMessages = new List { new(ChatRole.User, "Hello") }; // Act - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, s_mockSession, requestMessages); + var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, s_mockSession, requestMessages, []); // Assert Assert.Same(s_mockSession, context.Session); @@ -264,7 +236,7 @@ public void InvokedContext_Session_CanBeNull() var requestMessages = new List { new(ChatRole.User, "Hello") }; // Act - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, null, requestMessages); + var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, null, requestMessages, []); // Assert Assert.Null(context.Session); @@ -277,7 +249,27 @@ public void InvokedContext_Constructor_ThrowsForNullAgent() var requestMessages = new List { new(ChatRole.User, "Hello") }; // Act & Assert - Assert.Throws(() => new ChatHistoryProvider.InvokedContext(null!, s_mockSession, requestMessages)); + Assert.Throws(() => new ChatHistoryProvider.InvokedContext(null!, s_mockSession, requestMessages, [])); + } + + [Fact] + public void InvokedContext_SuccessConstructor_ThrowsForNullResponseMessages() + { + // Arrange + var requestMessages = new List { new(ChatRole.User, "Hello") }; + + // Act & Assert + Assert.Throws(() => new ChatHistoryProvider.InvokedContext(s_mockAgent, s_mockSession, requestMessages, (IEnumerable)null!)); + } + + [Fact] + public void InvokedContext_FailureConstructor_ThrowsForNullException() + { + // Arrange + var requestMessages = new List { new(ChatRole.User, "Hello") }; + + // Act & Assert + Assert.Throws(() => new ChatHistoryProvider.InvokedContext(s_mockAgent, s_mockSession, requestMessages, (Exception)null!)); } #endregion diff --git a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/InMemoryChatHistoryProviderTests.cs b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/InMemoryChatHistoryProviderTests.cs index 1833fa1cc3..b907529241 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/InMemoryChatHistoryProviderTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/InMemoryChatHistoryProviderTests.cs @@ -84,10 +84,7 @@ public async Task InvokedAsyncAddsMessagesAsync() var provider = new InMemoryChatHistoryProvider(); provider.SetMessages(session, providerMessages); - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, requestMessages) - { - ResponseMessages = responseMessages - }; + var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, requestMessages, responseMessages); await provider.InvokedAsync(context, CancellationToken.None); // Assert @@ -107,9 +104,8 @@ public async Task InvokedAsyncWithEmptyDoesNotFailAsync() // Arrange var provider = new InMemoryChatHistoryProvider(); - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, []); + var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, [], []); await provider.InvokedAsync(context, CancellationToken.None); - // Assert Assert.Empty(provider.GetMessages(session)); } @@ -222,7 +218,7 @@ public async Task InvokedAsyncWithEmptyMessagesDoesNotChangeProviderAsync() var provider = new InMemoryChatHistoryProvider(); var messages = new List(); - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, messages); + var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, messages, []); await provider.InvokedAsync(context, CancellationToken.None); // Assert @@ -263,7 +259,7 @@ public async Task AddMessagesAsync_WithReducer_AfterMessageAdded_InvokesReducerA var provider = new InMemoryChatHistoryProvider(new() { ChatReducer = reducerMock.Object, ReducerTriggerEvent = InMemoryChatHistoryProviderOptions.ChatReducerTriggerEvent.AfterMessageAdded }); // Act - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, originalMessages); + var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, originalMessages, []); await provider.InvokedAsync(context, CancellationToken.None); // Assert @@ -323,7 +319,7 @@ public async Task AddMessagesAsync_WithReducer_ButWrongTrigger_DoesNotInvokeRedu var provider = new InMemoryChatHistoryProvider(new() { ChatReducer = reducerMock.Object, ReducerTriggerEvent = InMemoryChatHistoryProviderOptions.ChatReducerTriggerEvent.BeforeMessagesRetrieval }); // Act - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, originalMessages); + var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, originalMessages, []); await provider.InvokedAsync(context, CancellationToken.None); // Assert @@ -370,15 +366,7 @@ public async Task InvokedAsync_WithException_DoesNotAddMessagesAsync() { new(ChatRole.User, "Hello") }; - var responseMessages = new List - { - new(ChatRole.Assistant, "Hi there!") - }; - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, requestMessages) - { - ResponseMessages = responseMessages, - InvokeException = new InvalidOperationException("Test exception") - }; + var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, requestMessages, new InvalidOperationException("Test exception")); // Act await provider.InvokedAsync(context, CancellationToken.None); @@ -410,10 +398,7 @@ public async Task InvokedAsync_DefaultFilter_ExcludesChatHistoryMessagesAsync() new(ChatRole.System, "From context provider") { AdditionalProperties = new() { { AgentRequestMessageSourceAttribution.AdditionalPropertiesKey, new AgentRequestMessageSourceAttribution(AgentRequestMessageSourceType.AIContextProvider, "ContextSource") } } }, }; - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, requestMessages) - { - ResponseMessages = [new ChatMessage(ChatRole.Assistant, "Response")] - }; + var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, requestMessages, [new ChatMessage(ChatRole.Assistant, "Response")]); // Act await provider.InvokedAsync(context, CancellationToken.None); @@ -442,10 +427,7 @@ public async Task InvokedAsync_CustomFilter_OverridesDefaultAsync() new(ChatRole.System, "From context provider") { AdditionalProperties = new() { { AgentRequestMessageSourceAttribution.AdditionalPropertiesKey, new AgentRequestMessageSourceAttribution(AgentRequestMessageSourceType.AIContextProvider, "ContextSource") } } }, }; - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, requestMessages) - { - ResponseMessages = [new ChatMessage(ChatRole.Assistant, "Response")] - }; + var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, requestMessages, [new ChatMessage(ChatRole.Assistant, "Response")]); // Act await provider.InvokedAsync(context, CancellationToken.None); diff --git a/dotnet/tests/Microsoft.Agents.AI.CosmosNoSql.UnitTests/CosmosChatHistoryProviderTests.cs b/dotnet/tests/Microsoft.Agents.AI.CosmosNoSql.UnitTests/CosmosChatHistoryProviderTests.cs index 6be86d60bb..12bd467e71 100644 --- a/dotnet/tests/Microsoft.Agents.AI.CosmosNoSql.UnitTests/CosmosChatHistoryProviderTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.CosmosNoSql.UnitTests/CosmosChatHistoryProviderTests.cs @@ -231,10 +231,7 @@ public async Task InvokedAsync_WithSingleMessage_ShouldAddMessageAsync() _ => new CosmosChatHistoryProvider.State(conversationId)); var message = new ChatMessage(ChatRole.User, "Hello, world!"); - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, [message]) - { - ResponseMessages = [] - }; + var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, [message], []); // Act await provider.InvokedAsync(context); @@ -309,10 +306,7 @@ public async Task InvokedAsync_WithMultipleMessages_ShouldAddAllMessagesAsync() new ChatMessage(ChatRole.Assistant, "Response message") }; - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, requestMessages) - { - ResponseMessages = responseMessages - }; + var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, requestMessages, responseMessages); // Act await provider.InvokedAsync(context); @@ -367,8 +361,8 @@ public async Task InvokingAsync_WithConversationIsolation_ShouldOnlyReturnMessag using var store2 = new CosmosChatHistoryProvider(this._connectionString, s_testDatabaseId, TestContainerId, _ => new CosmosChatHistoryProvider.State(conversation2), stateKey: "conv2"); - var context1 = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, [new ChatMessage(ChatRole.User, "Message for conversation 1")]); - var context2 = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, [new ChatMessage(ChatRole.User, "Message for conversation 2")]); + var context1 = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, [new ChatMessage(ChatRole.User, "Message for conversation 1")], []); + var context2 = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, [new ChatMessage(ChatRole.User, "Message for conversation 2")], []); await store1.InvokedAsync(context1); await store2.InvokedAsync(context2); @@ -416,7 +410,7 @@ public async Task FullWorkflow_AddAndGet_ShouldWorkCorrectlyAsync() }; // Act 1: Add messages - var invokedContext = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, messages); + var invokedContext = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, messages, []); await originalStore.InvokedAsync(invokedContext); // Act 2: Verify messages were added @@ -562,7 +556,7 @@ public async Task InvokedAsync_WithHierarchicalPartitioning_ShouldAddMessageWith _ => new CosmosChatHistoryProvider.State(SessionId, TenantId, UserId)); var message = new ChatMessage(ChatRole.User, "Hello from hierarchical partitioning!"); - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, [message]); + var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, [message], []); // Act await provider.InvokedAsync(context); @@ -621,7 +615,7 @@ public async Task InvokedAsync_WithHierarchicalMultipleMessages_ShouldAddAllMess new ChatMessage(ChatRole.User, "Third hierarchical message") }; - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, messages); + var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, messages, []); // Act await provider.InvokedAsync(context); @@ -660,8 +654,8 @@ public async Task InvokingAsync_WithHierarchicalPartitionIsolation_ShouldIsolate _ => new CosmosChatHistoryProvider.State(SessionId, TenantId, UserId2), stateKey: "user2"); // Add messages to both stores - var context1 = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, [new ChatMessage(ChatRole.User, "Message from user 1")]); - var context2 = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, [new ChatMessage(ChatRole.User, "Message from user 2")]); + var context1 = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, [new ChatMessage(ChatRole.User, "Message from user 1")], []); + var context2 = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, [new ChatMessage(ChatRole.User, "Message from user 2")], []); await store1.InvokedAsync(context1); await store2.InvokedAsync(context2); @@ -700,7 +694,7 @@ public async Task StateBag_WithHierarchicalPartitioning_ShouldPreserveStateAcros using var originalStore = new CosmosChatHistoryProvider(this._connectionString, s_testDatabaseId, HierarchicalTestContainerId, _ => new CosmosChatHistoryProvider.State(SessionId, TenantId, UserId)); - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, [new ChatMessage(ChatRole.User, "Test serialization message")]); + var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, [new ChatMessage(ChatRole.User, "Test serialization message")], []); await originalStore.InvokedAsync(context); // Wait a moment for eventual consistency @@ -738,8 +732,8 @@ public async Task HierarchicalAndSimplePartitioning_ShouldCoexistAsync() _ => new CosmosChatHistoryProvider.State(SessionId, "tenant-coexist", "user-coexist"), stateKey: "hierarchical"); // Add messages to both - var simpleContext = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, [new ChatMessage(ChatRole.User, "Simple partitioning message")]); - var hierarchicalContext = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, [new ChatMessage(ChatRole.User, "Hierarchical partitioning message")]); + var simpleContext = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, [new ChatMessage(ChatRole.User, "Simple partitioning message")], []); + var hierarchicalContext = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, [new ChatMessage(ChatRole.User, "Hierarchical partitioning message")], []); await simpleProvider.InvokedAsync(simpleContext); await hierarchicalProvider.InvokedAsync(hierarchicalContext); @@ -783,7 +777,7 @@ public async Task MaxMessagesToRetrieve_ShouldLimitAndReturnMostRecentAsync() await Task.Delay(10); // Small delay to ensure different timestamps } - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, messages); + var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, messages, []); await provider.InvokedAsync(context); // Wait for eventual consistency @@ -823,7 +817,7 @@ public async Task MaxMessagesToRetrieve_Null_ShouldReturnAllMessagesAsync() messages.Add(new ChatMessage(ChatRole.User, $"Message {i}")); } - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, messages); + var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, messages, []); await provider.InvokedAsync(context); // Wait for eventual consistency @@ -862,10 +856,7 @@ public async Task InvokedAsync_DefaultFilter_ExcludesChatHistoryMessagesFromStor new ChatMessage(ChatRole.System, "From context provider") { AdditionalProperties = new() { { AgentRequestMessageSourceAttribution.AdditionalPropertiesKey, new AgentRequestMessageSourceAttribution(AgentRequestMessageSourceType.AIContextProvider, "ContextSource") } } }, }; - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, requestMessages) - { - ResponseMessages = [new ChatMessage(ChatRole.Assistant, "Response")] - }; + var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, requestMessages, [new ChatMessage(ChatRole.Assistant, "Response")]); // Act await provider.InvokedAsync(context); @@ -904,10 +895,7 @@ public async Task InvokedAsync_CustomStorageInputFilter_OverridesDefaultAsync() new ChatMessage(ChatRole.System, "From context provider") { AdditionalProperties = new() { { AgentRequestMessageSourceAttribution.AdditionalPropertiesKey, new AgentRequestMessageSourceAttribution(AgentRequestMessageSourceType.AIContextProvider, "ContextSource") } } }, }; - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, requestMessages) - { - ResponseMessages = [new ChatMessage(ChatRole.Assistant, "Response")] - }; + var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, requestMessages, [new ChatMessage(ChatRole.Assistant, "Response")]); // Act await provider.InvokedAsync(context); @@ -944,10 +932,7 @@ public async Task InvokingAsync_RetrievalOutputFilter_FiltersRetrievedMessagesAs new ChatMessage(ChatRole.System, "System message"), }; - var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, requestMessages) - { - ResponseMessages = [new ChatMessage(ChatRole.Assistant, "Assistant response")] - }; + var context = new ChatHistoryProvider.InvokedContext(s_mockAgent, session, requestMessages, [new ChatMessage(ChatRole.Assistant, "Assistant response")]); await provider.InvokedAsync(context); diff --git a/dotnet/tests/Microsoft.Agents.AI.Mem0.IntegrationTests/Mem0ProviderTests.cs b/dotnet/tests/Microsoft.Agents.AI.Mem0.IntegrationTests/Mem0ProviderTests.cs index c713b9f9c9..9fafb1b256 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Mem0.IntegrationTests/Mem0ProviderTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Mem0.IntegrationTests/Mem0ProviderTests.cs @@ -57,7 +57,7 @@ public async Task CanAddAndRetrieveUserMemoriesAsync() Assert.DoesNotContain("Caoimhe", ctxBefore.Messages?[0].Text ?? string.Empty); // Act - await sut.InvokedAsync(new AIContextProvider.InvokedContext(s_mockAgent, mockSession, [input])); + await sut.InvokedAsync(new AIContextProvider.InvokedContext(s_mockAgent, mockSession, [input], [])); var ctxAfterAdding = await GetContextWithRetryAsync(sut, mockSession, question); await sut.ClearStoredMemoriesAsync(mockSession); var ctxAfterClearing = await sut.InvokingAsync(new AIContextProvider.InvokingContext(s_mockAgent, mockSession, new AIContext { Messages = new List { question } })); @@ -82,7 +82,7 @@ public async Task CanAddAndRetrieveAgentMemoriesAsync() Assert.DoesNotContain("Caoimhe", ctxBefore.Messages?[0].Text ?? string.Empty); // Act - await sut.InvokedAsync(new AIContextProvider.InvokedContext(s_mockAgent, mockSession, [assistantIntro])); + await sut.InvokedAsync(new AIContextProvider.InvokedContext(s_mockAgent, mockSession, [assistantIntro], [])); var ctxAfterAdding = await GetContextWithRetryAsync(sut, mockSession, question); await sut.ClearStoredMemoriesAsync(mockSession); var ctxAfterClearing = await sut.InvokingAsync(new AIContextProvider.InvokingContext(s_mockAgent, mockSession, new AIContext { Messages = new List { question } })); @@ -114,7 +114,7 @@ public async Task DoesNotLeakMemoriesAcrossAgentScopesAsync() Assert.DoesNotContain("Caoimhe", ctxBefore2.Messages?[0].Text ?? string.Empty); // Act - await sut1.InvokedAsync(new AIContextProvider.InvokedContext(s_mockAgent, mockSession1, [assistantIntro])); + await sut1.InvokedAsync(new AIContextProvider.InvokedContext(s_mockAgent, mockSession1, [assistantIntro], [])); var ctxAfterAdding1 = await GetContextWithRetryAsync(sut1, mockSession1, question); var ctxAfterAdding2 = await GetContextWithRetryAsync(sut2, mockSession2, question); diff --git a/dotnet/tests/Microsoft.Agents.AI.Mem0.UnitTests/Mem0ProviderTests.cs b/dotnet/tests/Microsoft.Agents.AI.Mem0.UnitTests/Mem0ProviderTests.cs index 83c9d0a89d..3e76c11a01 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Mem0.UnitTests/Mem0ProviderTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Mem0.UnitTests/Mem0ProviderTests.cs @@ -227,7 +227,7 @@ public async Task InvokedAsync_PersistsAllowedMessagesAsync() }; // Act - await sut.InvokedAsync(new AIContextProvider.InvokedContext(s_mockAgent, mockSession, requestMessages) { ResponseMessages = responseMessages }); + await sut.InvokedAsync(new AIContextProvider.InvokedContext(s_mockAgent, mockSession, requestMessages, responseMessages)); // Assert var memoryPosts = this._handler.Requests.Where(r => r.RequestMessage.RequestUri!.AbsolutePath == "/v1/memories/" && r.RequestMessage.Method == HttpMethod.Post).ToList(); @@ -255,7 +255,7 @@ public async Task InvokedAsync_PersistsNothingForFailedRequestAsync() }; // Act - await sut.InvokedAsync(new AIContextProvider.InvokedContext(s_mockAgent, mockSession, requestMessages) { ResponseMessages = null, InvokeException = new InvalidOperationException("Request Failed") }); + await sut.InvokedAsync(new AIContextProvider.InvokedContext(s_mockAgent, mockSession, requestMessages, new InvalidOperationException("Request Failed"))); // Assert Assert.Empty(this._handler.Requests); @@ -282,7 +282,7 @@ public async Task InvokedAsync_ShouldNotThrow_WhenStorageFailsAsync() }; // Act - await sut.InvokedAsync(new AIContextProvider.InvokedContext(s_mockAgent, mockSession, requestMessages) { ResponseMessages = responseMessages }); + await sut.InvokedAsync(new AIContextProvider.InvokedContext(s_mockAgent, mockSession, requestMessages, responseMessages)); // Assert this._loggerMock.Verify( @@ -333,7 +333,7 @@ public async Task InvokedAsync_LogsUserIdBasedOnEnableSensitiveTelemetryDataAsyn }; // Act - await sut.InvokedAsync(new AIContextProvider.InvokedContext(s_mockAgent, mockSession, requestMessages) { ResponseMessages = responseMessages }); + await sut.InvokedAsync(new AIContextProvider.InvokedContext(s_mockAgent, mockSession, requestMessages, responseMessages)); // Assert Assert.Equal(expectedLogCount, this._loggerMock.Invocations.Count); @@ -510,7 +510,7 @@ public async Task InvokedAsync_DefaultFilter_ExcludesNonExternalMessagesFromStor }; // Act - await sut.InvokedAsync(new AIContextProvider.InvokedContext(s_mockAgent, mockSession, requestMessages)); + await sut.InvokedAsync(new AIContextProvider.InvokedContext(s_mockAgent, mockSession, requestMessages, [])); // Assert - Only the External message should be persisted var memoryPosts = this._handler.Requests.Where(r => r.RequestMessage.RequestUri!.AbsolutePath == "/v1/memories/" && r.RequestMessage.Method == HttpMethod.Post).ToList(); @@ -539,7 +539,7 @@ public async Task InvokedAsync_CustomStorageInputFilter_OverridesDefaultAsync() }; // Act - await sut.InvokedAsync(new AIContextProvider.InvokedContext(s_mockAgent, mockSession, requestMessages)); + await sut.InvokedAsync(new AIContextProvider.InvokedContext(s_mockAgent, mockSession, requestMessages, [])); // Assert - Both messages should be persisted (identity filter overrides default) var memoryPosts = this._handler.Requests.Where(r => r.RequestMessage.RequestUri!.AbsolutePath == "/v1/memories/" && r.RequestMessage.Method == HttpMethod.Post).ToList(); diff --git a/dotnet/tests/Microsoft.Agents.AI.UnitTests/Data/TextSearchProviderTests.cs b/dotnet/tests/Microsoft.Agents.AI.UnitTests/Data/TextSearchProviderTests.cs index 98cb2ce85a..e4f3a2a818 100644 --- a/dotnet/tests/Microsoft.Agents.AI.UnitTests/Data/TextSearchProviderTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.UnitTests/Data/TextSearchProviderTests.cs @@ -442,7 +442,7 @@ public async Task InvokedAsync_DefaultFilter_ExcludesNonExternalMessagesFromStor }; // Store messages via InvokedAsync - await provider.InvokedAsync(new(s_mockAgent, session, requestMessages)); + await provider.InvokedAsync(new(s_mockAgent, session, requestMessages, [])); // Now invoke to read stored memory var invokingContext = new AIContextProvider.InvokingContext(s_mockAgent, session, new AIContext { Messages = [new ChatMessage(ChatRole.User, "Next")] }); @@ -478,7 +478,7 @@ public async Task InvokedAsync_CustomStorageInputFilter_OverridesDefaultAsync() }; // Store messages via InvokedAsync - await provider.InvokedAsync(new(s_mockAgent, session, requestMessages)); + await provider.InvokedAsync(new(s_mockAgent, session, requestMessages, [])); // Now invoke to read stored memory var invokingContext = new AIContextProvider.InvokingContext(s_mockAgent, session, new AIContext { Messages = [new ChatMessage(ChatRole.User, "Next")] }); @@ -519,7 +519,7 @@ public async Task InvokingAsync_WithPreviousFailedRequest_ShouldNotIncludeFailed }; var session = new TestAgentSession(); - await provider.InvokedAsync(new(s_mockAgent, session, initialMessages) { InvokeException = new InvalidOperationException("Request Failed") }); + await provider.InvokedAsync(new(s_mockAgent, session, initialMessages, new InvalidOperationException("Request Failed"))); var invokingContext = new AIContextProvider.InvokingContext( s_mockAgent, @@ -560,7 +560,7 @@ public async Task InvokingAsync_WithRecentMessageMemory_ShouldIncludeStoredMessa new ChatMessage(ChatRole.User, "C"), new ChatMessage(ChatRole.Assistant, "D"), }; - await provider.InvokedAsync(new(s_mockAgent, session, initialMessages)); + await provider.InvokedAsync(new(s_mockAgent, session, initialMessages, [])); var invokingContext = new AIContextProvider.InvokingContext( s_mockAgent, @@ -600,7 +600,8 @@ await provider.InvokedAsync(new( [ new ChatMessage(ChatRole.User, "A"), new ChatMessage(ChatRole.Assistant, "B"), - ])); + ], + [])); // Second memory update (C,D,E) await provider.InvokedAsync(new( @@ -610,7 +611,8 @@ await provider.InvokedAsync(new( new ChatMessage(ChatRole.User, "C"), new ChatMessage(ChatRole.Assistant, "D"), new ChatMessage(ChatRole.User, "E"), - ])); + ], + [])); var invokingContext = new AIContextProvider.InvokingContext(s_mockAgent, session, new AIContext { Messages = new List { new(ChatRole.User, "F") } }); @@ -648,7 +650,7 @@ public async Task InvokingAsync_WithRecentMessageRolesIncluded_ShouldFilterRoles new ChatMessage(ChatRole.User, "U2"), new ChatMessage(ChatRole.Assistant, "A2"), }; - await provider.InvokedAsync(new(s_mockAgent, session, initialMessages)); + await provider.InvokedAsync(new(s_mockAgent, session, initialMessages, [])); var invokingContext = new AIContextProvider.InvokingContext( s_mockAgent, @@ -686,7 +688,7 @@ public async Task InvokedAsync_ShouldPersistMessagesToSessionStateBagAsync() }; // Act - await provider.InvokedAsync(new(s_mockAgent, session, messages)); // Populate recent memory. + await provider.InvokedAsync(new(s_mockAgent, session, messages, [])); // Populate recent memory. // Assert - State should be in the session's StateBag var stateBagSerialized = session.StateBag.Serialize(); @@ -717,7 +719,7 @@ public async Task StateBag_RoundtripRestoresMessagesAsync() new ChatMessage(ChatRole.User, "C"), new ChatMessage(ChatRole.Assistant, "D"), }; - await provider.InvokedAsync(new(s_mockAgent, session, messages)); + await provider.InvokedAsync(new(s_mockAgent, session, messages, [])); // Act - Serialize and deserialize the StateBag var serializedStateBag = session.StateBag.Serialize(); diff --git a/dotnet/tests/Microsoft.Agents.AI.UnitTests/Memory/ChatHistoryMemoryProviderTests.cs b/dotnet/tests/Microsoft.Agents.AI.UnitTests/Memory/ChatHistoryMemoryProviderTests.cs index 2d7d8a74c0..29e5e46777 100644 --- a/dotnet/tests/Microsoft.Agents.AI.UnitTests/Memory/ChatHistoryMemoryProviderTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.UnitTests/Memory/ChatHistoryMemoryProviderTests.cs @@ -170,10 +170,7 @@ public async Task InvokedAsync_UpsertsMessages_ToCollectionAsync() var requestMsgWithNulls = new ChatMessage(ChatRole.User, "request text nulls"); var responseMsg = new ChatMessage(ChatRole.Assistant, "response text") { MessageId = "resp-1", AuthorName = "assistant" }; - var invokedContext = new AIContextProvider.InvokedContext(s_mockAgent, new TestAgentSession(), [requestMsgWithValues, requestMsgWithNulls]) - { - ResponseMessages = [responseMsg] - }; + var invokedContext = new AIContextProvider.InvokedContext(s_mockAgent, new TestAgentSession(), [requestMsgWithValues, requestMsgWithNulls], [responseMsg]); // Act await provider.InvokedAsync(invokedContext, CancellationToken.None); @@ -228,10 +225,7 @@ public async Task InvokedAsync_DoesNotUpsertMessages_WhenInvokeFailedAsync() 1, _ => new ChatHistoryMemoryProvider.State(new ChatHistoryMemoryProviderScope { UserId = "UID" })); var requestMsg = new ChatMessage(ChatRole.User, "request text") { MessageId = "req-1" }; - var invokedContext = new AIContextProvider.InvokedContext(s_mockAgent, new TestAgentSession(), [requestMsg]) - { - InvokeException = new InvalidOperationException("Invoke failed") - }; + var invokedContext = new AIContextProvider.InvokedContext(s_mockAgent, new TestAgentSession(), [requestMsg], new InvalidOperationException("Invoke failed")); // Act await provider.InvokedAsync(invokedContext, CancellationToken.None); @@ -257,7 +251,7 @@ public async Task InvokedAsync_DoesNotThrow_WhenUpsertThrowsAsync() _ => new ChatHistoryMemoryProvider.State(new ChatHistoryMemoryProviderScope { UserId = "UID" }), loggerFactory: this._loggerFactoryMock.Object); var requestMsg = new ChatMessage(ChatRole.User, "request text") { MessageId = "req-1" }; - var invokedContext = new AIContextProvider.InvokedContext(s_mockAgent, new TestAgentSession(), [requestMsg]); + var invokedContext = new AIContextProvider.InvokedContext(s_mockAgent, new TestAgentSession(), [requestMsg], []); // Act await provider.InvokedAsync(invokedContext, CancellationToken.None); @@ -308,7 +302,7 @@ public async Task InvokedAsync_LogsUserIdBasedOnEnableSensitiveTelemetryDataAsyn loggerFactory: this._loggerFactoryMock.Object); var requestMsg = new ChatMessage(ChatRole.User, "request text"); - var invokedContext = new AIContextProvider.InvokedContext(s_mockAgent, new TestAgentSession(), [requestMsg]); + var invokedContext = new AIContextProvider.InvokedContext(s_mockAgent, new TestAgentSession(), [requestMsg], []); // Act await provider.InvokedAsync(invokedContext, CancellationToken.None); @@ -657,10 +651,7 @@ public async Task InvokedAsync_DefaultFilter_ExcludesNonExternalMessagesFromStor new(ChatRole.System, "From context provider") { AdditionalProperties = new() { { AgentRequestMessageSourceAttribution.AdditionalPropertiesKey, new AgentRequestMessageSourceAttribution(AgentRequestMessageSourceType.AIContextProvider, "ContextSource") } } }, }; - var invokedContext = new AIContextProvider.InvokedContext(s_mockAgent, new TestAgentSession(), requestMessages) - { - ResponseMessages = [new ChatMessage(ChatRole.Assistant, "Response")] - }; + var invokedContext = new AIContextProvider.InvokedContext(s_mockAgent, new TestAgentSession(), requestMessages, [new ChatMessage(ChatRole.Assistant, "Response")]); // Act await provider.InvokedAsync(invokedContext, CancellationToken.None); @@ -704,10 +695,7 @@ public async Task InvokedAsync_CustomStorageInputFilter_OverridesDefaultAsync() new(ChatRole.System, "From history") { AdditionalProperties = new() { { AgentRequestMessageSourceAttribution.AdditionalPropertiesKey, new AgentRequestMessageSourceAttribution(AgentRequestMessageSourceType.ChatHistory, "HistorySource") } } }, }; - var invokedContext = new AIContextProvider.InvokedContext(s_mockAgent, new TestAgentSession(), requestMessages) - { - ResponseMessages = [new ChatMessage(ChatRole.Assistant, "Response")] - }; + var invokedContext = new AIContextProvider.InvokedContext(s_mockAgent, new TestAgentSession(), requestMessages, [new ChatMessage(ChatRole.Assistant, "Response")]); // Act await provider.InvokedAsync(invokedContext, CancellationToken.None);