Back to KB
Difficulty
Intermediate
Read Time
9 min

Vercel AI SDK 6: First-Class Agents for TypeScript

By Codcompass TeamΒ·Β·9 min read

When Vercel released AI SDK 6 on December 22, 2025, the headline feature was not a new model integration or a faster streaming API. It was a different kind of addition: agents became a first-class primitive in the SDK, not an afterthought patched on top of generateText.

Effloow Lab installed ai@latest (currently 6.0.177) and inspected the package exports, constructor signatures, and available methods directly. This guide covers what actually changed, what the new ToolLoopAgent API looks like in practice, and how to move existing code from SDK 5.x to 6.

Why This Matters: The Shift from Loops to Primitives

In AI SDK 5.x, building an agent meant writing your own loop. You called generateText, checked for tool calls in the response, executed those tools, passed results back, and repeated until done β€” all in application code that you maintained yourself.

The result was that every team ended up writing a slightly different, slightly buggy version of the same control loop. Edge cases around retries, step limits, streaming, and type safety accumulated per project.

SDK 6 formalizes this pattern. ToolLoopAgent handles the loop. Your code defines what the agent can do and when it should stop. The runtime handles how it executes.

This is not just a convenience wrapper. The Agent interface and ToolLoopAgent class are designed so that:

  • The same agent definition works in API routes, background jobs, and UI streaming contexts without modification
  • TypeScript type inference flows end-to-end from tool schemas to UI message types
  • Human-in-the-loop approval, stop conditions, and structured output are all opt-in per-agent rather than bolt-ons

Installation and Current Version

The package name is still ai. Installing the latest v6 release:

npm install ai@latest
# or
npm install ai@^6.0.0

Enter fullscreen mode Exit fullscreen mode

Effloow Lab confirmed that npm install ai@latest pulls 10 packages with zero vulnerabilities. The install is lean.

Peer dependency: Zod 3.x or Zod 4.x are both supported.

"zod": "^3.25.76 || ^4.1.8"

Enter fullscreen mode Exit fullscreen mode

If you are on Zod 3, nothing changes. If you want Zod 4, SDK 6 now accepts it natively.

The Core Change: ToolLoopAgent

The central addition is ToolLoopAgent. In SDK 5.x, an Experimental_Agent class existed (it is still exported in 6.0.177 as a compatibility shim, but it is deprecated). In SDK 6, the production API is:

import { ToolLoopAgent } from 'ai';
import { anthropic } from '@ai-sdk/anthropic';
import { z } from 'zod';
import { tool } from 'ai';

const searchTool = tool({
  description: 'Search documentation for a given query',
  inputSchema: z.object({ query: z.string() }),
  execute: async ({ query }) => {
    // your search implementation
    return { results: [] };
  },
});

const agent = new ToolLoopAgent({
  model: anthropic('claude-sonnet-4-5'),
  instructions: 'You are a helpful developer assistant.',
  tools: { search: searchTool },
});

Enter fullscreen mode Exit fullscreen mode

The ToolLoopAgent constructor accepts:

Parameter

Type

Default

Purpose

model

LanguageModel

required

The model to use

instructions

string

optional

System prompt

tools

Record<string, Tool>

optional

Available tools

stopWhen

`StopCondition

StopCondition[]`

stepCountIs(20)

output

Output

optional

Structured output format

toolChoice

ToolChoice

optional

Force/auto/none

temperature, topP, etc.

number

optional

Model parameters

onStepFinish

callback

optional

Hook for each step

onFinish

callback

optional

Hook on completion

The instance exposes two methods: generate() (returns Promise<GenerateTextResult>) and stream() (returns a streaming result). Both accept the same parameters:

const result = await agent.generate({
  prompt: 'What does the useEffect hook do?',
});

console.log(result.text);

Enter fullscreen mode Exit fullscreen mode

Agent Is an Interface

ToolLoopAgent implements the Agent interface. This matters because you can create cu

πŸŽ‰ Mid-Year Sale β€” Unlock Full Article

Base plan from just $4.99/mo or $49/yr

Sign in to read the full article and unlock all 635+ tutorials.

Sign In / Register β€” Start Free Trial

7-day free trial Β· Cancel anytime Β· 30-day money-back