框架 · Vercel
快速了解 Vercel AI SDK
Vercel 推出的、与模型提供商无关的 TypeScript 工具包。在 AI SDK 7 中,ToolLoopAgent 是主要的 agent 类。它将工具调用循环与流式 UI 辅助工具结合起来,而 WorkflowAgent 支持可在重启后继续运行的任务。
适用于: 希望将工具调用循环 agent 与流式 UI 紧密集成的 Next.js 和 Web 开发者。
关键信息
- 维护者
- Vercel
- 语言
- TypeScript
- 许可证
- Apache-2.0
- 最新版本
ai 7.0.126· 2026年9月30日- 代码仓库
- vercel/ai
- 托管选项
- Vercel Functions + Vercel Workflow
快速入门
安装软件包、设置凭据,然后运行官方文档中的最简 agent。这里使用的模型 ID 与文档一致,但你的账户可能尚未启用这些模型。
npm install ai zod (inferred; not copied from docs)import { ToolLoopAgent, tool } from 'ai';
import { z } from 'zod';
const weatherAgent = new ToolLoopAgent({
model: "anthropic/claude-sonnet-5.5",
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 };
},
}),
},
});
const result = await weatherAgent.generate({
prompt: 'What is the weather in San Francisco in celsius?',
});
console.log(result.text); // agent's final answer
console.log(result.steps); // steps taken by the agent功能
| 支持任意模型 | 是 | 可使用任意提供商的包,也可使用 anthropic/claude-sonnet-5.5 等 AI Gateway 字符串 |
|---|---|---|
| MCP 客户端 | 是 | @ai-sdk/mcp 客户端 |
| MCP 服务器 | 尚未确认 | |
| 多 agent | 是 | 子代理;HarnessAgent 可运行 Claude Code、Codex 或 Pi |
| 持久化运行 | 是 | 需要 Workflow 5 beta 的 WorkflowAgent |
| 人工审批 | 是 | toolApproval,支持 HMAC 签名审批和 OPA 策略 |
| 追踪 | 尚未确认 | |
| 评测 | 尚未确认 |
近期更新
- AI SDK 7 将 ToolLoopAgent 列为推荐的代理类。
- HarnessAgent 可将 Claude Code、Codex 或 Pi 作为代理运行。
- WorkflowAgent (@ai-sdk/workflow) 取代 Workflow DevKit 的 DurableAgent。
- runtimeContext 和 toolsContext 取代 experimental_context。