|
| 1 | +--- |
| 2 | +title: AI SDK 6 Beta |
| 3 | +description: Get started with the Beta version of AI SDK 6. |
| 4 | +--- |
| 5 | + |
| 6 | +# Announcing AI SDK 6 Beta |
| 7 | + |
| 8 | +<Note type="warning"> |
| 9 | + AI SDK 6 is in beta — while more stable than alpha, AI SDK 6 is still in |
| 10 | + active development and APIs may still change. Pin to specific versions as |
| 11 | + breaking changes may occur in patch releases. |
| 12 | +</Note> |
| 13 | + |
| 14 | +## Why AI SDK 6? |
| 15 | + |
| 16 | +AI SDK 6 is a **major version** due to the introduction of the **v3 Language Model Specification** that powers new capabilities like agents and tool approval. However, unlike AI SDK 5, **this release is not expected to have major breaking changes** for most users. |
| 17 | + |
| 18 | +The version bump reflects improvements to the specification, not a complete redesign of the SDK. If you're using AI SDK 5, migrating to v6 should be straightforward with minimal code changes. |
| 19 | + |
| 20 | +## Beta Version Guidance |
| 21 | + |
| 22 | +The AI SDK 6 Beta is intended for: |
| 23 | + |
| 24 | +- **Trying out new features** and giving us feedback on the developer experience |
| 25 | +- **Experimenting with agents** and tool approval workflows |
| 26 | + |
| 27 | +Your feedback during this beta phase directly shapes the final stable release. Share your experiences through [GitHub issues](https://github.com/vercel/ai/issues/new/choose). |
| 28 | + |
| 29 | +## Installation |
| 30 | + |
| 31 | +To install the AI SDK 6 Beta, run the following command: |
| 32 | + |
| 33 | +```bash |
| 34 | +npm install ai@beta @ai-sdk/openai@beta @ai-sdk/react@beta |
| 35 | +``` |
| 36 | + |
| 37 | +<Note type="warning"> |
| 38 | + APIs may still change during beta. Pin to specific versions as breaking |
| 39 | + changes may occur in patch releases. |
| 40 | +</Note> |
| 41 | + |
| 42 | +## What's New in AI SDK 6? |
| 43 | + |
| 44 | +AI SDK 6 introduces three flagship features (with more to come soon!): |
| 45 | + |
| 46 | +### Agent Abstraction |
| 47 | + |
| 48 | +A new unified interface for building agents with full control over execution flow, tool loops, and state management. |
| 49 | + |
| 50 | +### Tool Execution Approval |
| 51 | + |
| 52 | +Request user confirmation before executing tools, enabling native human-in-the-loop patterns. |
| 53 | + |
| 54 | +### Image Editing Support |
| 55 | + |
| 56 | +Native support for image editing (coming soon). |
| 57 | + |
| 58 | +## Agent Abstraction |
| 59 | + |
| 60 | +AI SDK 6 introduces a powerful new `Agent` interface that provides a standardized way to build agents. |
| 61 | + |
| 62 | +### Default Implementation: ToolLoopAgent |
| 63 | + |
| 64 | +The `ToolLoopAgent` class provides a default implementation out of the box: |
| 65 | + |
| 66 | +```typescript |
| 67 | +import { openai } from '@ai-sdk/openai'; |
| 68 | +import { ToolLoopAgent } from 'ai'; |
| 69 | +import { weatherTool } from '@/tool/weather'; |
| 70 | + |
| 71 | +export const weatherAgent = new ToolLoopAgent({ |
| 72 | + model: openai('gpt-4o'), |
| 73 | + instructions: 'You are a helpful weather assistant.', |
| 74 | + tools: { |
| 75 | + weather: weatherTool, |
| 76 | + }, |
| 77 | +}); |
| 78 | + |
| 79 | +// Use the agent |
| 80 | +const result = await weatherAgent.generate({ |
| 81 | + prompt: 'What is the weather in San Francisco?', |
| 82 | +}); |
| 83 | +``` |
| 84 | + |
| 85 | +The agent automatically handles the tool execution loop: |
| 86 | + |
| 87 | +1. Calls the LLM with your prompt |
| 88 | +2. Executes any requested tool calls |
| 89 | +3. Adds results back to the conversation |
| 90 | +4. Repeats until complete (default `stopWhen: stepCountIs(20)`) |
| 91 | + |
| 92 | +### UI Integration |
| 93 | + |
| 94 | +Agents integrate seamlessly with React and other UI frameworks: |
| 95 | + |
| 96 | +```typescript |
| 97 | +// Server-side API route |
| 98 | +import { createAgentUIStreamResponse, convertToModelMessages } from 'ai'; |
| 99 | + |
| 100 | +export async function POST(request: Request) { |
| 101 | + const { messages } = await request.json(); |
| 102 | + |
| 103 | + return createAgentUIStreamResponse({ |
| 104 | + agent: weatherAgent, |
| 105 | + messages: convertToModelMessages(messages), |
| 106 | + }); |
| 107 | +} |
| 108 | +``` |
| 109 | + |
| 110 | +```typescript |
| 111 | +// Client-side with type safety |
| 112 | +import { useChat } from '@ai-sdk/react'; |
| 113 | +import { InferAgentUIMessage } from 'ai'; |
| 114 | +import { weatherAgent } from '@/agent/weather-agent'; |
| 115 | + |
| 116 | +type WeatherAgentUIMessage = InferAgentUIMessage<typeof weatherAgent>; |
| 117 | + |
| 118 | +const { messages, sendMessage } = useChat<WeatherAgentUIMessage>(); |
| 119 | +``` |
| 120 | + |
| 121 | +### Custom Agent Implementations |
| 122 | + |
| 123 | +In AI SDK 6, `Agent` is an interface rather than a concrete class. While `ToolLoopAgent` provides a solid default implementation for most use cases, you can implement the `Agent` interface to build custom agent architectures: |
| 124 | + |
| 125 | +```typescript |
| 126 | +import { Agent } from 'ai'; |
| 127 | + |
| 128 | +// Build your own multi-agent orchestrator that delegates to specialists |
| 129 | +class Orchestrator implements Agent { |
| 130 | + constructor(private subAgents: Record<string, Agent>) { |
| 131 | + /* Implementation */ |
| 132 | + } |
| 133 | +} |
| 134 | + |
| 135 | +const orchestrator = new Orchestrator({ |
| 136 | + subAgents: { |
| 137 | + // your subagents |
| 138 | + }, |
| 139 | +}); |
| 140 | +``` |
| 141 | + |
| 142 | +This approach enables you to experiment with orchestrators, memory layers, custom stop conditions, and agent patterns tailored to your specific use case. |
| 143 | + |
| 144 | +## Tool Execution Approval |
| 145 | + |
| 146 | +AI SDK 6 introduces a tool approval system that gives you control over when tools are executed. |
| 147 | + |
| 148 | +Enable approval for a tool by setting `needsApproval`: |
| 149 | + |
| 150 | +```typescript |
| 151 | +import { tool } from 'ai'; |
| 152 | +import { z } from 'zod'; |
| 153 | + |
| 154 | +export const weatherTool = tool({ |
| 155 | + description: 'Get the weather in a location', |
| 156 | + inputSchema: z.object({ |
| 157 | + city: z.string(), |
| 158 | + }), |
| 159 | + needsApproval: true, // Require user approval |
| 160 | + execute: async ({ city }) => { |
| 161 | + const weather = await fetchWeather(city); |
| 162 | + return weather; |
| 163 | + }, |
| 164 | +}); |
| 165 | +``` |
| 166 | + |
| 167 | +### Dynamic Approval |
| 168 | + |
| 169 | +Make approval decisions based on tool input: |
| 170 | + |
| 171 | +```typescript |
| 172 | +export const paymentTool = tool({ |
| 173 | + description: 'Process a payment', |
| 174 | + inputSchema: z.object({ |
| 175 | + amount: z.number(), |
| 176 | + recipient: z.string(), |
| 177 | + }), |
| 178 | + // Only require approval for large transactions |
| 179 | + needsApproval: async ({ amount }) => amount > 1000, |
| 180 | + execute: async ({ amount, recipient }) => { |
| 181 | + return await processPayment(amount, recipient); |
| 182 | + }, |
| 183 | +}); |
| 184 | +``` |
| 185 | + |
| 186 | +### Client-Side Approval UI |
| 187 | + |
| 188 | +Handle approval requests in your UI: |
| 189 | + |
| 190 | +```tsx |
| 191 | +export function WeatherToolView({ invocation, addToolApprovalResponse }) { |
| 192 | + if (invocation.state === 'approval-requested') { |
| 193 | + return ( |
| 194 | + <div> |
| 195 | + <p>Can I retrieve the weather for {invocation.input.city}?</p> |
| 196 | + <button |
| 197 | + onClick={() => |
| 198 | + addToolApprovalResponse({ |
| 199 | + id: invocation.approval.id, |
| 200 | + approved: true, |
| 201 | + }) |
| 202 | + } |
| 203 | + > |
| 204 | + Approve |
| 205 | + </button> |
| 206 | + <button |
| 207 | + onClick={() => |
| 208 | + addToolApprovalResponse({ |
| 209 | + id: invocation.approval.id, |
| 210 | + approved: false, |
| 211 | + }) |
| 212 | + } |
| 213 | + > |
| 214 | + Deny |
| 215 | + </button> |
| 216 | + </div> |
| 217 | + ); |
| 218 | + } |
| 219 | + |
| 220 | + if (invocation.state === 'output-available') { |
| 221 | + return ( |
| 222 | + <div> |
| 223 | + Weather: {invocation.output.weather} |
| 224 | + Temperature: {invocation.output.temperature}°F |
| 225 | + </div> |
| 226 | + ); |
| 227 | + } |
| 228 | + |
| 229 | + // Handle other states... |
| 230 | +} |
| 231 | +``` |
| 232 | + |
| 233 | +### Auto-Submit After Approvals |
| 234 | + |
| 235 | +Automatically continue the conversation once approvals are handled: |
| 236 | + |
| 237 | +```typescript |
| 238 | +import { useChat } from '@ai-sdk/react'; |
| 239 | +import { lastAssistantMessageIsCompleteWithApprovalResponses } from 'ai'; |
| 240 | + |
| 241 | +const { messages, addToolApprovalResponse } = useChat({ |
| 242 | + sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithApprovalResponses, |
| 243 | +}); |
| 244 | +``` |
| 245 | + |
| 246 | +## Image Editing Support |
| 247 | + |
| 248 | +Native support for image editing and generation workflows is coming soon. This will enable: |
| 249 | + |
| 250 | +- Image-to-image transformations |
| 251 | +- Multi-modal editing with text prompts |
| 252 | + |
| 253 | +## Migration from AI SDK 5.x |
| 254 | + |
| 255 | +AI SDK 6 is expected to have minimal breaking changes. The version bump is due to the v3 Language Model Specification, but most AI SDK 5 code will work with little or no modification. |
| 256 | + |
| 257 | +## Timeline |
| 258 | + |
| 259 | +**AI SDK 6 Beta**: Available now |
| 260 | + |
| 261 | +**Stable Release**: End of 2025 |
0 commit comments