runtime
Original:🇺🇸 English
Translated
@copilotkit/runtime — mount a fetch-native CopilotRuntime on any JS server, wire middleware, pick an AgentRunner, instantiate BuiltInAgent (Factory Mode with TanStack AI is the preferred default) or plug in any of 12 external agent frameworks (Mastra, LangGraph, CrewAI Crews/Flows, PydanticAI, ADK, LlamaIndex, Agno, AWS Strands, MS Agent Framework, AG2, A2A), enable Intelligence mode for durable threads + websocket, register server-side tools via defineTool, and wire voice transcription. Uses the fetch-based createCopilotRuntimeHandler primitive — the Express/Hono adapters are discouraged. Load the reference under references/ that matches your task.
5installs
Sourcecopilotkit/copilotkit
Added on
NPX Install
npx skill4agent add copilotkit/copilotkit runtimeTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →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/Mental Model — the three dictionaries you hand to 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 };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) | |
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
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