AIAgentBuilderExtensions.Use Method
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.
Adds function invocation callbacks to the AIAgent pipeline that intercepts and processes AIFunction calls.
public static Microsoft.Agents.AI.AIAgentBuilder Use(this Microsoft.Agents.AI.AIAgentBuilder builder, Func<Microsoft.Agents.AI.AIAgent,Microsoft.Extensions.AI.FunctionInvocationContext,Func<Microsoft.Extensions.AI.FunctionInvocationContext,System.Threading.CancellationToken,System.Threading.Tasks.ValueTask<object?>>,System.Threading.CancellationToken,System.Threading.Tasks.ValueTask<object?>> callback);
static member Use : Microsoft.Agents.AI.AIAgentBuilder * Func<Microsoft.Agents.AI.AIAgent, Microsoft.Extensions.AI.FunctionInvocationContext, Func<Microsoft.Extensions.AI.FunctionInvocationContext, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<obj>>, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<obj>> -> Microsoft.Agents.AI.AIAgentBuilder
<Extension()>
Public Function Use (builder As AIAgentBuilder, callback As Func(Of AIAgent, FunctionInvocationContext, Func(Of FunctionInvocationContext, CancellationToken, ValueTask(Of Object)), CancellationToken, ValueTask(Of Object))) As AIAgentBuilder
Parameters
- builder
- AIAgentBuilder
The AIAgentBuilder to which the function invocation callback is added.
- callback
- Func<AIAgent,FunctionInvocationContext,Func<FunctionInvocationContext,CancellationToken,ValueTask<Object>>,CancellationToken,ValueTask<Object>>
A delegate that processes function invocations. The delegate receives the AIAgent instance, the function invocation context, and a continuation delegate representing the next callback in the pipeline. It returns a task representing the result of the function invocation.
Returns
The AIAgentBuilder instance with the function invocation callback added, enabling method chaining.
Exceptions
builder or callback is null.
Remarks
The callback must call the provided continuation delegate to proceed with the function invocation, unless it intends to completely replace the function's behavior.
The inner agent or the pipeline wrapping it must include a FunctionInvokingChatClient. If one does not exist, the AIAgent added to the pipline by this method will throw an exception when it is invoked.