Agent patterns

Tool use

Also called: function calling, tool calling

Tool use lets a model do more than produce text: you expose named actions with typed inputs, and the model calls them to read data, run code, or reach the outside world. It is the bridge from talking to doing.

James Phoenix
Understanding Data Updated July 3, 2026

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:

TypeScript
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.
Note
Tool use is the atom of agents. An agent is just tool use run in a loop: call a tool, read the result, decide the next call, repeat until the goal is met.

Related terms

Engineering context for real systems?

Getting the right information into the window at the right time is most of the job. If you want that thinking applied to your product, that is what I do.

See how I can help