Table of Contents

Class AddPluginExtensions

Namespace
SemanticPluginForge
Assembly
SemanticPluginForge.Core.dll

Extension methods for adding plugins to the plugin collection.

public static class AddPluginExtensions
Inheritance
AddPluginExtensions
Inherited Members

Methods

AddFromClrObjectWithMetadata(IKernelBuilderPlugins, object, string)

Creates a plugin that wraps the specified target object and updates any metadata that it can find using IPluginMetadataProvider and adds it into the plugin collection.

public static IKernelBuilderPlugins AddFromClrObjectWithMetadata(this IKernelBuilderPlugins plugins, object target, string pluginName)

Parameters

plugins IKernelBuilderPlugins

The plugin collection to which the new plugin should be added.

target object

The instance of the class to be wrapped.

pluginName string

Name of the plugin for function collection.

Returns

IKernelBuilderPlugins

A Microsoft.SemanticKernel.KernelPlugin containing Microsoft.SemanticKernel.KernelFunctions for all relevant members of target.

Remarks

Methods that have the metadata defined using IPluginMetadataProvider will be included in the plugin.

AddFromClrObjectWithMetadata(ICollection<KernelPlugin>, object, IServiceProvider, string)

Creates a plugin that wraps the specified target object and updates any metadata that it can find using IPluginMetadataProvider and adds it into the plugin collection.

public static KernelPlugin AddFromClrObjectWithMetadata(this ICollection<KernelPlugin> plugins, object target, IServiceProvider serviceProvider, string pluginName)

Parameters

plugins ICollection<KernelPlugin>

The plugin collection to which the new plugin should be added.

target object

The instance of the class to be wrapped.

serviceProvider IServiceProvider

Service provider from which to resolve dependencies, such as Microsoft.Extensions.Logging.ILoggerFactory.

pluginName string

Name of the plugin for function collection.

Returns

KernelPlugin

A Microsoft.SemanticKernel.KernelPlugin containing Microsoft.SemanticKernel.KernelFunctions for all relevant members of target.

Remarks

Methods that have the metadata defined using IPluginMetadataProvider will be included in the plugin.

AddFromClrTypeWithMetadata<T>(IKernelBuilderPlugins, string)

Creates a plugin that wraps a new instance of the specified type T and updates any metadata that it can find using IPluginMetadataProvider and adds it into the plugin collection.

public static IKernelBuilderPlugins AddFromClrTypeWithMetadata<T>(this IKernelBuilderPlugins plugins, string pluginName)

Parameters

plugins IKernelBuilderPlugins

The plugin collection to which the new plugin should be added.

pluginName string

Name of the plugin for function collection.

Returns

IKernelBuilderPlugins

A Microsoft.SemanticKernel.KernelPlugin containing Microsoft.SemanticKernel.KernelFunctions for all relevant members of target.

Type Parameters

T

Specifies the type of the object to wrap.

Remarks

Methods that have the metadata defined using IPluginMetadataProvider will be included in the plugin.

AddFromClrTypeWithMetadata<T>(ICollection<KernelPlugin>, IServiceProvider, string)

Creates a plugin that wraps a new instance of the specified type T and updates any metadata that it can find using IPluginMetadataProvider and adds it into the plugin collection.

public static KernelPlugin AddFromClrTypeWithMetadata<T>(this ICollection<KernelPlugin> plugins, IServiceProvider serviceProvider, string pluginName)

Parameters

plugins ICollection<KernelPlugin>

The plugin collection to which the new plugin should be added.

serviceProvider IServiceProvider

Service provider from which to resolve dependencies, such as Microsoft.Extensions.Logging.ILoggerFactory.

pluginName string

Name of the plugin for function collection.

Returns

KernelPlugin

A Microsoft.SemanticKernel.KernelPlugin containing Microsoft.SemanticKernel.KernelFunctions for all relevant members of target.

Type Parameters

T

Specifies the type of the object to wrap.

Remarks

Methods that have the metadata defined using IPluginMetadataProvider will be included in the plugin.

AddFromFunctionsWithMetadata(IKernelBuilderPlugins, string, IEnumerable<KernelFunction>?)

Creates a plugin that wraps the specified functions and updates any metadata that it can find using IPluginMetadataProvider and adds it into the plugin collection.

public static IKernelBuilderPlugins AddFromFunctionsWithMetadata(this IKernelBuilderPlugins plugins, string pluginName, IEnumerable<KernelFunction>? functions)

Parameters

plugins IKernelBuilderPlugins

The plugin collection to which the new plugin should be added.

pluginName string

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 target.

functions IEnumerable<KernelFunction>

The initial functions to be available as part of the plugin.

Returns

IKernelBuilderPlugins

The same instance as plugins

Remarks

Methods that have the Microsoft.SemanticKernel.KernelFunctionAttribute attribute will be included in the plugin. See Microsoft.SemanticKernel.KernelFunctionAttribute attribute for details.

AddFromFunctionsWithMetadata(ICollection<KernelPlugin>, IServiceProvider, string, IEnumerable<KernelFunction>?)

Creates a plugin that wraps the specified functions and updates any metadata that it can find using IPluginMetadataProvider and adds it into the plugin collection.

public static KernelPlugin AddFromFunctionsWithMetadata(this ICollection<KernelPlugin> plugins, IServiceProvider serviceProvider, string pluginName, IEnumerable<KernelFunction>? functions)

Parameters

plugins ICollection<KernelPlugin>

The plugin collection to which the new plugin should be added.

serviceProvider IServiceProvider

Service provider from which to resolve dependencies, such as Microsoft.Extensions.Logging.ILoggerFactory.

pluginName string

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 target.

functions IEnumerable<KernelFunction>

The initial functions to be available as part of the plugin.

Returns

KernelPlugin

A Microsoft.SemanticKernel.KernelPlugin containing Microsoft.SemanticKernel.KernelFunctions for all relevant members of target.

Remarks

Methods that have the Microsoft.SemanticKernel.KernelFunctionAttribute attribute will be included in the plugin. See Microsoft.SemanticKernel.KernelFunctionAttribute attribute for details.

AddFromObjectWithMetadata(IKernelBuilderPlugins, object, string?)

Creates a plugin that wraps the specified target object and updates any metadata that it can find using IPluginMetadataProvider and adds it into the plugin collection.

public static IKernelBuilderPlugins AddFromObjectWithMetadata(this IKernelBuilderPlugins plugins, object target, string? pluginName = null)

Parameters

plugins IKernelBuilderPlugins

The plugin collection to which the new plugin should be added.

target object

The instance of the class to be wrapped.

pluginName string

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 target.

Returns

IKernelBuilderPlugins

The same instance as plugins

Remarks

Methods that have the Microsoft.SemanticKernel.KernelFunctionAttribute attribute will be included in the plugin. See Microsoft.SemanticKernel.KernelFunctionAttribute attribute for details.

AddFromObjectWithMetadata(ICollection<KernelPlugin>, object, IServiceProvider, string?)

Creates a plugin that wraps the specified target object and updates any metadata that it can find using IPluginMetadataProvider and adds it into the plugin collection.

public static KernelPlugin AddFromObjectWithMetadata(this ICollection<KernelPlugin> plugins, object target, IServiceProvider serviceProvider, string? pluginName = null)

Parameters

plugins ICollection<KernelPlugin>

The plugin collection to which the new plugin should be added.

target object

The instance of the class to be wrapped.

serviceProvider IServiceProvider

Service provider from which to resolve dependencies, such as Microsoft.Extensions.Logging.ILoggerFactory.

pluginName string

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 target.

Returns

KernelPlugin

A Microsoft.SemanticKernel.KernelPlugin containing Microsoft.SemanticKernel.KernelFunctions for all relevant members of target.

Remarks

Methods that have the Microsoft.SemanticKernel.KernelFunctionAttribute attribute will be included in the plugin. See Microsoft.SemanticKernel.KernelFunctionAttribute attribute for details.

AddFromOpenApiWithMetadataAsync(Kernel, string, Stream, OpenApiFunctionExecutionParameters?, CancellationToken)

Creates a plugin from an OpenAPI definition stream, updates its metadata, and adds it to the kernel's plugin collection.

public static Task<KernelPlugin> AddFromOpenApiWithMetadataAsync(this Kernel kernel, string pluginName, Stream stream, OpenApiFunctionExecutionParameters? executionParameters = null, CancellationToken cancellationToken = default)

Parameters

kernel Kernel

The Microsoft.SemanticKernel.Kernel containing services, plugins, and other state for use throughout the operation.

pluginName string

The name of the plugin.

stream Stream

The stream representing the OpenAPI definition.

executionParameters OpenApiFunctionExecutionParameters

Optional execution parameters for the plugin.

cancellationToken CancellationToken

A cancellation token to observe while waiting for the task to complete.

Returns

Task<KernelPlugin>

A task representing the asynchronous operation. The task result contains the added Microsoft.SemanticKernel.KernelPlugin.

AddFromOpenApiWithMetadataAsync(Kernel, string, string, OpenApiFunctionExecutionParameters?, CancellationToken)

Creates a plugin from an OpenAPI definition file, updates its metadata, and adds it to the kernel's plugin collection.

public static Task<KernelPlugin> AddFromOpenApiWithMetadataAsync(this Kernel kernel, string pluginName, string filePath, OpenApiFunctionExecutionParameters? executionParameters = null, CancellationToken cancellationToken = default)

Parameters

kernel Kernel

The Microsoft.SemanticKernel.Kernel containing services, plugins, and other state for use throughout the operation.

pluginName string

The name of the plugin.

filePath string

The file path to the OpenAPI definition file.

executionParameters OpenApiFunctionExecutionParameters

Optional execution parameters for the plugin.

cancellationToken CancellationToken

A cancellation token to observe while waiting for the task to complete.

Returns

Task<KernelPlugin>

A task representing the asynchronous operation. The task result contains the added Microsoft.SemanticKernel.KernelPlugin.

AddFromOpenApiWithMetadataAsync(Kernel, string, Uri, OpenApiFunctionExecutionParameters?, CancellationToken)

Creates a plugin from an OpenAPI definition URI, updates its metadata, and adds it to the kernel's plugin collection.

public static Task<KernelPlugin> AddFromOpenApiWithMetadataAsync(this Kernel kernel, string pluginName, Uri uri, OpenApiFunctionExecutionParameters? executionParameters = null, CancellationToken cancellationToken = default)

Parameters

kernel Kernel

The Microsoft.SemanticKernel.Kernel containing services, plugins, and other state for use throughout the operation.

pluginName string

The name of the plugin.

uri Uri

The URI to the OpenAPI definition.

executionParameters OpenApiFunctionExecutionParameters

Optional execution parameters for the plugin.

cancellationToken CancellationToken

A cancellation token to observe while waiting for the task to complete.

Returns

Task<KernelPlugin>

A task representing the asynchronous operation. The task result contains the added Microsoft.SemanticKernel.KernelPlugin.

AddFromTypeWithMetadata<T>(IKernelBuilderPlugins, string?)

Creates a plugin that wraps a new instance of the specified type T and updates any metadata that it can find using IPluginMetadataProvider and adds it into the plugin collection.

public static IKernelBuilderPlugins AddFromTypeWithMetadata<T>(this IKernelBuilderPlugins plugins, string? pluginName = null)

Parameters

plugins IKernelBuilderPlugins

The plugin collection to which the new plugin should be added.

pluginName string

Name of the plugin for function collection and prompt templates. If the value is null, a plugin name is derived from the type of T.

Returns

IKernelBuilderPlugins

The same instance as plugins

Type Parameters

T

Specifies the type of the object to wrap.

Remarks

Methods that have the Microsoft.SemanticKernel.KernelFunctionAttribute attribute will be included in the plugin. See Microsoft.SemanticKernel.KernelFunctionAttribute attribute for details.

AddFromTypeWithMetadata<T>(ICollection<KernelPlugin>, IServiceProvider, string?)

Creates a plugin that wraps a new instance of the specified type T and updates any metadata that it can find using IPluginMetadataProvider and adds it into the plugin collection.

public static KernelPlugin AddFromTypeWithMetadata<T>(this ICollection<KernelPlugin> plugins, IServiceProvider serviceProvider, string? pluginName = null)

Parameters

plugins ICollection<KernelPlugin>

The plugin collection to which the new plugin should be added.

serviceProvider IServiceProvider

Service provider from which to resolve dependencies, such as Microsoft.Extensions.Logging.ILoggerFactory.

pluginName string

Name of the plugin for function collection and prompt templates. If the value is null, a plugin name is derived from the type of T.

Returns

KernelPlugin

A Microsoft.SemanticKernel.KernelPlugin containing Microsoft.SemanticKernel.KernelFunctions for all relevant members of target.

Type Parameters

T

Specifies the type of the object to wrap.

Remarks

Methods that have the Microsoft.SemanticKernel.KernelFunctionAttribute attribute will be included in the plugin. See Microsoft.SemanticKernel.KernelFunctionAttribute attribute for details.

AddPatchedKernelPluginWithMetadata(Kernel, KernelPlugin)

Adds the provided kernel plugin to the kernel's plugin collection after patching it with metadata.

public static KernelPlugin AddPatchedKernelPluginWithMetadata(this Kernel kernel, KernelPlugin kernelPlugin)

Parameters

kernel Kernel

The Microsoft.SemanticKernel.Kernel containing services, plugins, and other state for use throughout the operation.

kernelPlugin KernelPlugin

The kernel plugin to be patched and added.

Returns

KernelPlugin

The patched and added Microsoft.SemanticKernel.KernelPlugin.

PatchKernelPluginWithMetadata(IServiceProvider, KernelPlugin)

Using the IPluginMetadataProvider if there are any updates to the plugin, creates a new plugin or returns the same instance.

public static KernelPlugin PatchKernelPluginWithMetadata(this IServiceProvider serviceProvider, KernelPlugin plugin)

Parameters

serviceProvider IServiceProvider

Service provider from which to resolve dependencies, such as IPluginMetadataProvider.

plugin KernelPlugin

A Microsoft.SemanticKernel.KernelPlugin containing the original functions wrapped.

Returns

KernelPlugin

A new instance of Microsoft.SemanticKernel.KernelPlugin if any change was needed in the plugin otherwise the same instance is returned.