On its own a model can only emit text. Tool use is what gives it hands. You define an action with a name, a description, and a schema for its inputs; the model decides when to call it and with what arguments; your code runs the real thing and hands the result back. Fetch an order, run a query, hit an API: all of it happens through tools.
Defining a tool
With the Vercel AI SDK a tool is a description plus an input schema plus the function that does the work. Pass it to the model and it can call it:
import { generateText, tool, stepCountIs } from 'ai'
import { openai } from '@ai-sdk/openai'
import { z } from 'zod'
const getWeather = tool({
description: 'Get the current weather for a city',
inputSchema: z.object({ city: z.string() }),
execute: async ({ city }) => ({ city, tempC: 21 }),
})
const { text } = await generateText({
model: openai('gpt-5-mini'),
tools: { getWeather },
stopWhen: stepCountIs(5),
prompt: 'What is the weather in Lisbon?',
})The model reads the description and schema, decides to call getWeather, the SDK runs it, and the result flows back into the answer.
What makes tools work
- The description is the interface. The model chooses a tool based on its name and description, so write them for a reader who has never seen your code.
- Fewer, sharper tools beat a big pile. Too many options and the model picks wrong or hallucinates arguments. Start with two or three.
- Validate the arguments. The model chooses the inputs, and it can choose badly. A typed schema catches the obvious mistakes before you execute.
Related terms
Agents vs. workflows
A workflow follows a path you designed in advance; an agent decides its own path at run time by calling tools in a loop toward a goal. Knowing which one you actually need is the first context-engineering decision.
Read definition →Routing
Routing classifies an input and sends it to the handler built for it. It keeps each path specialised and lets you send easy cases to a cheap model and hard cases to an expensive one, without any of the cost of a full agent.
Read definition →