Dynamically enhance your Semantic Kernel plugins with powerful metadata capabilities
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.
KernelFunction
attributesdotnet add package SemanticPluginForge.Core
public class CustomMetadataProvider : IPluginMetadataProvider
{
public PluginMetadata? GetPluginMetadata(KernelPlugin plugin) =>
plugin.Name == "TimePlugin" ? new PluginMetadata
{
Description = "Enhanced time and date operations"
} : 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 format"
}
: null;
}
// Register the metadata provider
services.AddSingleton<IPluginMetadataProvider, CustomMetadataProvider>();
// Add plugins with enhanced metadata
var kernelBuilder = services.AddKernel();
kernelBuilder.Plugins.AddFromTypeWithMetadata<TimePlugin>();
Section | Description |
---|---|
๐ฏ Getting Started | Step-by-step setup and basic usage |
๐ง Core Concepts | Understand the fundamentals |
โก Advanced Features | Suppression, CLR types, and more |
๐ Samples | Practical examples and tutorials |
๐ API Reference | Complete API documentation |
public FunctionMetadata? GetFunctionMetadata(KernelPlugin plugin, KernelFunctionMetadata metadata)
{
if (plugin.Name == "WeatherPlugin" && metadata.Name == "GetWeather")
{
return new FunctionMetadata(metadata.Name)
{
Description = "Gets weather for user's location (auto-detected)",
Parameters = new List<ParameterMetadata>
{
new ParameterMetadata("location")
{
Suppress = true,
DefaultValue = "user_current_location"
}
}
};
}
return null;
}
public class MathUtils
{
public double Add(double a, double b) => a + b;
public double Multiply(double a, double b) => a * b;
}
// No attributes needed!
kernelBuilder.Plugins.AddFromClrTypeWithMetadata<MathUtils>("MathPlugin");
return new FunctionMetadata(metadata.Name)
{
OverrideFunctionName = "CalculateSum", // Better name for AI
Description = "Adds two numbers together"
};
Explore our comprehensive samples:
Sample | Focus | Key Learning |
---|---|---|
DefaultValue | Parameter handling | Smart defaults and suppression |
UseClrType | Legacy integration | CLR types as plugins |
AzureAiSearchPlugin | Production patterns | Multiple instances, different configs |
Ready to enhance your Semantic Kernel plugins?
Contributions are welcome! Please open an issue or submit a pull request.