Skip to content

Commit 86b25a8

Browse files
Copilotstephentoub
andcommitted
Use static readonly field for shared empty Kernel instance
Co-authored-by: stephentoub <[email protected]>
1 parent 9a3d5bf commit 86b25a8

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

dotnet/src/Connectors/Connectors.Google/GeminiPromptExecutionSettings.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,11 @@ public static GeminiPromptExecutionSettings FromExecutionSettings(PromptExecutio
381381
return settings;
382382
}
383383

384+
/// <summary>
385+
/// Shared empty kernel instance used for FunctionChoiceBehavior conversion.
386+
/// </summary>
387+
private static readonly Kernel s_emptyKernel = new();
388+
384389
/// <summary>
385390
/// Converts a <see cref="FunctionChoiceBehavior"/> to a <see cref="GeminiToolCallBehavior"/>.
386391
/// </summary>
@@ -393,20 +398,14 @@ public static GeminiPromptExecutionSettings FromExecutionSettings(PromptExecutio
393398
return null;
394399
}
395400

396-
// Static empty kernel to avoid creating new instances for each conversion
397-
static Kernel GetEmptyKernel()
398-
{
399-
return new Kernel();
400-
}
401-
402401
// Check the type and determine auto-invoke by reflection or known behavior types
403402
// All FunctionChoiceBehavior types (Auto, Required, None) support auto-invoke
404403
// We use a simple approach: get the configuration with minimal context to check AutoInvoke
405404
try
406405
{
407406
var context = new FunctionChoiceBehaviorConfigurationContext(new ChatHistory())
408407
{
409-
Kernel = GetEmptyKernel(), // Provide an empty kernel for the configuration
408+
Kernel = s_emptyKernel, // Provide an empty kernel for the configuration
410409
RequestSequenceIndex = 0
411410
};
412411
var config = functionChoiceBehavior.GetConfiguration(context);

0 commit comments

Comments
 (0)