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 →PatternValidatedRouting
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 →PatternProvenStructured outputs
Structured outputs constrain a model to return data matching a schema you define, rather than prose you have to parse. It removes an entire class of failure: the model answered correctly and your code could not read it.
Read definition →AntipatternProvenPrompt injection
Prompt injection is untrusted content in the context being followed as instruction. It is not a prompting bug to be patched but a structural consequence of putting data and instructions in the same channel.
Read definition →ConceptGuardrail
A guardrail is a deterministic check that runs around a model call, on the way in or the way out, and refuses to pass something through. It is ordinary code enforcing what a prompt can only request.
Read definition →PatternProvenReAct
ReAct interleaves reasoning and acting: the model thinks, takes one action, reads the result, and thinks again. It is the loop underneath most agents, and its defining property is that the next step is chosen after seeing the last result.
Read definition →