System Briefing: Agent Architecture
Building intelligent systems is no longer about writing massive prompt chains. It is about empowering models with deterministic tools. Here is how we build agents using AI SDK 6.
The Shift to Tool Calling
With AI SDK 6, the emphasis has officially shifted from generating pure text to generating structured, predictable logic outputs. Language models can now parse your Zod schemas and decide when to pull in external resources.
Defining Deterministic Tools
You can provide your agent with native functions that execute safely on the server side. Let's look at a tool designed to read the database.
import { tool } from "ai";
import { z } from "zod";
export const fetchWeatherTool = tool({
description: "Get the current weather for a city.",
inputSchema: z.object({
city: z.string().describe("The name of the city"),
}),
execute: async ({ city }) => {
// Access external API here
const temp = await getTemp(city);
return { temperature: temp };
},
});The Multi-Step Agent Loop
When building an autonomous agent, returning a single response isn't enough. We utilize multi-step generation, allowing the model to invoke a tool, read the tool's result, and then format a final reply to the user.
import { streamText } from "ai";
import { openai } from "@ai-sdk/openai";
const result = streamText({
model: openai("gpt-4o"),
messages,
tools: { getWeather: fetchWeatherTool },
maxSteps: 5, // Execute up to 5 automatic tool cycles
});
return result.toUIMessageStreamResponse();