KernelFunctionAttribute Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Specifies that a method on a class imported as a plugin should be included as a KernelFunction in the resulting KernelPlugin.
[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=false)]
public sealed class KernelFunctionAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=false)>]
type KernelFunctionAttribute = class
inherit Attribute
Public NotInheritable Class KernelFunctionAttribute
Inherits Attribute
- Inheritance
-
KernelFunctionAttribute
- Attributes
Remarks
When the system imports functions from an object, it searches for all methods tagged with this attribute. If a method is not tagged with this attribute, it may still be imported directly via a Delegate or MethodInfo referencing the method directly.
Method visibility does not impact whether a method may be imported. Any method tagged with this attribute, regardless of whether it's public or not, will be imported.
A description of the method should be supplied using the DescriptionAttribute. That description will be used both with LLM prompts and embedding comparisons; the quality of the description affects the planner's ability to reason about complex tasks. A DescriptionAttribute should also be provided on each parameter to provide a description of the parameter suitable for consumption by an LLM or embedding.
Functions may have any number of parameters. In general, arguments to parameters are supplied via the KernelArguments used to invoke the function, with the arguments matched by name to the parameters of the method. If no argument of the given name is present, but a default value was specified in the method's definition, that default value will be used. If the argument value in KernelArguments is not of the same type as the parameter, the system will attempt to convert the value to the parameter's type using a TypeConverter.
However, parameters of the following types are treated specially and are supplied from a source other than from the arguments dictionary:
Kernel | The Kernel supplied when invoking the function. |
KernelArguments | The KernelArguments supplied when invoking the function. |
KernelFunction | The KernelFunction that represents this function being invoked. |
CancellationToken | The CancellationToken supplied when invoking the function. |
CultureInfo or IFormatProvider | The result of Culture from the Kernel used when invoking the function. |
ILoggerFactory or ILogger | The result of LoggerFactory from the Kernel (or an ILogger created from it) used when invoking the function. |
IAIServiceSelector | The result of ServiceSelector from the Kernel used when invoking the function. |
Arguments may also be fulfilled from the associated Kernel's Services service provider. If a parameter is attributed with FromKernelServicesAttribute, the system will attempt to resolve the parameter by querying the service provider for a service of the parameter's type. If the service provider does not contain a service of the parameter's type and the parameter is not optional, the invocation will fail.
If no value can be derived from any of these means for all parameters, the invocation will fail.
Constructors
KernelFunctionAttribute() |
Initializes the attribute. |
KernelFunctionAttribute(String) |
Initializes the attribute. |
Properties
Name |
Gets the function's name. |