From ad498279d39a8e9c816a89fb3263610d660f31e9 Mon Sep 17 00:00:00 2001 From: westey <164392973+westey-m@users.noreply.github.com> Date: Tue, 13 Jan 2026 11:30:34 +0000 Subject: [PATCH 1/3] Make ChatMessageStore and AIContextProvider context props setable --- .../Microsoft.Agents.AI.Abstractions/AIContextProvider.cs | 6 +++--- .../Microsoft.Agents.AI.Abstractions/ChatMessageStore.cs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/AIContextProvider.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/AIContextProvider.cs index fd3ff10fc2..c8f3581ff1 100644 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/AIContextProvider.cs +++ b/dotnet/src/Microsoft.Agents.AI.Abstractions/AIContextProvider.cs @@ -142,7 +142,7 @@ public InvokingContext(IEnumerable requestMessages) /// /// A collection of instances representing new messages that were provided by the caller. /// - public IEnumerable RequestMessages { get; } + public IEnumerable RequestMessages { get; set; } } /// @@ -174,7 +174,7 @@ public InvokedContext(IEnumerable requestMessages, IEnumerable instances representing new messages that were provided by the caller. /// This does not include any supplied messages. /// - public IEnumerable RequestMessages { get; } + public IEnumerable RequestMessages { get; set; } /// /// Gets the messages provided by the for this invocation, if any. @@ -183,7 +183,7 @@ public InvokedContext(IEnumerable requestMessages, IEnumerable instances that were provided by the , /// and were used by the agent as part of the invocation. /// - public IEnumerable? AIContextProviderMessages { get; } + public IEnumerable? AIContextProviderMessages { get; set; } /// /// Gets the collection of response messages generated during this invocation if the invocation succeeded. diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/ChatMessageStore.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/ChatMessageStore.cs index d28cd191b7..e8a1f48744 100644 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/ChatMessageStore.cs +++ b/dotnet/src/Microsoft.Agents.AI.Abstractions/ChatMessageStore.cs @@ -152,7 +152,7 @@ public InvokingContext(IEnumerable requestMessages) /// /// A collection of instances representing new messages that were provided by the caller. /// - public IEnumerable RequestMessages { get; } + public IEnumerable RequestMessages { get; set; } } /// @@ -184,7 +184,7 @@ public InvokedContext(IEnumerable requestMessages, IEnumerable instances representing new messages that were provided by the caller. /// This does not include any supplied messages. /// - public IEnumerable RequestMessages { get; } + public IEnumerable RequestMessages { get; set; } /// /// Gets the messages retrieved from the for this invocation, if any. @@ -193,7 +193,7 @@ public InvokedContext(IEnumerable requestMessages, IEnumerable instances that were retrieved from the , /// and were used by the agent as part of the invocation. /// - public IEnumerable ChatMessageStoreMessages { get; } + public IEnumerable ChatMessageStoreMessages { get; set; } /// /// Gets or sets the messages provided by the for this invocation, if any. From b4f4b12faa0f90a2801a25c49639dc9bc7d8b354 Mon Sep 17 00:00:00 2001 From: westey <164392973+westey-m@users.noreply.github.com> Date: Tue, 13 Jan 2026 11:54:14 +0000 Subject: [PATCH 2/3] Add validation to preserve non-null requirement of certain properties. --- .../Microsoft.Agents.AI.Abstractions/AIContextProvider.cs | 4 ++-- .../Microsoft.Agents.AI.Abstractions/ChatMessageStore.cs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/AIContextProvider.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/AIContextProvider.cs index c8f3581ff1..f104f12890 100644 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/AIContextProvider.cs +++ b/dotnet/src/Microsoft.Agents.AI.Abstractions/AIContextProvider.cs @@ -142,7 +142,7 @@ public InvokingContext(IEnumerable requestMessages) /// /// A collection of instances representing new messages that were provided by the caller. /// - public IEnumerable RequestMessages { get; set; } + public IEnumerable RequestMessages { get; set { field = Throw.IfNull(value); } } } /// @@ -174,7 +174,7 @@ public InvokedContext(IEnumerable requestMessages, IEnumerable instances representing new messages that were provided by the caller. /// This does not include any supplied messages. /// - public IEnumerable RequestMessages { get; set; } + public IEnumerable RequestMessages { get; set { field = Throw.IfNull(value); } } /// /// Gets the messages provided by the for this invocation, if any. diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/ChatMessageStore.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/ChatMessageStore.cs index e8a1f48744..54cee063d7 100644 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/ChatMessageStore.cs +++ b/dotnet/src/Microsoft.Agents.AI.Abstractions/ChatMessageStore.cs @@ -152,7 +152,7 @@ public InvokingContext(IEnumerable requestMessages) /// /// A collection of instances representing new messages that were provided by the caller. /// - public IEnumerable RequestMessages { get; set; } + public IEnumerable RequestMessages { get; set { field = Throw.IfNull(value); } } } /// @@ -174,7 +174,7 @@ public sealed class InvokedContext public InvokedContext(IEnumerable requestMessages, IEnumerable chatMessageStoreMessages) { this.RequestMessages = Throw.IfNull(requestMessages); - this.ChatMessageStoreMessages = chatMessageStoreMessages; + this.ChatMessageStoreMessages = Throw.IfNull(chatMessageStoreMessages); } /// @@ -184,7 +184,7 @@ public InvokedContext(IEnumerable requestMessages, IEnumerable instances representing new messages that were provided by the caller. /// This does not include any supplied messages. /// - public IEnumerable RequestMessages { get; set; } + public IEnumerable RequestMessages { get; set { field = Throw.IfNull(value); } } /// /// Gets the messages retrieved from the for this invocation, if any. @@ -193,7 +193,7 @@ public InvokedContext(IEnumerable requestMessages, IEnumerable instances that were retrieved from the , /// and were used by the agent as part of the invocation. /// - public IEnumerable ChatMessageStoreMessages { get; set; } + public IEnumerable ChatMessageStoreMessages { get; set { field = Throw.IfNull(value); } } /// /// Gets or sets the messages provided by the for this invocation, if any. From f48aa2d7a529121de75fb1df860d37fa6193f528 Mon Sep 17 00:00:00 2001 From: westey <164392973+westey-m@users.noreply.github.com> Date: Tue, 13 Jan 2026 18:34:17 +0000 Subject: [PATCH 3/3] Fix broken tests. --- dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs b/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs index 0c02932b0a..8f6d6a5160 100644 --- a/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs +++ b/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs @@ -692,7 +692,7 @@ private async Task List inputMessagesForChatClient = []; IList? aiContextProviderMessages = null; - IList? chatMessageStoreMessages = null; + IList? chatMessageStoreMessages = []; // Populate the thread messages only if we are not continuing an existing response as it's not allowed if (chatOptions?.ContinuationToken is null)