diff --git a/dotnet/samples/KernelSyntaxExamples/Example59_OpenAIFunctionCalling.cs b/dotnet/samples/KernelSyntaxExamples/Example59_OpenAIFunctionCalling.cs
index 4b4089e82b88..6f628085f3f4 100644
--- a/dotnet/samples/KernelSyntaxExamples/Example59_OpenAIFunctionCalling.cs
+++ b/dotnet/samples/KernelSyntaxExamples/Example59_OpenAIFunctionCalling.cs
@@ -29,7 +29,7 @@ public static async Task RunAsync()
Kernel kernel = builder.Build();
// Add a plugin with some helper functions we want to allow the model to utilize.
- kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("HelperFunctions", new[]
+ kernel.ImportPluginFromFunctions("HelperFunctions", new[]
{
kernel.CreateFunctionFromMethod(() => DateTime.UtcNow.ToString("R"), "GetCurrentUtcTime", "Retrieves the current time in UTC."),
kernel.CreateFunctionFromMethod((string cityName) =>
@@ -44,7 +44,7 @@ public static async Task RunAsync()
"Tel Aviv" => "80 and sunny",
_ => "31 and snowing",
}, "Get_Weather_For_City", "Gets the current weather for the specified city"),
- }));
+ });
Console.WriteLine("======== Example 1: Use automated function calling with a non-streaming prompt ========");
{
diff --git a/dotnet/src/Experimental/Agents.UnitTests/Extensions/KernelExtensionTests.cs b/dotnet/src/Experimental/Agents.UnitTests/Extensions/KernelExtensionTests.cs
index 7784674725ca..c117be28577a 100644
--- a/dotnet/src/Experimental/Agents.UnitTests/Extensions/KernelExtensionTests.cs
+++ b/dotnet/src/Experimental/Agents.UnitTests/Extensions/KernelExtensionTests.cs
@@ -20,7 +20,7 @@ public static void InvokeTwoPartTool()
var function = KernelFunctionFactory.CreateFromMethod(() => { }, functionName: "Bogus");
var kernel = new Kernel();
- kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("Fake", "Fake functions", new[] { function }));
+ kernel.ImportPluginFromFunctions("Fake", new[] { function });
//Act
var tool = kernel.GetAssistantTool(TwoPartToolName);
diff --git a/dotnet/src/SemanticKernel.Core/KernelExtensions.cs b/dotnet/src/SemanticKernel.Core/KernelExtensions.cs
index 5398157a62da..b44ab9a6f2dc 100644
--- a/dotnet/src/SemanticKernel.Core/KernelExtensions.cs
+++ b/dotnet/src/SemanticKernel.Core/KernelExtensions.cs
@@ -169,6 +169,37 @@ public static KernelPlugin CreatePluginFromObject(this Kernel kernel, object tar
}
#endregion
+ #region CreatePluginFromFunctions
+ /// Creates a plugin that contains the specified functions.
+ /// The containing services, plugins, and other state for use throughout the operation.
+ /// The name for the plugin.
+ /// The initial functions to be available as part of the plugin.
+ /// A containing the functions provided in .
+ /// is null.
+ /// is an invalid plugin name.
+ /// contains a null function.
+ /// contains two functions with the same name.
+ public static KernelPlugin CreatePluginFromFunctions(this Kernel kernel, string pluginName, IEnumerable? functions) =>
+ CreatePluginFromFunctions(kernel, pluginName, description: null, functions);
+
+ /// Creates a plugin that contains the specified functions.
+ /// The containing services, plugins, and other state for use throughout the operation.
+ /// The name for the plugin.
+ /// A description of the plugin.
+ /// The initial functions to be available as part of the plugin.
+ /// A containing the functions provided in .
+ /// is null.
+ /// is an invalid plugin name.
+ /// contains a null function.
+ /// contains two functions with the same name.
+ public static KernelPlugin CreatePluginFromFunctions(this Kernel kernel, string pluginName, string? description = null, IEnumerable? functions = null)
+ {
+ Verify.NotNull(kernel);
+
+ return KernelPluginFactory.CreateFromFunctions(pluginName, description, functions);
+ }
+ #endregion
+
#region ImportPlugin/AddFromType
/// Creates a plugin that wraps a new instance of the specified type and imports it into the 's plugin collection.
/// Specifies the type of the object to wrap.
@@ -279,6 +310,68 @@ public static KernelPlugin AddFromObject(this ICollection plugins,
return plugin;
}
+ /// Creates a plugin that wraps the specified target object and adds it into the plugin collection.
+ /// The plugin collection to which the new plugin should be added.
+ /// The instance of the class to be wrapped.
+ ///
+ /// Name of the plugin for function collection and prompt templates. If the value is null, a plugin name is derived from the type of the .
+ ///
+ /// The same instance as .
+ ///
+ /// Public methods that have the attribute will be included in the plugin.
+ ///
+ public static IKernelBuilderPlugins AddFromObject(this IKernelBuilderPlugins plugins, object target, string? pluginName = null)
+ {
+ Verify.NotNull(plugins);
+
+ plugins.Services.AddSingleton(serviceProvider => KernelPluginFactory.CreateFromObject(target, pluginName, serviceProvider?.GetService()));
+
+ return plugins;
+ }
+ #endregion
+
+ #region ImportPlugin/AddFromFunctions
+ /// Creates a plugin that contains the specified functions and imports it into the 's plugin collection.
+ /// The containing services, plugins, and other state for use throughout the operation.
+ /// The name for the plugin.
+ /// The initial functions to be available as part of the plugin.
+ /// A containing the functions provided in .
+ /// is null.
+ /// is an invalid plugin name.
+ /// contains a null function.
+ /// contains two functions with the same name.
+ public static KernelPlugin ImportPluginFromFunctions(this Kernel kernel, string pluginName, IEnumerable? functions) =>
+ ImportPluginFromFunctions(kernel, pluginName, description: null, functions);
+
+ /// Creates a plugin that contains the specified functions and imports it into the 's plugin collection.
+ /// The containing services, plugins, and other state for use throughout the operation.
+ /// The name for the plugin.
+ /// A description of the plugin.
+ /// The initial functions to be available as part of the plugin.
+ /// A containing the functions provided in .
+ /// is null.
+ /// is an invalid plugin name.
+ /// contains a null function.
+ /// contains two functions with the same name.
+ public static KernelPlugin ImportPluginFromFunctions(this Kernel kernel, string pluginName, string? description = null, IEnumerable? functions = null)
+ {
+ KernelPlugin plugin = CreatePluginFromFunctions(kernel, pluginName, description, functions);
+ kernel.Plugins.Add(plugin);
+ return plugin;
+ }
+
+ /// Creates a plugin that contains the specified functions and adds it into the plugin collection.
+ /// The plugin collection to which the new plugin should be added.
+ /// The name for the plugin.
+ /// The initial functions to be available as part of the plugin.
+ /// A containing the functions provided in .
+ /// is null.
+ /// is an invalid plugin name.
+ /// contains a null function.
+ /// contains two functions with the same name.
+ public static KernelPlugin AddFromFunctions(this ICollection plugins, string pluginName, IEnumerable? functions) =>
+ AddFromFunctions(plugins, pluginName, description: null, functions);
+
/// Creates a plugin that contains the specified functions and adds it into the plugin collection.
/// The plugin collection to which the new plugin should be added.
/// The name for the plugin.
@@ -289,7 +382,7 @@ public static KernelPlugin AddFromObject(this ICollection plugins,
/// is an invalid plugin name.
/// contains a null function.
/// contains two functions with the same name.
- public static KernelPlugin AddFromFunctions(this ICollection plugins, string pluginName, string? description, IEnumerable? functions = null)
+ public static KernelPlugin AddFromFunctions(this ICollection plugins, string pluginName, string? description = null, IEnumerable? functions = null)
{
Verify.NotNull(plugins);
@@ -300,19 +393,31 @@ public static KernelPlugin AddFromFunctions(this ICollection plugi
/// Creates a plugin that wraps the specified target object and adds it into the plugin collection.
/// The plugin collection to which the new plugin should be added.
- /// The instance of the class to be wrapped.
- ///
- /// Name of the plugin for function collection and prompt templates. If the value is null, a plugin name is derived from the type of the .
- ///
+ /// The name for the plugin.
+ /// The initial functions to be available as part of the plugin.
/// The same instance as .
- ///
- /// Public methods that have the attribute will be included in the plugin.
- ///
- public static IKernelBuilderPlugins AddFromObject(this IKernelBuilderPlugins plugins, object target, string? pluginName = null)
+ /// is null.
+ /// is an invalid plugin name.
+ /// contains a null function.
+ /// contains two functions with the same name.
+ public static IKernelBuilderPlugins AddFromFunctions(this IKernelBuilderPlugins plugins, string pluginName, IEnumerable? functions) =>
+ AddFromFunctions(plugins, pluginName, description: null, functions);
+
+ /// Creates a plugin that wraps the specified target object and adds it into the plugin collection.
+ /// The plugin collection to which the new plugin should be added.
+ /// The name for the plugin.
+ /// A description of the plugin.
+ /// The initial functions to be available as part of the plugin.
+ /// The same instance as .
+ /// is null.
+ /// is an invalid plugin name.
+ /// contains a null function.
+ /// contains two functions with the same name.
+ public static IKernelBuilderPlugins AddFromFunctions(this IKernelBuilderPlugins plugins, string pluginName, string? description = null, IEnumerable? functions = null)
{
Verify.NotNull(plugins);
- plugins.Services.AddSingleton(serviceProvider => KernelPluginFactory.CreateFromObject(target, pluginName, serviceProvider?.GetService()));
+ plugins.Services.AddSingleton(KernelPluginFactory.CreateFromFunctions(pluginName, description, functions));
return plugins;
}
diff --git a/dotnet/src/SemanticKernel.UnitTests/Functions/KernelExtensionsTests.cs b/dotnet/src/SemanticKernel.UnitTests/Functions/KernelExtensionsTests.cs
new file mode 100644
index 000000000000..915c49e90712
--- /dev/null
+++ b/dotnet/src/SemanticKernel.UnitTests/Functions/KernelExtensionsTests.cs
@@ -0,0 +1,159 @@
+// Copyright (c) Microsoft. All rights reserved.
+
+using Microsoft.SemanticKernel;
+using Xunit;
+
+namespace SemanticKernel.UnitTests.Functions;
+
+public class KernelExtensionsTests
+{
+ [Fact]
+ public void CreatePluginFromFunctions()
+ {
+ Kernel kernel = new();
+
+ KernelPlugin plugin = kernel.CreatePluginFromFunctions("coolplugin", new[]
+ {
+ kernel.CreateFunctionFromMethod(() => { }, "Function1"),
+ kernel.CreateFunctionFromMethod(() => { }, "Function2"),
+ });
+
+ Assert.NotNull(plugin);
+ Assert.Empty(kernel.Plugins);
+
+ Assert.Equal("coolplugin", plugin.Name);
+ Assert.Empty(plugin.Description);
+ Assert.Equal(2, plugin.FunctionCount);
+ Assert.True(plugin.Contains("Function1"));
+ Assert.True(plugin.Contains("Function2"));
+ }
+
+ [Fact]
+ public void CreateEmptyPluginFromFunctions()
+ {
+ Kernel kernel = new();
+
+ KernelPlugin plugin = kernel.CreatePluginFromFunctions("coolplugin");
+
+ Assert.NotNull(plugin);
+ Assert.Empty(kernel.Plugins);
+
+ Assert.Equal("coolplugin", plugin.Name);
+ Assert.Empty(plugin.Description);
+ Assert.Empty(plugin);
+ Assert.Equal(0, plugin.FunctionCount);
+ }
+
+ [Fact]
+ public void CreatePluginFromDescriptionAndFunctions()
+ {
+ Kernel kernel = new();
+
+ KernelPlugin plugin = kernel.CreatePluginFromFunctions("coolplugin", "the description", new[]
+ {
+ kernel.CreateFunctionFromMethod(() => { }, "Function1"),
+ kernel.CreateFunctionFromMethod(() => { }, "Function2"),
+ });
+
+ Assert.NotNull(plugin);
+ Assert.Empty(kernel.Plugins);
+
+ Assert.Equal("coolplugin", plugin.Name);
+ Assert.Equal("the description", plugin.Description);
+ Assert.Equal(2, plugin.FunctionCount);
+ Assert.True(plugin.Contains("Function1"));
+ Assert.True(plugin.Contains("Function2"));
+ }
+
+ [Fact]
+ public void ImportPluginFromFunctions()
+ {
+ Kernel kernel = new();
+
+ kernel.ImportPluginFromFunctions("coolplugin", new[]
+ {
+ kernel.CreateFunctionFromMethod(() => { }, "Function1"),
+ kernel.CreateFunctionFromMethod(() => { }, "Function2"),
+ });
+
+ Assert.Single(kernel.Plugins);
+
+ KernelPlugin plugin = kernel.Plugins["coolplugin"];
+ Assert.Equal("coolplugin", plugin.Name);
+ Assert.Empty(plugin.Description);
+ Assert.NotNull(plugin);
+
+ Assert.Equal(2, plugin.FunctionCount);
+ Assert.True(plugin.Contains("Function1"));
+ Assert.True(plugin.Contains("Function2"));
+ }
+
+ [Fact]
+ public void ImportPluginFromDescriptionAndFunctions()
+ {
+ Kernel kernel = new();
+
+ kernel.ImportPluginFromFunctions("coolplugin", "the description", new[]
+ {
+ kernel.CreateFunctionFromMethod(() => { }, "Function1"),
+ kernel.CreateFunctionFromMethod(() => { }, "Function2"),
+ });
+
+ Assert.Single(kernel.Plugins);
+
+ KernelPlugin plugin = kernel.Plugins["coolplugin"];
+ Assert.Equal("coolplugin", plugin.Name);
+ Assert.Equal("the description", plugin.Description);
+ Assert.NotNull(plugin);
+
+ Assert.Equal(2, plugin.FunctionCount);
+ Assert.True(plugin.Contains("Function1"));
+ Assert.True(plugin.Contains("Function2"));
+ }
+
+ [Fact]
+ public void AddFromFunctions()
+ {
+ Kernel kernel = new();
+
+ kernel.Plugins.AddFromFunctions("coolplugin", new[]
+ {
+ kernel.CreateFunctionFromMethod(() => { }, "Function1"),
+ kernel.CreateFunctionFromMethod(() => { }, "Function2"),
+ });
+
+ Assert.Single(kernel.Plugins);
+
+ KernelPlugin plugin = kernel.Plugins["coolplugin"];
+ Assert.Equal("coolplugin", plugin.Name);
+ Assert.Empty(plugin.Description);
+ Assert.NotNull(plugin);
+
+ Assert.Equal(2, plugin.FunctionCount);
+ Assert.True(plugin.Contains("Function1"));
+ Assert.True(plugin.Contains("Function2"));
+ }
+
+ [Fact]
+ public void AddFromDescriptionAndFunctions()
+ {
+ Kernel kernel = new();
+
+ kernel.Plugins.AddFromFunctions("coolplugin", "the description", new[]
+ {
+ kernel.CreateFunctionFromMethod(() => { }, "Function1"),
+ kernel.CreateFunctionFromMethod(() => { }, "Function2"),
+ });
+
+ Assert.Single(kernel.Plugins);
+
+ KernelPlugin plugin = kernel.Plugins["coolplugin"];
+ Assert.Equal("coolplugin", plugin.Name);
+ Assert.Equal("the description", plugin.Description);
+ Assert.NotNull(plugin);
+
+ Assert.Equal(2, plugin.FunctionCount);
+ Assert.True(plugin.Contains("Function1"));
+ Assert.True(plugin.Contains("Function2"));
+ }
+}
diff --git a/dotnet/src/SemanticKernel.UnitTests/Functions/KernelFunctionFromPromptTests.cs b/dotnet/src/SemanticKernel.UnitTests/Functions/KernelFunctionFromPromptTests.cs
index ffe46715640b..a0239238194c 100644
--- a/dotnet/src/SemanticKernel.UnitTests/Functions/KernelFunctionFromPromptTests.cs
+++ b/dotnet/src/SemanticKernel.UnitTests/Functions/KernelFunctionFromPromptTests.cs
@@ -48,7 +48,7 @@ public void ItProvidesAccessToFunctionsViaFunctionCollection()
builder.Services.AddSingleton(factory.Object);
Kernel kernel = builder.Build();
- kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("jk", functions: new[] { kernel.CreateFunctionFromPrompt(promptTemplate: "Tell me a joke", functionName: "joker", description: "Nice fun") }));
+ kernel.ImportPluginFromFunctions("jk", functions: new[] { kernel.CreateFunctionFromPrompt(promptTemplate: "Tell me a joke", functionName: "joker", description: "Nice fun") });
// Act & Assert - 3 functions, var name is not case sensitive
Assert.True(kernel.Plugins.TryGetFunction("jk", "joker", out _));
@@ -573,7 +573,7 @@ public async Task InvokeAsyncWithNestedPromptsSelectsCorrectServiceAsync()
KernelFunction function1 = KernelFunctionFactory.CreateFromPrompt(new PromptTemplateConfig { Name = "Prompt1", Template = "Prompt1", ExecutionSettings = new() { ["service1"] = new OpenAIPromptExecutionSettings { MaxTokens = 1000 } } });
KernelFunction function2 = KernelFunctionFactory.CreateFromPrompt(new PromptTemplateConfig { Name = "Prompt2", Template = "Prompt2 {{MyPrompts.Prompt1}}", ExecutionSettings = new() { ["service2"] = new OpenAIPromptExecutionSettings { MaxTokens = 2000 } } });
- kernel.Plugins.AddFromFunctions("MyPrompts", "Prompt1 and Prompt2", new[] { function1, function2 });
+ kernel.ImportPluginFromFunctions("MyPrompts", new[] { function1, function2 });
// Act
var result = await kernel.InvokeAsync(function2);
diff --git a/dotnet/src/SemanticKernel.UnitTests/KernelTests.cs b/dotnet/src/SemanticKernel.UnitTests/KernelTests.cs
index 283eb4f1847f..0c75474ffcb5 100644
--- a/dotnet/src/SemanticKernel.UnitTests/KernelTests.cs
+++ b/dotnet/src/SemanticKernel.UnitTests/KernelTests.cs
@@ -503,7 +503,7 @@ public async Task ItCanFindAndRunFunctionAsync()
var function = KernelFunctionFactory.CreateFromMethod(() => "fake result", "function");
var kernel = new Kernel();
- kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("plugin", "description", new[] { function }));
+ kernel.ImportPluginFromFunctions("plugin", new[] { function });
//Act
var result = await kernel.InvokeAsync("plugin", "function");
diff --git a/dotnet/src/SemanticKernel.UnitTests/PromptTemplate/KernelPromptTemplateTests.cs b/dotnet/src/SemanticKernel.UnitTests/PromptTemplate/KernelPromptTemplateTests.cs
index bbcf093b4f89..4a36104b7d3e 100644
--- a/dotnet/src/SemanticKernel.UnitTests/PromptTemplate/KernelPromptTemplateTests.cs
+++ b/dotnet/src/SemanticKernel.UnitTests/PromptTemplate/KernelPromptTemplateTests.cs
@@ -106,11 +106,11 @@ public async Task ItRendersVariablesValuesAndFunctionsAsync()
// Arrange
var template = "This {{$x11}} {{$a}}{{$missing}} test template {{p.bar $b}} and {{p.food c='literal \"c\"' d = $d}}";
- this._kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("p", "description", new[]
+ this._kernel.ImportPluginFromFunctions("p", new[]
{
KernelFunctionFactory.CreateFromMethod((string input) => "with function that accepts " + input, "bar"),
KernelFunctionFactory.CreateFromMethod((string c, string d) => "another one with " + c + d, "food"),
- }));
+ });
var target = (KernelPromptTemplate)this._factory.Create(new PromptTemplateConfig(template));
@@ -186,7 +186,7 @@ void Foo(string input)
canary = input;
}
- this._kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("p", "description", new[] { KernelFunctionFactory.CreateFromMethod(Foo, "bar") }));
+ this._kernel.ImportPluginFromFunctions("p", new[] { KernelFunctionFactory.CreateFromMethod(Foo, "bar") });
var template = "This is a test template that references variable that does not have argument. {{p.bar $foo}}.";
@@ -210,7 +210,7 @@ void Foo(string input)
canary = input;
}
- this._kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("p", "description", new[] { KernelFunctionFactory.CreateFromMethod(Foo, "bar") }));
+ this._kernel.ImportPluginFromFunctions("p", new[] { KernelFunctionFactory.CreateFromMethod(Foo, "bar") });
var template = "This is a test template that references variable that have null argument{{p.bar $foo}}.";
@@ -236,7 +236,7 @@ void Foo(string input)
canary = input;
}
- this._kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("p", "description", new[] { KernelFunctionFactory.CreateFromMethod(Foo, "bar") }));
+ this._kernel.ImportPluginFromFunctions("p", new[] { KernelFunctionFactory.CreateFromMethod(Foo, "bar") });
var template = "This is a test template that {{$zoo}}references variables that have null arguments{{p.bar $foo}}.";
@@ -265,7 +265,7 @@ void Foo(string input)
canary = input;
}
- this._kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("p", "description", new[] { KernelFunctionFactory.CreateFromMethod(Foo, "bar") }));
+ this._kernel.ImportPluginFromFunctions("p", new[] { KernelFunctionFactory.CreateFromMethod(Foo, "bar") });
var template = "This is a test template that {{$zoo}}references variables that do not have arguments{{p.bar $foo}}.";
@@ -292,7 +292,7 @@ string MyFunctionAsync(string input)
var func = KernelFunctionFactory.CreateFromMethod(MyFunctionAsync, "function");
- this._kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("plugin", "description", new[] { func }));
+ this._kernel.ImportPluginFromFunctions("plugin", new[] { func });
this._arguments[InputParameterName] = "INPUT-BAR";
@@ -318,7 +318,7 @@ string MyFunctionAsync(string input)
var func = KernelFunctionFactory.CreateFromMethod(MyFunctionAsync, "function");
- this._kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("plugin", "description", new[] { func }));
+ this._kernel.ImportPluginFromFunctions("plugin", new[] { func });
this._arguments["myVar"] = "BAR";
var template = "foo-{{plugin.function $myVar}}-baz";
@@ -348,7 +348,7 @@ string MyFunctionAsync(
var func = KernelFunctionFactory.CreateFromMethod(MyFunctionAsync, "function");
- this._kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("plugin", "description", new[] { func }));
+ this._kernel.ImportPluginFromFunctions("plugin", new[] { func });
this._arguments[InputParameterName] = "Mario";
this._arguments["someDate"] = "2023-08-25T00:00:00";
@@ -395,7 +395,7 @@ string MyFunctionAsync(
KernelFunction func = KernelFunctionFactory.CreateFromMethod(MyFunctionAsync, "function");
- this._kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("plugin", "description", new[] { func }));
+ this._kernel.ImportPluginFromFunctions("plugin", new[] { func });
this._arguments[InputParameterName] = "Mario";
this._arguments["someDate"] = "2023-08-25T00:00:00";
@@ -461,7 +461,7 @@ Task MyFunctionAsync(string input)
KernelFunction func = KernelFunctionFactory.CreateFromMethod(MyFunctionAsync, "function");
- this._kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("plugin", "description", new[] { func }));
+ this._kernel.ImportPluginFromFunctions("plugin", new[] { func });
this._arguments["myVar"] = "BAR";
@@ -497,7 +497,7 @@ public async Task RenderVarValuesFunctionWithDiffArgTypesAsync()
"f");
this._kernel.Culture = new CultureInfo("fr-FR"); //In French culture, a comma is used as a decimal separator, and a slash is used as a date separator. See the Assert below.
- this._kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("p", "description", new[] { func }));
+ this._kernel.ImportPluginFromFunctions("p", new[] { func });
var template = "int:{{$i}}, double:{{$d}}, {{p.f $s g=$g}}, DateTime:{{$dt}}, enum:{{$e}}";
diff --git a/dotnet/src/SemanticKernel.UnitTests/TemplateEngine/Blocks/CodeBlockTests.cs b/dotnet/src/SemanticKernel.UnitTests/TemplateEngine/Blocks/CodeBlockTests.cs
index a8ed9c2ed240..b2012b15488f 100644
--- a/dotnet/src/SemanticKernel.UnitTests/TemplateEngine/Blocks/CodeBlockTests.cs
+++ b/dotnet/src/SemanticKernel.UnitTests/TemplateEngine/Blocks/CodeBlockTests.cs
@@ -34,7 +34,7 @@ public async Task ItThrowsIfAFunctionCallThrowsAsync()
static void method() => throw new FormatException("error");
var function = KernelFunctionFactory.CreateFromMethod(method, "function", "description");
- this._kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("plugin", "description", new[] { function }));
+ this._kernel.ImportPluginFromFunctions("plugin", new[] { function });
var target = new CodeBlock("plugin.function");
@@ -194,7 +194,7 @@ public async Task ItInvokesFunctionWithCustomVariableAsync()
},
"function");
- this._kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("plugin", "description", new[] { function }));
+ this._kernel.ImportPluginFromFunctions("plugin", new[] { function });
// Act
var codeBlock = new CodeBlock(new List { funcId, varBlock }, "");
@@ -222,7 +222,7 @@ public async Task ItInvokesFunctionWithCustomValueAsync()
},
"function");
- this._kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("plugin", "description", new[] { function }));
+ this._kernel.ImportPluginFromFunctions("plugin", new[] { function });
// Act
var codeBlock = new CodeBlock(new List { funcBlock, valBlock }, "");
@@ -259,7 +259,7 @@ public async Task ItInvokesFunctionWithNamedArgsAsync()
},
"function");
- this._kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("plugin", "description", new[] { function }));
+ this._kernel.ImportPluginFromFunctions("plugin", new[] { function });
// Act
var codeBlock = new CodeBlock(new List { funcId, namedArgBlock1, namedArgBlock2 }, "");
@@ -282,10 +282,10 @@ public async Task ItReturnsArgumentValueAndTypeAsync()
var varBlock = new VarBlock("$var");
var namedArgBlock = new NamedArgBlock("p1=$a1");
- this._kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("p", "description", new[] { KernelFunctionFactory.CreateFromMethod((object p1) =>
+ this._kernel.ImportPluginFromFunctions("p", new[] { KernelFunctionFactory.CreateFromMethod((object p1) =>
{
canary = p1;
- }, "f") }));
+ }, "f") });
// Act
var functionWithPositionedArgument = new CodeBlock(new List { funcId, varBlock }, "");
@@ -323,7 +323,7 @@ public async Task ItDoesNotMutateOriginalArgumentsAsync()
var function = KernelFunctionFactory.CreateFromMethod((string foo, string baz) => { }, "function");
- this._kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("plugin", "description", new[] { function }));
+ this._kernel.ImportPluginFromFunctions("plugin", new[] { function });
// Act
var codeBlock = new CodeBlock(new List { funcId, namedArgBlock1, namedArgBlock2 }, "");
@@ -363,7 +363,7 @@ public async Task ItThrowsWhenArgumentsAreProvidedToAParameterlessFunctionAsync(
var function = KernelFunctionFactory.CreateFromMethod(() => { }, "function");
- this._kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("plugin", "description", new[] { function }));
+ this._kernel.ImportPluginFromFunctions("plugin", new[] { function });
// Act
var codeBlock = new CodeBlock(blockList, "");
@@ -392,15 +392,13 @@ public async Task ItCallsPromptFunctionWithPositionalTargetFirstArgumentRegardle
new ValBlock($"'{FooValue}'")
};
- kernel.Plugins.Add(
- KernelPluginFactory.CreateFromFunctions("Plugin1", functions: new[]
+ kernel.ImportPluginFromFunctions("Plugin1", functions: new[]
{
kernel.CreateFunctionFromPrompt(
promptTemplate: $"\"This {{{{${parameterName}}}}}",
functionName: "Function1")
}
- )
- );
+ );
kernel.PromptRendering += (object? sender, PromptRenderingEventArgs e) =>
{
@@ -438,15 +436,13 @@ public async Task ItCallsPromptFunctionMatchArgumentWithNamedArgsAsync()
new NamedArgBlock("x12='new'") // Extra parameters are ignored
};
- kernel.Plugins.Add(
- KernelPluginFactory.CreateFromFunctions("Plugin1", functions: new[]
+ kernel.ImportPluginFromFunctions("Plugin1", functions: new[]
{
kernel.CreateFunctionFromPrompt(
promptTemplate: "\"This {{$x11}}",
functionName: "Function1")
}
- )
- );
+ );
kernel.PromptRendering += (object? sender, PromptRenderingEventArgs e) =>
{
@@ -490,7 +486,7 @@ public async Task ItThrowsWhenArgumentsAreAmbiguousAsync()
},
"function");
- this._kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("plugin", "description", new[] { function }));
+ this._kernel.ImportPluginFromFunctions("plugin", new[] { function });
// Act
var codeBlock = new CodeBlock(new List { funcId, namedArgBlock1, namedArgBlock2 }, "");