Skip to content

Tool

Tool<INPUT, OUTPUT> = object & ToolOutputProperties<INPUT, OUTPUT> & object & { type?: "function"; } | { type: "dynamic"; } | { args: Record<string, unknown>; id: `${string}.${string}`; name: string; type: "provider-defined"; }

Defined in: node_modules/.bun/@ai-sdk+provider-utils@3.0.25+27912429049419a2/node_modules/@ai-sdk/provider-utils/dist/index.d.ts:728

A tool contains the description and the schema of the input that the tool expects. This enables the language model to generate the input.

The tool can also contain an optional execute function for the actual execution function of the tool.

optional description?: string

An optional description of what the tool does. Will be used by the language model to decide whether to use the tool. Not used for provider-defined tools.

inputSchema: FlexibleSchema<INPUT>

The schema of the input that the tool expects. The language model will use this to generate the input. It is also used to validate the output of the language model. Use descriptions to make the input understandable for the language model.

optional onInputAvailable?: (options) => void | PromiseLike<void>

Optional function that is called when a tool call can be started, even if the execute function is not provided.

object & ToolCallOptions

void | PromiseLike<void>

optional onInputDelta?: (options) => void | PromiseLike<void>

Optional function that is called when an argument streaming delta is available. Only called when the tool is used in a streaming context.

object & ToolCallOptions

void | PromiseLike<void>

optional onInputStart?: (options) => void | PromiseLike<void>

Optional function that is called when the argument streaming starts. Only called when the tool is used in a streaming context.

ToolCallOptions

void | PromiseLike<void>

optional providerOptions?: ProviderOptions

Additional provider-specific metadata. They are passed through to the provider from the AI SDK and enable provider-specific functionality that can be fully encapsulated in the provider.

optional toModelOutput?: (output) => LanguageModelV2ToolResultPart["output"]

Optional conversion function that maps the tool result to an output that can be used by the language model.

If not provided, the tool result will be sent as a JSON object.

0 extends 1 & OUTPUT ? any : [OUTPUT] extends [never] ? any : NoInfer<OUTPUT>

LanguageModelV2ToolResultPart["output"]

INPUT extends JSONValue | unknown | never = any

OUTPUT extends JSONValue | unknown | never = any