惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Tailwind CSS Blog
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog
GbyAI
GbyAI
爱范儿
爱范儿
量子位
Martin Fowler
Martin Fowler
V
V2EX
博客园 - 三生石上(FineUI控件)
I
InfoQ
MongoDB | Blog
MongoDB | Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
N
Netflix TechBlog - Medium
D
DataBreaches.Net
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
U
Unit 42
Apple Machine Learning Research
Apple Machine Learning Research
H
Help Net Security
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
Engineering at Meta
Engineering at Meta

Chat SDK Documentation

History | Chat SDK History | Chat SDK List a vendor-official adapter | Chat SDK Approvals | Chat SDK Vercel Connect | Chat SDK Teams Low-Level APIs | Chat SDK CLI | Chat SDK Platform Adapters | Chat SDK State Adapters | Chat SDK Cards | Chat SDK Getting Started | Chat SDK Introduction | Chat SDK Modals | Chat SDK Slack Low-Level APIs | Chat SDK Streaming | Chat SDK Testing | Chat SDK toAiMessages | Chat SDK Cards | Chat SDK Overview | Chat SDK Markdown | Chat SDK Modals | Chat SDK AI SDK Tools | Chat SDK Types | Chat SDK Message Subject | Chat SDK Conversation History | Chat SDK Transcripts | Chat SDK Slack bot with Next.js and Redis Actions | Chat SDK Direct Messages | Chat SDK Emoji | Chat SDK
Overview | Chat SDK
Vercel · 2026-05-29 · via Chat SDK Documentation

AI utilities that ship with Chat SDK — agent tools, message conversion, and supporting types.

The chat/ai subpath is the home for AI utilities that ship with Chat SDK.

import { createChatTools, toAiMessages } from "chat/ai";

Add the optional peers if you don't already have them:

PageWhat it gives you
AI SDK ToolscreateChatTools and standalone tool factories that let an agent post messages, send DMs, react, edit, delete, and manage subscriptions across every adapter your Chat instance has registered. Built-in approval gates and presets keep writes safe.
toAiMessagesConvert Chat SDK Message[] into the { role, content }[] shape expected by AI SDK calls. Handles role mapping, attachments, links, sorting, and optional per-message transforms.
TypesReference for every type exported from chat/ai — agent message shapes, tool option contracts, presets, approval config, and the binding type that ties tools to your Chat instance.

A Chat SDK bot wired to a tool-calling agent usually looks like this:

import { Chat } from "chat";
import { createChatTools, toAiMessages } from "chat/ai";
import { ToolLoopAgent } from "ai";

const chat = new Chat({ /* adapters, state, ... */ });

const agent = new ToolLoopAgent({
  model: "anthropic/claude-sonnet-4.6",
  instructions: "You operate inside a chat workspace via Chat SDK tools.",
  tools: createChatTools({ chat, preset: "messenger", requireApproval: true }),
});

bot.onSubscribedMessage(async (thread) => {
  const { messages } = await thread.adapter.fetchMessages(thread.id, {
    limit: 20,
  });
  const history = await toAiMessages(messages);
  const result = await agent.stream({ prompt: history });
  await thread.post(result.fullStream);
});
  1. toAiMessages converts messages into an output compatible with AI SDK's ModelMessage[].
  2. createChatTools gives the agent pre-built and fully customizable AI SDK tools.
  3. The streamed response is rendered back into the thread via the standard thread.post(stream) flow.

toAiMessages and the related Ai* types are still re-exported from the top-level chat package so older bots keep working. Those re-exports are now flagged with @deprecated JSDoc — your editor will surface a hint pointing at chat/ai. Migrating is a one-line import change:

- import { toAiMessages } from "chat";
+ import { toAiMessages } from "chat/ai";
  • Human-in-the-Loop with Chat SDK and Workflow SDK — Pause durable workflows on Slack approval cards using Chat SDK and Workflow SDK. Uses createWebhook to suspend workflows until a button click, with patterns for multi-stage approvals, timeouts via durable sleep, and approver validation.

See all guides and templates on the resources page.