|
1 | 1 | // Copyright (c) Microsoft. All rights reserved.
|
2 | 2 |
|
| 3 | +using System; |
3 | 4 | using System.Collections.Generic;
|
4 | 5 | using System.Diagnostics.CodeAnalysis;
|
5 | 6 | using System.Runtime.CompilerServices;
|
@@ -138,11 +139,22 @@ public async IAsyncEnumerable<AgentResponseItem<ChatMessageContent>> InvokeAsync
|
138 | 139 | AdditionalInstructions = options?.AdditionalInstructions,
|
139 | 140 | });
|
140 | 141 |
|
141 |
| - Kernel kernel = (options?.Kernel ?? this.Kernel).Clone(); |
| 142 | + Kernel kernel = this.GetKernel(options); |
| 143 | +#pragma warning disable SKEXP0110, SKEXP0130 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. |
| 144 | + if (this.UseImmutableKernel) |
| 145 | + { |
| 146 | + kernel = kernel.Clone(); |
| 147 | + } |
142 | 148 |
|
143 | 149 | // Get the context contributions from the AIContextProviders.
|
144 |
| -#pragma warning disable SKEXP0110, SKEXP0130 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. |
145 | 150 | AIContext providersContext = await openAIAssistantAgentThread.AIContextProviders.ModelInvokingAsync(messages, cancellationToken).ConfigureAwait(false);
|
| 151 | + |
| 152 | + // Check for compatibility AIContextProviders and the UseImmutableKernel setting. |
| 153 | + if (providersContext.AIFunctions is { Count: > 0 } && !this.UseImmutableKernel) |
| 154 | + { |
| 155 | + throw new InvalidOperationException("AIContextProviders with AIFunctions are not supported when Agent UseImmutableKernel setting is false."); |
| 156 | + } |
| 157 | + |
146 | 158 | kernel.Plugins.AddFromAIContext(providersContext, "Tools");
|
147 | 159 | #pragma warning restore SKEXP0110, SKEXP0130 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
|
148 | 160 |
|
@@ -226,11 +238,22 @@ public async IAsyncEnumerable<AgentResponseItem<StreamingChatMessageContent>> In
|
226 | 238 | () => new OpenAIAssistantAgentThread(this.Client),
|
227 | 239 | cancellationToken).ConfigureAwait(false);
|
228 | 240 |
|
229 |
| - Kernel kernel = (options?.Kernel ?? this.Kernel).Clone(); |
| 241 | + Kernel kernel = this.GetKernel(options); |
| 242 | +#pragma warning disable SKEXP0110, SKEXP0130 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. |
| 243 | + if (this.UseImmutableKernel) |
| 244 | + { |
| 245 | + kernel = kernel.Clone(); |
| 246 | + } |
230 | 247 |
|
231 | 248 | // Get the context contributions from the AIContextProviders.
|
232 |
| -#pragma warning disable SKEXP0110, SKEXP0130 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. |
233 | 249 | AIContext providersContext = await openAIAssistantAgentThread.AIContextProviders.ModelInvokingAsync(messages, cancellationToken).ConfigureAwait(false);
|
| 250 | + |
| 251 | + // Check for compatibility AIContextProviders and the UseImmutableKernel setting. |
| 252 | + if (providersContext.AIFunctions is { Count: > 0 } && !this.UseImmutableKernel) |
| 253 | + { |
| 254 | + throw new InvalidOperationException("AIContextProviders with AIFunctions are not supported when Agent UseImmutableKernel setting is false."); |
| 255 | + } |
| 256 | + |
234 | 257 | kernel.Plugins.AddFromAIContext(providersContext, "Tools");
|
235 | 258 | #pragma warning restore SKEXP0110, SKEXP0130 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
|
236 | 259 |
|
|
0 commit comments