Overview
ThedefineTool() function defines tools (functions) that language models can call during generation. Tools enable models to access external data, perform calculations, or trigger actions beyond text generation.
Function signature
Parameters
string
required
The unique name of the tool. This is what the model uses to identify and call the tool.Should be descriptive and follow snake_case convention (e.g.,
get_weather, search_database).string
required
A clear description of what the tool does. This helps the model understand when and how to use it.Should explain the tool’s purpose, expected inputs, and what it returns.
z.ZodType
required
Zod schema defining the tool’s input parameters. The model will generate arguments matching this schema.
Return value
Returns the sameToolDefinition object that was passed in. This is a type-safe helper that provides IDE autocompletion and validation.