Partager via


Kernel.InvokeAsync Method

Definition

Overloads

InvokeAsync(String, String, KernelArguments, CancellationToken)

Invokes a function from Plugins using the specified arguments.

InvokeAsync(KernelFunction, KernelArguments, CancellationToken)

Invokes the KernelFunction.

InvokeAsync<TResult>(KernelFunction, KernelArguments, CancellationToken)

Invokes the KernelFunction.

InvokeAsync<TResult>(String, String, KernelArguments, CancellationToken)

Invokes a function from Plugins using the specified arguments.

InvokeAsync(String, String, KernelArguments, CancellationToken)

Invokes a function from Plugins using the specified arguments.

public System.Threading.Tasks.Task<Microsoft.SemanticKernel.FunctionResult> InvokeAsync (string? pluginName, string functionName, Microsoft.SemanticKernel.KernelArguments? arguments = default, System.Threading.CancellationToken cancellationToken = default);
member this.InvokeAsync : string * string * Microsoft.SemanticKernel.KernelArguments * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.SemanticKernel.FunctionResult>
Public Function InvokeAsync (pluginName As String, functionName As String, Optional arguments As KernelArguments = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of FunctionResult)

Parameters

pluginName
String

The name of the plugin containing the function to invoke. If null, all plugins will be searched for the first function of the specified name.

functionName
String

The name of the function to invoke.

arguments
KernelArguments

The arguments to pass to the function's invocation, including any PromptExecutionSettings.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

The result of the function's execution.

Exceptions

functionName is null.

functionName is composed entirely of whitespace.

The KernelFunction's invocation was canceled.

Remarks

This behaves identically to using GetFunction(IReadOnlyKernelPluginCollection, String, String) to find the desired KernelFunction and then invoking it with this Kernel as its Kernel argument.

Applies to

InvokeAsync(KernelFunction, KernelArguments, CancellationToken)

Invokes the KernelFunction.

public System.Threading.Tasks.Task<Microsoft.SemanticKernel.FunctionResult> InvokeAsync (Microsoft.SemanticKernel.KernelFunction function, Microsoft.SemanticKernel.KernelArguments? arguments = default, System.Threading.CancellationToken cancellationToken = default);
member this.InvokeAsync : Microsoft.SemanticKernel.KernelFunction * Microsoft.SemanticKernel.KernelArguments * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.SemanticKernel.FunctionResult>
Public Function InvokeAsync (function As KernelFunction, Optional arguments As KernelArguments = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of FunctionResult)

Parameters

function
KernelFunction

The KernelFunction to invoke.

arguments
KernelArguments

The arguments to pass to the function's invocation, including any PromptExecutionSettings.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

The result of the function's execution.

Exceptions

function is null.

The KernelFunction's invocation was canceled.

Remarks

This behaves identically to invoking the specified function with this Kernel as its Kernel argument.

Applies to

InvokeAsync<TResult>(KernelFunction, KernelArguments, CancellationToken)

Invokes the KernelFunction.

public System.Threading.Tasks.Task<TResult?> InvokeAsync<TResult> (Microsoft.SemanticKernel.KernelFunction function, Microsoft.SemanticKernel.KernelArguments? arguments = default, System.Threading.CancellationToken cancellationToken = default);
member this.InvokeAsync : Microsoft.SemanticKernel.KernelFunction * Microsoft.SemanticKernel.KernelArguments * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Result>
Public Function InvokeAsync(Of TResult) (function As KernelFunction, Optional arguments As KernelArguments = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of TResult)

Type Parameters

TResult

Specifies the type of the result value of the function.

Parameters

function
KernelFunction

The KernelFunction to invoke.

arguments
KernelArguments

The arguments to pass to the function's invocation, including any PromptExecutionSettings.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

Task<TResult>

The result of the function's execution, cast to TResult.

Exceptions

function is null.

The KernelFunction's invocation was canceled.

The function's result could not be cast to TResult.

Remarks

This behaves identically to invoking the specified function with this Kernel as its Kernel argument.

Applies to

InvokeAsync<TResult>(String, String, KernelArguments, CancellationToken)

Invokes a function from Plugins using the specified arguments.

public System.Threading.Tasks.Task<TResult?> InvokeAsync<TResult> (string? pluginName, string functionName, Microsoft.SemanticKernel.KernelArguments? arguments = default, System.Threading.CancellationToken cancellationToken = default);
member this.InvokeAsync : string * string * Microsoft.SemanticKernel.KernelArguments * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Result>
Public Function InvokeAsync(Of TResult) (pluginName As String, functionName As String, Optional arguments As KernelArguments = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of TResult)

Type Parameters

TResult

Specifies the type of the result value of the function.

Parameters

pluginName
String

The name of the plugin containing the function to invoke. If null, all plugins will be searched for the first function of the specified name.

functionName
String

The name of the function to invoke.

arguments
KernelArguments

The arguments to pass to the function's invocation, including any PromptExecutionSettings.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

Task<TResult>

The result of the function's execution, cast to TResult.

Exceptions

functionName is null.

functionName is composed entirely of whitespace.

The KernelFunction's invocation was canceled.

The function's result could not be cast to TResult.

Remarks

This behaves identically to using GetFunction(IReadOnlyKernelPluginCollection, String, String) to find the desired KernelFunction and then invoking it with this Kernel as its Kernel argument.

Applies to