Parameters
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.
string
An optional title of the tool.
FlexibleSchema<INPUT>
required
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.You can use descriptions on the schema properties to make the input understandable for the language model.
FlexibleSchema<OUTPUT>
Optional schema for the output of the tool.
Used for type validation of the tool’s return value.
(input: INPUT, options: ToolExecutionOptions) => OUTPUT | Promise<OUTPUT> | AsyncIterable<OUTPUT>
An async function that is called with the arguments from the tool call and produces a result.
If not provided, the tool will not be executed automatically.
Array<{ input: INPUT }>
An optional list of input examples that show the language model what the input should look like.
boolean | ((input: INPUT, options) => boolean | Promise<boolean>)
Whether the tool needs approval before it can be executed.
Can be a boolean or a function that receives the input and returns a boolean.
boolean
Strict mode setting for the tool.Providers that support strict mode will use this setting to determine
how the input should be generated. Strict mode will always produce
valid inputs, but it might limit what input schemas are supported.
(options: ToolExecutionOptions) => void | Promise<void>
Optional function that is called when the argument streaming starts.
Only called when the tool is used in a streaming context.
(options: { inputTextDelta: string } & ToolExecutionOptions) => void | Promise<void>
Optional function that is called when an argument streaming delta is available.
Only called when the tool is used in a streaming context.
(options: { input: INPUT } & ToolExecutionOptions) => void | Promise<void>
Optional function that is called when a tool call can be started,
even if the execute function is not provided.
(options: { toolCallId: string; input: INPUT; output: OUTPUT }) => ToolResultOutput | Promise<ToolResultOutput>
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.
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.
Tool Execution Options
When theexecute function is called, it receives these options:
string
The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
Array<ModelMessage>
Messages that were sent to the language model to initiate the response that contained the tool call.
The messages do not include the system prompt nor the assistant response that contained the tool call.
AbortSignal
An optional abort signal that indicates that the overall operation should be aborted.
unknown
User-defined context that flows through the execution.
Returns
Returns aTool object with type information inferred from the input and output schemas.