![]() |
VOOZH | about |
dotnet add package SemanticPluginForge.Core --version 2.1.1
NuGet\Install-Package SemanticPluginForge.Core -Version 2.1.1
<PackageReference Include="SemanticPluginForge.Core" Version="2.1.1" />
<PackageVersion Include="SemanticPluginForge.Core" Version="2.1.1" />Directory.Packages.props
<PackageReference Include="SemanticPluginForge.Core" />Project file
paket add SemanticPluginForge.Core --version 2.1.1
#r "nuget: SemanticPluginForge.Core, 2.1.1"
#:package SemanticPluginForge.Core@2.1.1
#addin nuget:?package=SemanticPluginForge.Core&version=2.1.1Install as a Cake Addin
#tool nuget:?package=SemanticPluginForge.Core&version=2.1.1Install as a Cake Tool
SemanticPluginForge adds functionality to dynamically alter the metadata for SemanticKernel plugins. This library introduces the IPluginMetadataProvider interface, allowing for real-time updates to plugin metadata, including descriptions, return value descriptions, and parameter descriptions, without the need for redeployment.
Dynamic Metadata Updates:
Extensible Architecture:
Dynamic Tuning:
Custom Metadata Providers:
To add SemanticPluginForge to your project, use the following command:
dotnet add package SemanticPluginForge.Core
Implement the IPluginMetadataProvider interface. The following code is a sample provider that overrides the description of a function from the TimePlugin.
public class CustomTimeYearMetadataProvider : IPluginMetadataProvider
{
public PluginMetadata? GetPluginMetadata(KernelPlugin plugin) => null;
public FunctionMetadata GetFunctionMetadata(KernelPlugin plugin, KernelFunctionMetadata metadata) =>
plugin.Name == "TimePlugin" && metadata.Name == "Year"
? new FunctionMetadata(metadata.Name) { Description = "Get the current year in 4-digit number format." }
: null;
}
Register the custom metadata provider with the service collection.
services.AddSingleton<IPluginMetadataProvider, CustomTimeYearMetadataProvider>();
Use the extension methods from this library to add plugins with patched metadata.
var kernelBuilder = services.AddKernel();
kernelBuilder.Plugins.AddFromTypeWithMetadata<TimePlugin>();
The library now supports suppressing functions and parameters in plugin metadata. This feature allows you to hide specific functions or parameters from the plugin's consumers while maintaining functionality. For parameters, if a default value is provided, it will be used even when the parameter is suppressed.
To suppress a function, set the Suppress property to true in the FunctionMetadata.
public class CustomMetadataProvider : IPluginMetadataProvider
{
public PluginMetadata? GetPluginMetadata(KernelPlugin plugin) => null;
public FunctionMetadata GetFunctionMetadata(KernelPlugin plugin, KernelFunctionMetadata metadata) =>
plugin.Name == "SamplePlugin" && metadata.Name == "HiddenFunction"
? new FunctionMetadata(metadata.Name) { Suppress = true }
: null;
}
To suppress a parameter, set the Suppress property to true in the ParameterMetadata. If a default value is provided, it will be used.
public class CustomMetadataProvider : IPluginMetadataProvider
{
public PluginMetadata? GetPluginMetadata(KernelPlugin plugin) => null;
public FunctionMetadata GetFunctionMetadata(KernelPlugin plugin, KernelFunctionMetadata metadata) =>
plugin.Name == "SamplePlugin" && metadata.Name == "FunctionWithHiddenParameter"
? new FunctionMetadata(metadata.Name)
{
Parameters = new List<ParameterMetadata>
{
new ParameterMetadata("hiddenParam") { Suppress = true, DefaultValue = "default" }
}
}
: null;
}
When a parameter is set to Suppress, it must either be optional or have a default value provided. This default value can be specified in the underlying implementation or through the metadata provider.
This ensures that suppressed parameters are handled gracefully without causing runtime errors.
The library allows you to use any CLR type or object as a plugin without requiring KernelFunction attribute. This enables you to create plugins from existing objects or types, making it easier to integrate with existing codebases.
When registering CLR types or objects as plugins, the library follows these rules:
Open Generic Methods: Open generic methods are filtered out and not exposed as plugin functions.
TAP Method Normalization: Methods following the Task-based Asynchronous Pattern (TAP) are normalized by:
CancellationToken parameterAsync suffix from method namesCancellationToken parameter, then method with Async suffixHandling Overloaded Methods: For methods with the same name but different parameters, you can use FunctionMetadata.OverrideFunctionName in your metadata provider to give each overload a unique name:
// Handling the Random.Next() overloads
public FunctionMetadata? GetFunctionMetadata(KernelPlugin plugin, KernelFunctionMetadata metadata)
{
return plugin.Name switch
{
"RandomPlugin" => metadata.Name switch
{
"Next" when metadata.Parameters.Count == 0 => new FunctionMetadata(metadata.Name)
{
Description = "Returns a non-negative random integer."
},
"Next" when metadata.Parameters.Count == 1 => new FunctionMetadata(metadata.Name)
{
OverrideFunctionName = "NextWithUpperBound",
Description = "Returns a random integer within a specified range.",
Parameters = [
new ParameterMetadata("maxValue")
{
Description = "The exclusive upper bound of the random number returned."
}
]
},
"Next" when metadata.Parameters.Count == 2 => new FunctionMetadata(metadata.Name)
{
OverrideFunctionName = "NextWithRange",
Description = "Returns a random integer within a specified range.",
Parameters = [
new ParameterMetadata("minValue") { Description = "The inclusive lower bound of the random number returned." },
new ParameterMetadata("maxValue") { Description = "The exclusive upper bound of the random number returned." }
]
},
_ => null
},
_ => null
};
}
Sample Type and Metadata Provider:
public class DateTimeWrapper
{
public string ToShortDateString()
{
return DateTime.Now.ToShortDateString();
}
public string ToLongDateString()
{
return DateTime.Now.ToLongDateString();
}
public string CurrentTime()
{
return DateTime.Now.ToString("T");
}
}
public class CustomMetadataProvider : IPluginMetadataProvider
{
public PluginMetadata? GetPluginMetadata(KernelPlugin plugin) =>
plugin.Name == "DateTimeWrapper" ? new PluginMetadata
{
Description = "This plugin returns date and time information."
} : null;
public FunctionMetadata? GetFunctionMetadata(KernelPlugin plugin, KernelFunctionMetadata metadata) =>
plugin.Name == "DateTimeWrapper" && metadata.Name == "ToShortDateString" ? new FunctionMetadata(metadata.Name)
{
Description = "Returns the current date in short format (MM/dd/yyyy)."
} : null;
}
Usage Example:
kernelBuilder.Plugins.AddFromClrObjectWithMetadata(new DateTimeWrapper(), "DateTimeWrapper");
Usage Example:
kernelBuilder.Plugins.AddFromClrTypeWithMetadata<DateTimeWrapper>("DateTimeWrapper");
Usage Example:
var qc = new QueueClient(new Uri("https://your-storage.queue.core.windows.net/your-queue"), new DefaultAzureCredential());
kernelBuilder.Plugins.AddFromClrObjectWithMetadata(qc, "Queue");
Explore the samples directory for practical examples of using SemanticPluginForge in different scenarios. Each sample includes comprehensive documentation, setup instructions, and focuses on specific framework concepts.
DefaultValue: Demonstrates advanced parameter handling including suppression, default values, and context-aware metadata. Shows how to override parameter descriptions and ensure parameters are never resolved from context when suppressed.
UseClrType: Shows how to use existing .NET classes as Semantic Kernel plugins without requiring KernelFunction attributes. Demonstrates multiple plugin types including custom classes, standard .NET classes like Random, and direct Azure SDK integration through QueueClient. Features function name overriding for handling method overloads.
AzureAiSearchPlugin: Comprehensive example showing how to create multiple instances of the same plugin class with different metadata configurations for various data sources. Uses mocked data for learning without external dependencies.
Navigate to the samples folder to get started with these examples.
For comprehensive documentation, API reference, and advanced usage examples, visit:
https://lsiddiquee.github.io/SemanticPluginForge/
Need help or have questions? Check out our Support Guide for information on:
Contributions are welcome! Please open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 2 NuGet packages that depend on SemanticPluginForge.Core:
| Package | Downloads |
|---|---|
|
SemanticPluginForge.OpenApi
A library for extending Semantic Kernel OpenAPI spec plugins with customizable metadata support. |
|
|
SemanticPluginForge.OpenAI
A library for extending Semantic Kernel OpenAI and OpenAPI spec plugins with customisable metadata support. |
This package is not used by any popular GitHub repositories.