KernelFunctionExtension Class

Kernel function extension.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Inheritance
KernelFunctionExtension
KernelFunctionExtension

Constructor

KernelFunctionExtension(*, plugins: dict[str, KernelPlugin] = None)

Keyword-Only Parameters

Name Description
plugins
Required

Methods

add_function

Adds a function to the specified plugin.

add_functions

Adds a list of functions to the specified plugin.

add_plugin

Adds a plugin to the kernel's collection of plugins.

If a plugin is provided, it uses that instance instead of creating a new KernelPlugin. See KernelPlugin.from_directory for more details on how the directory is parsed.

add_plugin_from_openai

Add a plugin from an OpenAPI document.

add_plugin_from_openapi

Add a plugin from the OpenAPI manifest.

add_plugins

Adds a list of plugins to the kernel's collection of plugins.

get_full_list_of_function_metadata

Get a list of all function metadata in the plugins.

get_function

Get a function by plugin_name and function_name.

get_function_from_fully_qualified_function_name

Get a function by its fully qualified name (<plugin_name>-<function_name>).

get_list_of_function_metadata

Get a list of all function metadata in the plugin collection.

get_list_of_function_metadata_bool

Get a list of the function metadata in the plugin collection.

get_list_of_function_metadata_filters

Get a list of Kernel Function Metadata based on filters.

get_plugin

Get a plugin by name.

rewrite_plugins

Rewrite plugins to a dictionary.

add_function

Adds a function to the specified plugin.

add_function(plugin_name: str, function: KERNEL_FUNCTION_TYPE | None = None, function_name: str | None = None, description: str | None = None, prompt: str | None = None, prompt_template_config: PromptTemplateConfig | None = None, prompt_execution_settings: PromptExecutionSettings | list[PromptExecutionSettings] | dict[str, PromptExecutionSettings] | None = None, template_format: Literal['semantic-kernel', 'handlebars', 'jinja2'] = 'semantic-kernel', prompt_template: PromptTemplateBase | None = None, return_plugin: bool = False, **kwargs: Any) -> KernelFunction | KernelPlugin

Parameters

Name Description
plugin_name
Required
str

The name of the plugin to add the function to

function
<xref:KernelFunction | Callable>[<xref:...>,<xref: Any>]

The function to add

Default value: None
function_name
str

The name of the function

Default value: None
plugin_name
Required

The name of the plugin

description
<xref:<xref:semantic_kernel.functions.kernel_function_extension.str | None>>

The description of the function

Default value: None
prompt
<xref:<xref:semantic_kernel.functions.kernel_function_extension.str | None>>

The prompt template.

Default value: None
prompt_template_config
<xref:<xref:semantic_kernel.functions.kernel_function_extension.PromptTemplateConfig | None>>

The prompt template configuration

Default value: None
prompt_execution_settings

The execution settings, will be parsed into a dict.

Default value: None
template_format
<xref:<xref:semantic_kernel.functions.kernel_function_extension.str | None>>

The format of the prompt template

Default value: semantic-kernel
prompt_template
<xref:<xref:semantic_kernel.functions.kernel_function_extension.PromptTemplateBase | None>>

The prompt template

Default value: None
return_plugin

If True, the plugin is returned instead of the function

Default value: False
kwargs
Required
Any

Additional arguments

Returns

Type Description

The function that was added, or the plugin if return_plugin is True

add_functions

Adds a list of functions to the specified plugin.

add_functions(plugin_name: str, functions: list[KERNEL_FUNCTION_TYPE] | dict[str, KERNEL_FUNCTION_TYPE]) -> KernelPlugin

Parameters

Name Description
plugin_name
Required
str

The name of the plugin to add the functions to

functions
Required
list[<xref:KernelFunction>]<xref: | dict>[str,<xref: KernelFunction>]

The functions to add

Returns

Type Description

The plugin that the functions were added to.

add_plugin

Adds a plugin to the kernel's collection of plugins.

If a plugin is provided, it uses that instance instead of creating a new KernelPlugin. See KernelPlugin.from_directory for more details on how the directory is parsed.

add_plugin(plugin: KernelPlugin | object | dict[str, Any] | None = None, plugin_name: str | None = None, parent_directory: str | None = None, description: str | None = None, class_init_arguments: dict[str, dict[str, Any]] | None = None) -> KernelPlugin

Parameters

Name Description
plugin
<xref:KernelPlugin | Any | dict>[str,<xref: Any>]

The plugin to add. This can be a KernelPlugin, in which case it is added straightaway and other parameters are ignored, a custom class that contains methods with the kernel_function decorator or a dictionary of functions with the kernel_function decorator for one or several methods.

Default value: None
plugin_name
<xref:<xref:semantic_kernel.functions.kernel_function_extension.str | None>>

The name of the plugin, used if the plugin is not a KernelPlugin, if the plugin is None and the parent_directory is set, KernelPlugin.from_directory is called with those parameters, see KernelPlugin.from_directory for details.

Default value: None
parent_directory
<xref:<xref:semantic_kernel.functions.kernel_function_extension.str | None>>

The parent directory path where the plugin directory resides

Default value: None
description
<xref:<xref:semantic_kernel.functions.kernel_function_extension.str | None>>

The description of the plugin, used if the plugin is not a KernelPlugin.

Default value: None
class_init_arguments
dict[str,dict[str,<xref: Any>]]<xref: | None>

The class initialization arguments

Default value: None

Returns

Type Description

The plugin that was added.

Exceptions

Type Description
ValidationError

If a KernelPlugin needs to be created, but it is not valid.

add_plugin_from_openai

Add a plugin from an OpenAPI document.

async add_plugin_from_openai(plugin_name: str, plugin_url: str | None = None, plugin_str: str | None = None, execution_parameters: OpenAIFunctionExecutionParameters | None = None, description: str | None = None) -> KernelPlugin

Parameters

Name Description
plugin_name
Required
str

The name of the plugin

plugin_url
<xref:<xref:semantic_kernel.functions.kernel_function_extension.str | None>>

The URL of the plugin

Default value: None
plugin_str
<xref:<xref:semantic_kernel.functions.kernel_function_extension.str | None>>

The JSON string of the plugin

Default value: None
execution_parameters
<xref:<xref:semantic_kernel.functions.kernel_function_extension.OpenAIFunctionExecutionParameters | None>>

The execution parameters

Default value: None
description
<xref:<xref:semantic_kernel.functions.kernel_function_extension.str | None>>

The description of the plugin

Default value: None

Returns

Type Description

The imported plugin

Exceptions

Type Description

if the plugin URL or plugin JSON/YAML is not provided

add_plugin_from_openapi

Add a plugin from the OpenAPI manifest.

add_plugin_from_openapi(plugin_name: str, openapi_document_path: str, execution_settings: OpenAPIFunctionExecutionParameters | None = None, description: str | None = None) -> KernelPlugin

Parameters

Name Description
plugin_name
Required
str

The name of the plugin

openapi_document_path
Required
str

The path to the OpenAPI document

execution_settings
<xref:<xref:semantic_kernel.functions.kernel_function_extension.OpenAPIFunctionExecutionParameters | None>>

The execution parameters

Default value: None
description
<xref:<xref:semantic_kernel.functions.kernel_function_extension.str | None>>

The description of the plugin

Default value: None

Returns

Type Description

The imported plugin

Exceptions

Type Description

if the plugin URL or plugin JSON/YAML is not provided

add_plugins

Adds a list of plugins to the kernel's collection of plugins.

add_plugins(plugins: list[KernelPlugin] | dict[str, KernelPlugin | object]) -> None

Parameters

Name Description
plugins
Required
list[<xref:KernelPlugin>]<xref: | dict>[str,<xref: KernelPlugin>]

The plugins to add to the kernel

get_full_list_of_function_metadata

Get a list of all function metadata in the plugins.

get_full_list_of_function_metadata() -> list[KernelFunctionMetadata]

get_function

Get a function by plugin_name and function_name.

get_function(plugin_name: str | None, function_name: str) -> KernelFunction

Parameters

Name Description
plugin_name
Required
<xref:<xref:semantic_kernel.functions.kernel_function_extension.str | None>>

The name of the plugin

function_name
Required
str

The name of the function

Returns

Type Description

The function

Exceptions

Type Description

If the plugin is not found

If the function is not found

get_function_from_fully_qualified_function_name

Get a function by its fully qualified name (<plugin_name>-<function_name>).

get_function_from_fully_qualified_function_name(fully_qualified_function_name: str) -> KernelFunction

Parameters

Name Description
fully_qualified_function_name
Required
str

The fully qualified name of the function, if there is no '-' in the name, it is assumed that it is only a function_name.

Returns

Type Description

The function

Exceptions

Type Description

If the plugin is not found

If the function is not found

get_list_of_function_metadata

Get a list of all function metadata in the plugin collection.

get_list_of_function_metadata(*args: Any, **kwargs: Any) -> list[KernelFunctionMetadata]

get_list_of_function_metadata_bool

Get a list of the function metadata in the plugin collection.

get_list_of_function_metadata_bool(include_prompt: bool = True, include_native: bool = True) -> list[KernelFunctionMetadata]

Parameters

Name Description
include_prompt

Whether to include semantic functions in the list.

Default value: True
include_native

Whether to include native functions in the list.

Default value: True

Returns

Type Description

A list of KernelFunctionMetadata objects in the collection.

get_list_of_function_metadata_filters

Get a list of Kernel Function Metadata based on filters.

get_list_of_function_metadata_filters(filters: dict[Literal['excluded_plugins', 'included_plugins', 'excluded_functions', 'included_functions'], list[str]]) -> list[KernelFunctionMetadata]

Parameters

Name Description
filters
Required

The filters to apply to the function list. The keys are:

  • included_plugins: A list of plugin names to include.

  • excluded_plugins: A list of plugin names to exclude.

  • included_functions: A list of function names to include.

  • excluded_functions: A list of function names to exclude.

The included and excluded parameters are mutually exclusive. The function names are checked against the fully qualified name of a function.

Returns

Type Description

The list of Kernel Function Metadata that match the filters.

get_plugin

Get a plugin by name.

get_plugin(plugin_name: str) -> KernelPlugin

Parameters

Name Description
plugin_name
Required
str

The name of the plugin

Returns

Type Description

The plugin

Exceptions

Type Description

If the plugin is not found

rewrite_plugins

Rewrite plugins to a dictionary.

rewrite_plugins(plugins: KernelPlugin | list[KernelPlugin] | dict[str, KernelPlugin] | None = None) -> dict[str, KernelPlugin]

Parameters

Name Description
plugins
Default value: None

Attributes

model_computed_fields

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'populate_by_name': True, 'validate_assignment': True}

model_fields

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.fields from Pydantic V1.

model_fields: ClassVar[Dict[str, FieldInfo]] = {'plugins': FieldInfo(annotation=dict[str, KernelPlugin], required=False, default_factory=dict)}

plugins

plugins: dict[str, KernelPlugin]