Skip to main content

Tools & Functions API Reference

Tools and functions that agents can invoke to extend their capabilities.

AITool

Represents a tool that an agent can use, with metadata and an execution delegate.

Overview

AITool is the base class for all tools that can be provided to agents. The most common type of tool is AIFunction, which represents a callable function with parameters and return types.

Properties

AIToolMetadata
required
Metadata describing the tool, including its name, description, and parameter schema.

Methods

InvokeAsync()

Invokes the tool with the provided arguments.
IReadOnlyDictionary<string, object?>
required
The arguments to pass to the tool.
CancellationToken
default:"default"
The cancellation token to monitor for cancellation requests.
Task<object?>
The result of the tool invocation.

AIFunction

A specific type of AITool that represents a local function the agent can call.

Overview

AIFunction wraps .NET methods and makes them available to agents as callable tools. Functions can have strongly-typed parameters and return values.

Properties

AIFunctionMetadata
Metadata describing the function, including name, description, parameters, and return type information.

AIFunctionFactory

Factory class for creating AIFunction instances from delegates and methods.

Create()

Creates an AIFunction from a delegate or method.
Delegate
required
The delegate or method to wrap as an AIFunction.
string?
The name of the function. If null, the method name is used.
string?
A description of what the function does. This is provided to the AI model to help it decide when to call the function.
AIFunctionFactoryCreateOptions?
Options for configuring the function creation, including JSON serialization settings.
AIFunction
An AIFunction instance that wraps the provided delegate.

Example: Simple Function

Example: Function with Multiple Parameters

Example: Async Function

Example: Function with Dependency Injection

Example: Function with Complex Return Type

Example: Function from Static Method

Example: Function with Options

Example: Multiple Tools


FunctionInvokingChatClient

A delegating chat client that adds function invocation capabilities to an underlying IChatClient.

Overview

FunctionInvokingChatClient is a middleware component that intercepts chat completion requests and automatically handles function/tool invocations. When the AI model requests to call a function, this client automatically invokes it and provides the result back to the model.

Constructor

IChatClient
required
The underlying chat client to delegate to.
ILoggerFactory?
Optional logger factory for logging function invocations.
IServiceProvider?
Optional service provider for dependency injection into function parameters.

Properties

IList<AITool>?
Gets or sets additional tools that should be available for invocation beyond those specified in ChatOptions.Tools.

Example: Manual Function Invocation Setup

ChatClientAgent automatically wraps the provided IChatClient with a FunctionInvokingChatClient if one is not already present in the pipeline, so you typically don’t need to create this manually.