About runtime
runtime is an index skill for developers configuring the server-side @copilotkit/runtime package. It directs readers to focused references for mounting endpoints, selecting agent runners, adding middleware, and connecting built-in or external agents.
Key features
- 01Maps tasks to runtime references
- 02Guides fetch-native endpoint setup
- 03Covers agent runner choices
- 04Documents middleware and request hooks
- 05Explains built-in and external agent wiring
Use cases
- 01Mounting a CopilotKit runtime handler
- 02Choosing persistence and runner behavior
- 03Adding authentication or request guards
- 04Connecting an external agent framework
MCP support
The runtime can be configured with MCP Apps middleware through its optional `mcpApps` setting. The input does not describe an MCP server interface.
Install
Copy the command and run it in a terminal.
npx skills add https:/ / github.com/ copilotkit/ copilotkit --skill runtimeAfter installing, type/runtimein Claude Code to confirm it loaded.
Bundled files
References and scripts installed along with SKILL.md.
references/agent-runners-custom.mdagent-runners-in-memory.mdagent-runners-sqlite.mdagent-runners.mdbuilt-in-agent-factory-modes.mdbuilt-in-agent-helper-utilities.mdbuilt-in-agent-model-identifiers.mdbuilt-in-agent.mdintelligence-mode.mdmiddleware.mdserver-side-tools.mdsetup-endpoint.mdtranscription.mdwiring-a2a.mdwiring-adk.mdwiring-ag2.mdwiring-agno.mdwiring-aws-strands.mdwiring-crewai-crews.mdwiring-crewai-flows.mdwiring-external-agents.mdwiring-langgraph.mdwiring-llamaindex.mdwiring-mastra.mdwiring-mcp-apps-middleware.mdwiring-ms-agent-framework.mdwiring-pydantic-ai.mdDetails
From the project READMECopilotKit Runtime
@copilotkit/runtime is the server half of CopilotKit: it accepts AG-UI protocol
requests, dispatches them to an AbstractAgent (built-in or external), runs the
stream through an AgentRunner, and responds as Server-Sent Events.
This SKILL.md is the index. Read the reference under references/ that matches
your task — do not try to absorb the whole package from this file.
Mental Model — the three dictionaries you hand to CopilotRuntime
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:
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 | references/setup-endpoint.md |
Auth / logging / rate-limit / request-scoped guards via hooks.onRequest / hooks.onBeforeHandler (preferred) or legacy beforeRequestMiddleware / afterRequestMiddleware | references/middleware.md |
Choosing between InMemoryAgentRunner, SqliteAgentRunner, or a custom subclass — including thread-locking semantics and the runner/Intelligence mutual exclusion | references/agent-runners.md (+ -in-memory.md, -sqlite.md, -custom.md for backend-specific detail) |
| Enabling durable threads + realtime websocket via CopilotKit Intelligence (a managed service, not self-hostable) | references/intelligence-mode.md |
Voice transcription — implementing a TranscriptionService subclass for the /transcribe endpoint | references/transcription.md |
Instantiating BuiltInAgent — Simple Mode (classic) or Factory Mode with TanStack AI (preferred AG-UI-compliant default), AI SDK, or custom factory | references/built-in-agent.md (+ -factory-modes.md, -helper-utilities.md, -model-identifiers.md) |
Defining server-side tools via defineTool for BuiltInAgent.config.tools (Simple Mode only) | references/server-side-tools.md |
Wiring an external agent framework into CopilotRuntime({ agents }) | references/wiring-external-agents.md (index) + per-framework refs (wiring-mastra.md, wiring-langgraph.md, wiring-crewai-crews.md, wiring-crewai-flows.md, wiring-pydantic-ai.md, wiring-adk.md, wiring-llamaindex.md, wiring-agno.md, wiring-aws-strands.md, wiring-ms-agent-framework.md, wiring-ag2.md, wiring-a2a.md) |
| Wiring MCP Apps (runtime-level middleware, not an agent) | references/wiring-mcp-apps-middleware.md |
Invariants and gotchas (load-once, before any reference)
createCopilotRuntimeHandleris the canonical primitive.createCopilotExpressHandler/createCopilotHonoHandlerexist but are avoid at all costs — delegate from Express/Hono routes to the fetch primitive instead.- Intelligence credentials are server-side. The CLI writes
CPK_INTELLIGENCE_API_KEYinto the runtime's environment; no client-side key is involved. - Intelligence mode auto-wires
IntelligenceAgentRunner. Passing bothrunnerandintelligencetoCopilotRuntimeis rejected at construction. - Intelligence mode targets the managed CopilotKit Intelligence service (
api.cloud.copilotkit.ai) and is not self-hostable. hooks.onRequestruns beforebeforeRequestMiddleware(hook-based middleware wins for Response short-circuits).beforeRequestMiddlewareruns afterhooks.onRequest(seefetch-handler.ts:136-147).identifyUser(Intelligence) does not forward thrownResponseobjects — convert to 500. Gate auth rejection inhooks.onRequest, which does forward Responses.agents__unsafe_dev_onlyandselfManagedAgentsare dev-only aliases of each other; do not reach for them in production. Either signals that the SPA is in dev mode.
Reading order for a first-time reader
setup-endpoint— the primitive.built-in-agentor pick one fromwiring-external-agents— the agent.agent-runners— production persistence choice.- Optional:
middleware,intelligence-mode,server-side-tools,transcription.