showcase/shell-docs/src/content/docs/concepts/architecture.mdx
CopilotKit is a three-layer stack that connects your React frontend to any agent framework over a single open protocol. Understanding the layers — and the wire between them — is the fastest way to build the right mental model before touching code.
<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) that connect your UI to a running agent. 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."
A protocol-based architecture means you can swap the agent layer without rewriting the frontend, run multiple agent backends side by side, and integrate with any AG-UI-compatible tool from the broader ecosystem — MCP servers, A2UI components, Oracle / Google / AWS agent platforms.
useAgent hook posts to your runtime endpoint.