What is a tool?
A tool is an object that can be called by the model to perform a specific task. You can use tools withgenerateText and streamText by passing them to the tools parameter.
Tool structure
A tool consists of three properties:Description
An optional description that influences when the tool is selected:Input schema
A schema that defines and validates the tool’s input:Execute function
An async function that is called with the validated input:Multi-step tool calling
By default,generateText stops after a single step. Use stopWhen to enable multi-step execution:
streamText with the same configuration:
Tool choice
Control when tools are called using thetoolChoice parameter:
Auto (default)
Let the model decide whether to call tools:Required
Force the model to call at least one tool:None
Prevent the model from calling any tools:Specific tool
Force the model to call a specific tool:Schema types
The AI SDK supports multiple schema libraries:Zod
JSON Schema
Accessing tool results
After generation, you can access tool calls and results:Streaming tool calls
WithstreamText, you can stream tool calls and results:
Error handling
Handle errors in tool execution:toolResults: