Tool
Namespace: Vercel.AI
public sealed class ToolA tool the model can call. Maps to tool().
Inheritance: object
Constructors
Section titled “Constructors”Tool(string, string?, JsonElement, Func<JsonElement, CancellationToken, Task<string>>?, bool?)
Section titled “Tool(string, string?, JsonElement, Func<JsonElement, CancellationToken, Task<string>>?, bool?)”public Tool(string name, string? description, JsonElement inputSchema, Func<JsonElement, CancellationToken, Task<string>>? execute, bool? strict = null)Creates a function tool.
Parameters
| Name | Type | Description |
|---|---|---|
name |
string | |
description |
string | |
inputSchema |
JsonElement | |
execute |
Func<JsonElement, CancellationToken, Task<string>> | |
strict |
bool? |
Properties
Section titled “Properties”Description
Section titled “Description”public string? Description { get; }Tool description.
Value: string
Execute
Section titled “Execute”public Func<JsonElement, CancellationToken, Task<string>>? Execute { get; }Executes the tool and returns a JSON string. Null means the call is not executed locally, unless ExecuteWithOptions is set.
Value: Func<JsonElement, CancellationToken, Task<string>>
ExecuteWithOptions
Section titled “ExecuteWithOptions”public Func<JsonElement, ToolExecutionOptions, Task<string>>? ExecuteWithOptions { get; set; }Executes the tool with the options of the call, such as the messages of the step. When it is set, the loop calls it
instead of Execute. Maps to execute(input, { toolCallId, messages, abortSignal }).
Value: Func<JsonElement, ToolExecutionOptions, Task<string>>
InputSchema
Section titled “InputSchema”public JsonElement InputSchema { get; }JSON Schema for the arguments. Undefined for a provider-defined tool declared without one.
Value: JsonElement
IsDynamic
Section titled “IsDynamic”public bool IsDynamic { get; set; }True for a tool whose input type is not known at compile time, such as an MCP tool. Parsed calls of the tool are dynamic. Maps to dynamicTool.
Value: bool
IsProviderDefined
Section titled “IsProviderDefined”public bool IsProviderDefined { get; }Whether this is a provider-defined tool, which the provider executes. Maps to { type: 'provider', id, args }.
Value: bool
Metadata
Section titled “Metadata”public IReadOnlyDictionary<string, JsonElement>? Metadata { get; set; }Metadata of the tool, such as the name of the client that created it. Parsed calls of the tool carry it as tool metadata, apart from provider metadata.
Value: IReadOnlyDictionary<string, JsonElement>
public string Name { get; }Tool name.
Value: string
NeedsApproval
Section titled “NeedsApproval”public bool NeedsApproval { get; set; }When true, a call to this tool is not executed. The loop ends at that step and the call is left for the caller,
unless ApproveTool is set, which then decides. Maps to needsApproval.
Value: bool
ProviderOptions
Section titled “ProviderOptions”public JsonElement? ProviderOptions { get; set; }Provider options of the tool, keyed by provider name, such as { "openai": { "omitFromRequestTools": true } }.
Maps to the tool’s providerOptions.
Value: JsonElement?
ProviderToolArgs
Section titled “ProviderToolArgs”public JsonElement ProviderToolArgs { get; }Arguments of a provider-defined tool. Undefined for a function tool.
Value: JsonElement
ProviderToolId
Section titled “ProviderToolId”public string? ProviderToolId { get; }Provider-defined tool id (<provider>.<tool>), or null for a function tool.
Value: string
Strict
Section titled “Strict”public bool? Strict { get; }Responses strict mode. Null means unset, which Responses sends as false.
Value: bool?
public string? Title { get; set; }Display title of the tool. Parsed calls of the tool carry it.
Value: string
ToModelOutput
Section titled “ToModelOutput”public Func<ToolModelOutputCall, ToolModelOutput>? ToModelOutput { get; set; }Converts the JSON output of the tool into the result sent to the model. Null sends the output as it is.
Maps to toModelOutput.
Value: Func<ToolModelOutputCall, ToolModelOutput>
Methods
Section titled “Methods”DynamicTool(string, string?, string, Func<JsonElement, CancellationToken, Task<string>>?)
Section titled “DynamicTool(string, string?, string, Func<JsonElement, CancellationToken, Task<string>>?)”public static Tool DynamicTool(string name, string? description, string jsonSchema, Func<JsonElement, CancellationToken, Task<string>>? execute)Creates a dynamic tool from a JSON schema string. Maps to dynamicTool.
Parameters
| Name | Type | Description |
|---|---|---|
name |
string | |
description |
string | |
jsonSchema |
string | |
execute |
Func<JsonElement, CancellationToken, Task<string>> |
Returns: Tool
Function(string, string?, string, Func<JsonElement, CancellationToken, Task<string>>?, bool?)
Section titled “Function(string, string?, string, Func<JsonElement, CancellationToken, Task<string>>?, bool?)”public static Tool Function(string name, string? description, string jsonSchema, Func<JsonElement, CancellationToken, Task<string>>? execute, bool? strict = null)Creates a tool from a JSON schema string.
Parameters
| Name | Type | Description |
|---|---|---|
name |
string | |
description |
string | |
jsonSchema |
string | |
execute |
Func<JsonElement, CancellationToken, Task<string>> | |
strict |
bool? |
Returns: Tool
ProviderDefined(string, string, JsonElement)
Section titled “ProviderDefined(string, string, JsonElement)”public static Tool ProviderDefined(string id, string name, JsonElement args)Declares a provider-defined tool. The provider executes it, so it has no Execute.
<code class=“paramref”>args</code> must be a JSON object. Maps to JsonElement).
Parameters
| Name | Type | Description |
|---|---|---|
id |
string | |
name |
string | |
args |
JsonElement |
Returns: Tool
ProviderDefined(string, string, JsonElement, JsonElement)
Section titled “ProviderDefined(string, string, JsonElement, JsonElement)”public static Tool ProviderDefined(string id, string name, JsonElement args, JsonElement inputSchema)Declares a provider-defined tool with an input schema. The input of a call the provider ran is parsed with the
schema, so a property the schema does not declare is dropped, as a Zod object does. Maps to a provider tool’s inputSchema.
Parameters
| Name | Type | Description |
|---|---|---|
id |
string | |
name |
string | |
args |
JsonElement | |
inputSchema |
JsonElement |
Returns: Tool
Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product