@svpino: 以下是如何通过 Slack、Teams、Discord、WhatsApp 或 Telegram 构建并分发你的 Agent。这是给那些…
摘要
一位开发者布道师展示了如何使用 CopilotKit 的 Channels SDK 将 AI Agent 分发到 Slack、Teams、Discord、WhatsApp 和 Telegram,该 SDK 负责处理各平台特定的集成和原生 UI 渲染。
查看缓存全文
缓存时间: 2026/08/05 00:16
Here is how to build and distribute your agent via Slack, Teams, Discord, WhatsApp, or Telegram. This is for those of you who are building an agent. The most popular solution I’ve seen so far is to build a specific integration for each channel. This takes a ton of work because each platform is different and you need to maintain all those integrations. Using the Channels SDK from @CopilotKit will make your life way easier. The flow looks like this: 1. Build your agent. 2. Create a channel in CopilotKit Intelligence. 3. Add the specific platform adapter you want to support. 4. Copy and paste the runtime snippet into your app. 5. Your agent is now live in that channel. Basically, their Channels SDK handles all the plumbing that lets you integrate your agents across every messaging platform. You know the rest from here: Anyone on that channel can mention the agent directly to ask a question or assign work to it. Your agent will always get the context of the conversation where the work is happening. By the way, your agents keep full functionality here: they can use tools, retain memory across conversations, render native UI on each platform, and request human approval before important actions. GitHub Repository: https://github.com/CopilotKit/channels-sdk… Thanks to the team for partnering with me on this post.
CopilotKit/channels-sdk
Source: https://github.com/CopilotKit/channels-sdk
Channels SDK
将任何 AI agent 带入 Slack、Microsoft Teams 以及工作发生的渠道 —— 并带有原生、交互式 UI。
Try Channels (https://www.copilotkit.ai/try-channels) · Build with the SDK · Explore OpenTag
npm (https://www.npmjs.com/package/@copilotkit/channels) · License: MIT
https://github.com/user-attachments/assets/73d70014-fad1-4ee6-9c0c-97e5e949a04e
你的 agent 保留其工具、模型和业务逻辑。Channels 为它提供了一个与人类协作的原生场所。
Your agent belongs where work happens
Channels 将兼容 AG-UI 的 agent 连接到你的团队已经使用的沟通平台。Agent 可以理解对话、流式响应、调用工具、处理文件、渲染交互式 UI,并在执行操作前暂停等待人工批准。
| Bring your agent | Render native UI | Keep people in control |
|---|---|---|
| 使用 CopilotKit 内置的 agent,或连接 LangGraph、CrewAI、Mastra、Pydantic AI、Google ADK 以及其他 AG-UI agent。 | 只需描述一次消息,即可将其渲染为原生 Slack Block Kit、Teams Adaptive Cards 以及平台特定的 UI。 | 在 agent 采取行动之前,将按钮、选项和审批门槛直接放入对话中。 |
One interaction, native to every channel
| Slack | Microsoft Teams | Discord |
|---|---|---|
Channels 是为了让同一个 agent 能够在每一种通信界面上与用户互动而构建的。通过 CopilotKit Intelligence 可以获取 Slack 和 Microsoft Teams 的托管连接,更多渠道正在陆续推出。
Try it before you build it
在 Slack 或 Microsoft Teams 中体验真实的 Channels agent,无需配置应用、运行时或提供商凭据。
Try Channels → (https://www.copilotkit.ai/try-channels)
选择一个平台,加入体验,看看 agent 如何处理上下文、工具使用和原生渠道 UI。
Build your first Channel
你的 agent 和应用程序逻辑运行在你自己的基础设施中。CopilotKit Intelligence 负责管理平台连接,并将每一轮交互传递给长期运行的 Channels 进程。
Fastest path: let your coding agent drive
构建 Channels agent 涉及一个项目、一个 agent、一个受管理的 Channel、一个提供商应用,以及一个长期运行的运行时。一份指南可以带你的 agent 完成所有这些步骤。
npx copilotkit@latest channels setup
这会安装 channels-setup 技能,输出一条提示,并将其复制到你的剪贴板。把它粘贴到你的 coding agent 中。该技能是一个指针——当你的 agent 需要时,它会从 copilotkit.ai/channels-guide.md (https://copilotkit.ai/channels-guide.md) 获取工作流,因此即使安装的技能已过时数月,步骤仍然是最新的。指南会询问你想要的平台(Slack 或 Microsoft Teams)以及你使用的 agent 框架。你的 agent 会在你自己已登录的会话中自行操作 Slack 和 Intelligence 控制台。如果它还没有浏览器或 computer-use 工具,它会要求你先添加一个——这是预期的路径,而不是退路。你输入机密信息;它负责点击操作。或者在磁盘上安装 Slack 设置技能
跳过托管指南,将 Slack 工作流直接放入你正在运行的 coding agent 中:
npx copilotkit@latest skills install --skill setup-slack-channel -y
-y 会安装该技能,而不会打开选择器。该技能仅限于 Slack —— 对于 Microsoft Teams,请使用上面的指南。CLI 涵盖了 Intelligence 侧:copilotkit channels add --adapter slack 用于声明 Channel 并附加适配器,copilotkit channels status 用于比较你的配置、代码和服务器。留在浏览器中的是提供商侧 —— 创建 Slack 应用并将其安装到工作区 —— 以及签发项目 API 密钥。没有任何 CLI 标志接受凭据值,因此机器人令牌和签名密钥会保留在你的 .env 文件中,并且只由你掌握。
出现
Unknown option '--skill'? 一个较旧的copilotkit—— 全局安装或遗留在 npx 缓存中 —— 正在覆盖当前的 CLI。请保留@latest;正是它强制 npx 获取当前版本,而不是重用已有的版本。下面的步骤是相同的路径,只不过需要手动完成。
1. Configure the connection
在 CopilotKit Intelligence (https://docs.copilotkit.ai/channels) 中创建一个 Channel 并连接 Slack。保留 Channel 代码和项目范围内的 Intelligence API 密钥,供后续步骤使用。你需要 Node.js 22 或更高版本,以及一个长期运行的 Node 进程或容器。
2. Install the SDK
npm install @copilotkit/channels @copilotkit/runtime
npm install --save-dev tsx typescript @types/node
npm pkg set type=module
Channels 和 Runtime 作为经过测试的搭配一起发布。请一起升级这两个包。
3. Create the listener
下面的示例使用 CopilotKit 内置的 agent。你可以将 makeAgent 替换为任何兼容 AG-UI 的 agent 工厂,而无需更改 Channel 生命周期。
// channel.ts
import { createServer } from "node:http";
import { createChannel } from "@copilotkit/channels";
import {
BuiltInAgent,
CopilotKitIntelligence,
CopilotRuntime,
} from "@copilotkit/runtime/v2";
import { createCopilotNodeListener } from "@copilotkit/runtime/v2/node";
function required(name: string): string {
const value = process.env[name];
if (!value) throw new Error(`Missing required environment variable: ${name}`);
return value;
}
function makeAgent(threadId: string) {
const agent = new BuiltInAgent({
model: "openai:gpt-5.4-mini"
});
agent.threadId = threadId;
return agent;
}
const channel = createChannel({
name: required("CHANNEL_CODE"),
identifyUser: "platform",
agent: makeAgent,
});
channel.onMessage(async ({ thread, message }) => {
await thread.runAgent({
prompt: message.contentParts?.length ? [
...(message.text ? [{ type: "text" as const, text: message.text }] : []),
...message.contentParts,
] : message.text,
context: [{ description: "Originating platform", value: message.platform }],
});
});
const intelligence = new CopilotKitIntelligence({
apiKey: required("INTELLIGENCE_API_KEY"),
});
const runtime = new CopilotRuntime({
agents: {},
intelligence,
identifyUser: () => ({ id: "channels-runtime", name: "Channels Runtime" }),
channels: [channel],
});
const listener = createCopilotNodeListener({
runtime,
basePath: "/api/copilotkit",
});
const channels = listener.channels;
if (!channels) throw new Error("Channels control surface was not created.");
const server = createServer(listener);
const shutdown = async () => {
await channels.stop();
if (server.listening) server.close();
};
process.once("SIGINT", shutdown);
process.once("SIGTERM", shutdown);
await channels.ready({ timeoutMs: 30_000 });
const status = channels.status();
if (status.overall !== "online") {
throw new Error(`Channel is not online: ${JSON.stringify(status)}`);
}
const port = Number(process.env.PORT ?? 3000);
server.listen(port, () => {
console.log(`Channel online; lifecycle server listening on :${port}`);
});
4. Start it
# .env
OPENAI_API_KEY=
INTELLIGENCE_API_KEY=
CHANNEL_CODE=
PORT=3000
node --env-file=.env --import tsx channel.ts
当 Intelligence 报告 Online 时,将应用邀请到 Slack 频道并提及它。你的 agent 现在可以接收对话并在线程中响应。
想要 Microsoft Teams、不同的 agent 框架、交互式审批、文件或生产部署指南? 继续阅读 Channels 文档 (https://docs.copilotkit.ai/channels)。 更想让你的 agent 来做? 运行上面最快路径中的
npx copilotkit@latest channels setup。该指南涵盖了相同的设置流程以及提供商和验证步骤。
How it works
每一轮交互都遵循相同的路径:
- 有人在 Slack 或 Microsoft Teams 中给你的应用发消息。
- CopilotKit Intelligence 接收平台事件,并将其传递到你的 Channels 进程。
- Channels 通过 AG-UI 运行你的 agent,执行工具,并渲染结果。
- Intelligence 将原生平台 UI 发送回对话中。
| 你运行 | CopilotKit Intelligence 管理 |
|---|---|
| 你的 agent、模型凭据、工具和业务逻辑 | Slack 和 Microsoft Teams 平台凭据 |
| 长期运行的 Channels 监听器 | 平台入口和带凭据的投递 |
| 应用状态、部署和日志 | 运行时注册、健康检查和重连 |
SDK 是开源的,并使用 MIT 许可证。CopilotKit Intelligence 可以由 CopilotKit 托管,也可以为企业部署而自托管。
See a complete Channels app
OpenTag (
相似文章
Show HN: Channels SDK – 将任意智能体接入任意渠道(Slack、MS Teams)
CopilotKit 宣布推出 Channels SDK,这是一个开源工具包,让开发者能够将任何兼容 AG-UI 的 AI 智能体连接到 Slack、Microsoft Teams 和 Discord,并支持原生交互式界面、工具调用和人工审批门控。
Channels SDK
Channels SDK 使开发者能够将 AI 代理部署到 Slack 和 Teams,而无需面对常见的生产环境痛点。
Agent 设计用于共享,但现有工具并不适用
作者讨论了跨团队共享 AI Agent 工作流的困难,并介绍了 Nairi,这是一款用于在 Slack 中部署基于 Claude Code 的 Agent 且支持共享访问的工具。
@caspar_br: 要让智能体在公司中推广,就必须在人们已在进行工作的场所与之相遇。Fleet 就是围绕这一点构建的:…
Fleet 是一个平台,可让您直接在 Slack、Teams、电子邮件及其他工具中构建和部署 AI 智能体,从而使它们能够在人们现有工作场景中使用。
将你自己的 Agent 接入 MS Teams
微软全新的 Teams TypeScript SDK 让开发者只需三行 HTTP 服务器适配代码,就能把现有 AI Agent 或机器人暴露为 Teams 应用,实现 Slack 与 Teams 共用一套 Agent 逻辑。