copilotkit-upgrade
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCopilotKit v1 to v2 Migration Skill
CopilotKit v1 到 v2 迁移技能
Live Documentation (MCP)
在线文档(MCP)
This plugin includes an MCP server () that provides and tools for querying live CopilotKit documentation and source code. Useful for looking up current v2 API signatures during migration.
copilotkit-docssearch-docssearch-code- Claude Code: Auto-configured by the plugin's -- no setup needed.
.mcp.json - Codex: Requires manual configuration. See the copilotkit-debug skill for setup instructions.
此插件包含一个MCP服务器(),提供和工具,可用于查询实时CopilotKit文档和源代码。在迁移过程中查找当前v2 API签名时非常实用。
copilotkit-docssearch-docssearch-code- Claude Code: 由插件的自动配置,无需额外设置。
.mcp.json - Codex: 需要手动配置。请参考copilotkit-debug skill查看配置说明。
Overview
概述
CopilotKit v2 is a ground-up rewrite built on the AG-UI protocol ( / ). Users continue to install and import packages -- the v2 changes are exposed through the same package names with updated APIs (new hook names, component names, runtime configuration). The namespace is an internal implementation detail that users never interact with.
@ag-ui/client@ag-ui/core@copilotkit/*@copilotkit/*CopilotKit v2是基于AG-UI协议( / )完全重写的版本。用户仍可安装和导入系列包——v2的变更通过相同的包名暴露,仅API有所更新(新的钩子名称、组件名称、运行时配置)。命名空间属于内部实现细节,用户无需直接交互。
@ag-ui/client@ag-ui/core@copilotkit/*@copilotkit/*Migration Workflow
迁移工作流
1. Audit Current Usage
1. 审计当前使用情况
Scan the codebase for all v1 imports and API usage:
@copilotkit/react-core -> hooks, CopilotKit provider, types
@copilotkit/react-ui -> CopilotChat, CopilotPopup, CopilotSidebar
@copilotkit/react-textarea -> CopilotTextarea (removed in v2)
@copilotkit/runtime -> CopilotRuntime, service adapters, framework integrations
@copilotkit/runtime-client-gql -> GraphQL client, message types
@copilotkit/shared -> utility types, constants
@copilotkit/sdk-js -> LangGraph/LangChain SDK扫描代码库中所有v1版本的导入和API使用:
@copilotkit/react-core -> hooks, CopilotKit provider, types
@copilotkit/react-ui -> CopilotChat, CopilotPopup, CopilotSidebar
@copilotkit/react-textarea -> CopilotTextarea (removed in v2)
@copilotkit/runtime -> CopilotRuntime, service adapters, framework integrations
@copilotkit/runtime-client-gql -> GraphQL client, message types
@copilotkit/shared -> utility types, constants
@copilotkit/sdk-js -> LangGraph/LangChain SDK2. Identify Deprecated APIs
2. 识别已弃用的API
Key hooks and components to find and replace:
| v1 API | v2 Replacement |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| Removed -- use standard textarea + |
需要查找并替换的核心钩子和组件:
| v1 API | v2 替代方案 |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| 已移除 -- 使用标准textarea + |
3. Map to v2 Equivalents
3. 映射到v2等效API
Refer to for detailed before/after code examples.
references/v1-to-v2-migration.md请参考查看详细的代码前后对比示例。
references/v1-to-v2-migration.md4. Update Package Dependencies
4. 更新包依赖
The package names stay the same. Update to the latest v2 versions:
@copilotkit/*@copilotkit/react-core -> @copilotkit/react (consolidated into one package)
@copilotkit/react-ui -> @copilotkit/react (consolidated into one package)
@copilotkit/react-textarea -> removed (no v2 equivalent)
@copilotkit/runtime -> @copilotkit/runtime (same package, new agent-based API)
@copilotkit/runtime-client-gql -> removed (replaced by AG-UI protocol, re-exported from @copilotkit/react)
@copilotkit/shared -> @copilotkit/shared (same package)
@copilotkit/sdk-js -> @copilotkit/agent (new package for agent definitions)@copilotkit/*@copilotkit/react-core -> @copilotkit/react (consolidated into one package)
@copilotkit/react-ui -> @copilotkit/react (consolidated into one package)
@copilotkit/react-textarea -> removed (no v2 equivalent)
@copilotkit/runtime -> @copilotkit/runtime (same package, new agent-based API)
@copilotkit/runtime-client-gql -> removed (replaced by AG-UI protocol, re-exported from @copilotkit/react)
@copilotkit/shared -> @copilotkit/shared (same package)
@copilotkit/sdk-js -> @copilotkit/agent (new package for agent definitions)5. Update Runtime Configuration
5. 更新运行时配置
The v1 accepted service adapters (OpenAI, Anthropic, LangChain, etc.) and endpoint definitions. The v2 accepts AG-UI instances directly.
CopilotRuntimeCopilotRuntimeAbstractAgentv1 pattern (service adapter + endpoints):
ts
import { CopilotRuntime, OpenAIAdapter } from "@copilotkit/runtime";
const runtime = new CopilotRuntime({ actions: [...] });
// used with copilotKitEndpoint() for Next.js, Express, etc.v2 pattern (agents + Hono endpoint):
ts
import { CopilotRuntime, createCopilotEndpoint } from "@copilotkit/runtime";
import { BuiltInAgent } from "@copilotkit/agent";
const runtime = new CopilotRuntime({
agents: { myAgent: new BuiltInAgent({ model: "openai:gpt-4o" }) },
});
const app = createCopilotEndpoint({ runtime, basePath: "/api/copilotkit" });v1版本的接受服务适配器(OpenAI、Anthropic、LangChain等)和端点定义。v2版本的直接接受AG-UI 实例。
CopilotRuntimeCopilotRuntimeAbstractAgentv1 写法(服务适配器 + 端点):
ts
import { CopilotRuntime, OpenAIAdapter } from "@copilotkit/runtime";
const runtime = new CopilotRuntime({ actions: [...] });
// used with copilotKitEndpoint() for Next.js, Express, etc.v2 写法(Agent + Hono端点):
ts
import { CopilotRuntime, createCopilotEndpoint } from "@copilotkit/runtime";
import { BuiltInAgent } from "@copilotkit/agent";
const runtime = new CopilotRuntime({
agents: { myAgent: new BuiltInAgent({ model: "openai:gpt-4o" }) },
});
const app = createCopilotEndpoint({ runtime, basePath: "/api/copilotkit" });6. Update Provider
6. 更新Provider
v1:
tsx
import { CopilotKit } from "@copilotkit/react-core";
<CopilotKit runtimeUrl="/api/copilotkit">
{children}
</CopilotKit>v2:
tsx
import { CopilotKitProvider } from "@copilotkit/react";
<CopilotKitProvider runtimeUrl="/api/copilotkit">
{children}
</CopilotKitProvider>v1:
tsx
import { CopilotKit } from "@copilotkit/react-core";
<CopilotKit runtimeUrl="/api/copilotkit">
{children}
</CopilotKit>v2:
tsx
import { CopilotKitProvider } from "@copilotkit/react";
<CopilotKitProvider runtimeUrl="/api/copilotkit">
{children}
</CopilotKitProvider>7. Verify
7. 验证
- Run the application and check for runtime errors
- Verify all agent interactions work (chat, tool calls, interrupts)
- Check that tool renderers display correctly
- Confirm suggestions load and display
- 运行应用并检查运行时错误
- 验证所有Agent交互正常运行(聊天、工具调用、中断)
- 检查工具渲染器显示是否正确
- 确认建议内容可正常加载和显示
Quick Reference
快速参考
| Concept | v1 | v2 |
|---|---|---|
| Package scope | | |
| Protocol | GraphQL | AG-UI (SSE) |
| Provider component | | |
| Define frontend tool | | |
| Share app state | | |
| Agent interaction | | |
| Handle interrupts | | |
| Render tool calls | | |
| Chat suggestions | | |
| Runtime class | | |
| Endpoint setup | | |
| Agent definition | | |
| Chat components | | |
| 概念 | v1 | v2 |
|---|---|---|
| 包作用域 | | |
| 协议 | GraphQL | AG-UI (SSE) |
| Provider组件 | | |
| 定义前端工具 | | |
| 共享应用状态 | | |
| Agent交互 | | |
| 处理中断 | | |
| 渲染工具调用 | | |
| 聊天建议 | | |
| 运行时类 | | |
| 端点配置 | | |
| Agent定义 | | |
| 聊天组件 | | |