Agent patternsPatternProven

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

Concept

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 →
PatternValidated

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 →
PatternProven

Structured 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 →
AntipatternProven

Prompt 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 →
Concept

Guardrail

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 →
PatternProven

ReAct

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 →

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