File: overview.md | Updated: 11/15/2025
Menu
v5 (Latest)
AI SDK 5.x
Model Context Protocol (MCP) Tools
Copy markdown
=========================================================
Agents are large language models (LLMs) that use tools in a loop to accomplish tasks.
These components work together:
The Agent class handles these three components. Here's an agent that uses multiple tools in a loop to accomplish a task:
import { Experimental_Agent as Agent, stepCountIs, tool } from 'ai';import { z } from 'zod';
const weatherAgent = new Agent({ model: 'openai/gpt-4o', tools: { weather: tool({ description: 'Get the weather in a location (in Fahrenheit)', inputSchema: z.object({ location: z.string().describe('The location to get the weather for'), }), execute: async ({ location }) => ({ location, temperature: 72 + Math.floor(Math.random() * 21) - 10, }), }), convertFahrenheitToCelsius: tool({ description: 'Convert temperature from Fahrenheit to Celsius', inputSchema: z.object({ temperature: z.number().describe('Temperature in Fahrenheit'), }), execute: async ({ temperature }) => { const celsius = Math.round((temperature - 32) * (5 / 9)); return { celsius }; }, }), }, stopWhen: stepCountIs(20),});
const result = await weatherAgent.generate({ prompt: 'What is the weather in San Francisco in celsius?',});
console.log(result.text); // agent's final answerconsole.log(result.steps); // steps taken by the agent
The agent automatically:
weather tool to get the temperature in FahrenheitconvertFahrenheitToCelsius to convert itThe Agent class handles the loop, context management, and stopping conditions.
The Agent class is the recommended approach for building agents with the AI SDK because it:
For most use cases, start with the Agent class. Use core functions (generateText, streamText) when you need explicit control over each step for complex structured workflows.
Agents are flexible and powerful, but non-deterministic. When you need reliable, repeatable outcomes with explicit control flow, use core functions with structured workflow patterns combining:
Explore workflow patterns to learn more about building structured, reliable systems.
On this page
Deploy and Scale AI Apps with Vercel.
Vercel delivers the infrastructure and developer experience you need to ship reliable AI-powered applications at scale.
Trusted by industry leaders: