runtime
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCopilotKit Runtime
CopilotKit Runtime
@copilotkit/runtimeAbstractAgentAgentRunnerThis SKILL.md is the index. Read the reference under that matches
your task — do not try to absorb the whole package from this file.
references/@copilotkit/runtimeAbstractAgentAgentRunner本SKILL.md是索引文件。请阅读与你的任务匹配的下的参考文档——不要试图从本文件中了解整个包的所有内容。
references/Mental Model — the three dictionaries you hand to CopilotRuntime
CopilotRuntime核心模型——传递给CopilotRuntime
的三个配置项
CopilotRuntimets
new CopilotRuntime({
agents, // Record<string, AbstractAgent> — see wiring-external-agents or built-in-agent
runner, // AgentRunner (optional) — see agent-runners
intelligence, // CopilotKitIntelligence (optional) — see intelligence-mode (auto-wires runner)
mcpApps, // McpAppsConfig (optional) — see wiring-mcp-apps-middleware
a2ui, // A2UIConfig (optional) — see packages/a2ui-renderer skill
hooks, // { onRequest, onBeforeHandler } — see middleware
beforeRequestMiddleware,
afterRequestMiddleware, // legacy — see middleware
transcription, // TranscriptionService (optional) — see transcription
});You then mount it:
ts
import { createCopilotRuntimeHandler } from "@copilotkit/runtime/v2";
const handler = createCopilotRuntimeHandler({
runtime,
basePath: "/api/copilotkit",
});
export default { fetch: handler };ts
new CopilotRuntime({
agents, // Record<string, AbstractAgent> — 请查看wiring-external-agents或built-in-agent文档
runner, // AgentRunner(可选) — 请查看agent-runners文档
intelligence, // CopilotKitIntelligence(可选) — 请查看intelligence-mode文档(自动配置runner)
mcpApps, // McpAppsConfig(可选) — 请查看wiring-mcp-apps-middleware文档
a2ui, // A2UIConfig(可选) — 请查看packages/a2ui-renderer相关文档
hooks, // { onRequest, onBeforeHandler } — 请查看middleware文档
beforeRequestMiddleware,
afterRequestMiddleware, // 旧版方式 — 请查看middleware文档
transcription, // TranscriptionService(可选) — 请查看transcription文档
});随后挂载运行:
ts
import { createCopilotRuntimeHandler } from "@copilotkit/runtime/v2";
const handler = createCopilotRuntimeHandler({
runtime,
basePath: "/api/copilotkit",
});
export default { fetch: handler };When to load which reference
不同任务对应参考文档
| Task | Reference |
|---|---|
| Mounting on any fetch-native server (Cloudflare Workers, Bun, Deno, Vercel Edge, Next.js App Router, React Router v7, TanStack Start) or delegating from Express/Node | |
Auth / logging / rate-limit / request-scoped guards via | |
Choosing between | |
| Enabling durable threads + realtime websocket via CopilotKit Cloud (Intelligence is Cloud-only, not self-hostable) | |
Voice transcription — implementing a | |
Instantiating | |
Defining server-side tools via | |
Wiring an external agent framework into | |
| Wiring MCP Apps (runtime-level middleware, not an agent) | |
| 任务 | 参考文档 |
|---|---|
| 在任意原生基于fetch的服务器(Cloudflare Workers、Bun、Deno、Vercel Edge、Next.js App Router、React Router v7、TanStack Start)上挂载,或从Express/Node转发请求 | |
通过 | |
在 | |
| 通过CopilotKit Cloud启用持久化线程+实时WebSocket(Intelligence为仅云端可用功能,不支持自托管) | |
语音转录——为 | |
实例化 | |
通过 | |
将外部Agent框架接入 | |
| 配置MCP Apps(运行时级中间件,非Agent) | |
Invariants and gotchas (load-once, before any reference)
固定规则与注意事项(先阅读,再查看其他参考文档)
- is the canonical primitive.
createCopilotRuntimeHandler/createCopilotExpressHandlerexist but are avoid at all costs — delegate from Express/Hono routes to the fetch primitive instead.createCopilotHonoHandler - is the canonical provider-side field.
publicLicenseKeyis a deprecated alias — expect to see it in legacy code, emit the canonical name in new code.publicApiKey - Intelligence mode auto-wires . Passing both
IntelligenceAgentRunnerandrunnertointelligenceis rejected at construction.CopilotRuntime - Intelligence mode targets CopilotKit Cloud () and is not self-hostable.
api.cloud.copilotkit.ai - runs before
hooks.onRequest(hook-based middleware wins for Response short-circuits).beforeRequestMiddlewareruns afterbeforeRequestMiddleware(seehooks.onRequest).fetch-handler.ts:136-147 - (Intelligence) does not forward thrown
identifyUserobjects — convert to 500. Gate auth rejection inResponse, which does forward Responses.hooks.onRequest - and
agents__unsafe_dev_onlyare dev-only aliases of each other; do not reach for them in production. Either signals that the SPA is in dev mode.selfManagedAgents
- 是标准基础组件。
createCopilotRuntimeHandler/createCopilotExpressHandler虽存在,但务必避免使用——建议从Express/Hono路由转发请求至基于fetch的基础组件。createCopilotHonoHandler - 是标准的提供者端字段。
publicLicenseKey是已废弃的别名——旧代码中可能会出现,新代码请使用标准名称。publicApiKey - 智能模式会自动配置。同时向
IntelligenceAgentRunner传递CopilotRuntime和runner会在构造时被拒绝。intelligence - 智能模式针对CopilotKit Cloud(),不支持自托管。
api.cloud.copilotkit.ai - 在
hooks.onRequest之前运行(基于钩子的中间件优先响应短路)。beforeRequestMiddleware在beforeRequestMiddleware之后运行(详见hooks.onRequest)。fetch-handler.ts:136-147 - (智能模式)不会转发抛出的
identifyUser对象——需转换为500状态码。请在Response中处理认证拒绝,该钩子会转发Response。hooks.onRequest - 和
agents__unsafe_dev_only是彼此的开发环境专用别名;生产环境请勿使用。这两个字段均表示SPA处于开发模式。selfManagedAgents
Reading order for a first-time reader
首次阅读顺序
- — the primitive.
setup-endpoint - or pick one from
built-in-agent— the agent.wiring-external-agents - — production persistence choice.
agent-runners - Optional: ,
middleware,intelligence-mode,server-side-tools.transcription
- — 基础组件说明。
setup-endpoint - 或 从
built-in-agent中选择一个框架 — Agent配置说明。wiring-external-agents - — 生产环境持久化方案选择。
agent-runners - 可选:、
middleware、intelligence-mode、server-side-tools。transcription