showcase/shell-docs/src/content/docs/concepts/architecture.mdx
CopilotKit is a three-layer stack — frontend, runtime, agent — connected by the open AG-UI event protocol. The runtime lives in your own application server, so the only thing between your UI and your agent is a wire format you can inspect.
<ImageZoom src="https://cdn.copilotkit.ai/docs/copilotkit/images/architecture-diagram.png" className="rounded-2xl" width={1000} height={1000} />
The React app your users interact with. CopilotKit ships hooks (useAgent, useFrontendTool, useAgentContext, useThreads) and prebuilt components (CopilotChat, CopilotSidebar, CopilotPopup). Use the prebuilt chat surface, build a fully custom UI with the headless hooks, or mix the two.
A request handler that mounts inside your application server (Next.js App Router, Express, Hono, Bun, Deno, Cloudflare Workers). The runtime accepts requests from the frontend, mediates auth and tool calls, and forwards work to your agent over AG-UI. For the framework-agnostic path you can instantiate a BuiltInAgent in-process and skip an external agent process entirely.
The agent backend you choose: LangGraph, Mastra, CrewAI, Pydantic AI, Microsoft Agent Framework, the Built-in Agent, or any custom AG-UI-compatible implementation. The agent runs your prompt, calls tools, emits state, and streams events back to the runtime.
CopilotKit doesn't lock you into one agent framework. The runtime talks to your agent over AG-UI, an open, event-driven protocol that standardizes how agents communicate with applications:
"The future of agents isn't one company or one platform — it's an agentic ecosystem connected by protocols."
Because the contract is a protocol — not an SDK lock-in — you can swap the agent layer without rewriting the frontend, run multiple agent backends side by side, and integrate with anything AG-UI-compatible: MCP servers, A2UI components, Oracle / Google / AWS agent platforms.
useAgent hook posts to your runtime endpoint.