CopilotKit - An open-source AI agent framework, providing a full-stack agent UI infrastructure.
CopilotKit is an open-source AI-native application front-end operating system. The tool supports three generative UI modes: controlled, declarative A2UI, and open, allowing AI agents to move beyond chat windows and directly interact with applications...
What is CopilotKit?
CopilotKit is open source.AI native applicationsFront-end operating system. The tool supports three generative UI modes: controlled, declarative A2UI, and open, allowing the AI agent to move beyond the chat box and generate interactive interfaces directly within the application in real time. The team has launched the AG-UI protocol, enabling bidirectional state synchronization, Human-in-the-Loop, persistent threads, and other features, allowing for seamless integration across multiple platforms with a single integration.
Main functions of CopilotKit
- Three Generative UI Modes
-
Controlled modeDevelopers predefine React components, and the Agent is only responsible for selecting components and populating data to ensure complete consistency in brand style.
-
Declarative pattern (A2UI)The Agent outputs a JSON schema, which is automatically mapped to components by the front end. This is suitable for covering long-tail, low-frequency functions without having to write code manually.
-
Open-ended modeThe agent directly generates HTML or drives tools such as Excalidraw, making it suitable for one-off exploratory visualization scenarios.
-
- Bidirectional state synchronizationThe Agent can directly modify the state, enabling real-time two-way binding between the front end and the Agent.
- Human-in-the-LoopThe agent can pause at critical execution points, display a confirmation dialog box requesting user approval before continuing the operation.
- Persistent ThreadsAll conversations, states, and generated UI elements are automatically persisted, allowing users to seamlessly resume from where they left off the next time they open the application.
- AG-UI protocol full-stack integrationAs an industry-standard protocol, it supports writing agent logic once and running it simultaneously on multiple platforms such as Web, Mobile, and Slack.
CopilotKit's technical principles
- AG-UI Protocol LayerThe protocol defines the real-time communication standard between the AI Agent and the user interface. Through standardized message formats and event flows, the tool enables the Agent to directly generate structured UI commands, achieving a paradigm shift from dialogue to a user interface.
- Three Generative UI Rendering MechanismsControlled mode uses a pre-registered React component mapping table, allowing LLM to return only the component ID and data payload when invoked by tools, with the front end executing according to a fixed rendering pipeline; A2UI declarative mode outputs UI descriptions conforming to a JSON schema by the Agent, and the front end maps the schema to interactive elements through a dynamic component resolver at runtime; Open mode can directly render HTML strings generated by the Agent or sandboxed iframes.
- Bidirectional state synchronization architectureFrontend through
useAgentOnce the Hook establishes a WebSocket or SSE long connection with the CopilotKit Runtime, the application state is exposed to the Agent in the form of a shared state tree. The Agent reads the state snapshot through the protocol layer, executes tool calls, and writes back the state changes. The frontend subscribes to the state diff and automatically re-renders, forming a closed loop. - Human-in-the-Loop interruption mechanismThe Runtime inserts an Interrupt Node into the execution chain. When the Agent calls a tool requiring manual confirmation, the execution flow pauses and sends an Interrupt Event to the front end, rendering the approval UI. After user confirmation, the front end sends the approval result (Approval/Rejection) back to the Runtime, the execution flow resumes, and the Agent continues with subsequent steps.
- Persistent Threads and Session ManagementAll conversation messages, intermediate states, generated UI nodes, and user approval records are persisted to the storage layer by Thread ID. When a user reconnects, the Runtime loads the complete context based on the Thread ID, and the Agent resumes execution from the breakpoint state, achieving continuity across sessions.
How to use CopilotKit
- New projects launched quickly:implement
npx copilotkit@latest create -f <framework>Create template projects with CopilotKit with one click. - Integration of existing projects:implement
npx copilotkit@latest initAutomatically install core packages, configure the Provider, and connect the Agent and UI. - Access Agent Status:use
useAgentHooks read and modify Agent state, for exampleagent.state.cityandagent.setState(). - Define Copilot ActionsRegister existing API calls or business functions as LLM-callable actions to achieve a closed loop for tool calls.
- Deployment and launchOnce configured, it can be deployed directly, supporting self-hosting or CopilotKit Cloud Enterprise Edition.
CopilotKit's core advantages
-
Protocol-level standardsThe team is the creator of the AG-UI protocol, which has been adopted by giants such as Google, Microsoft, Amazon, LangChain, and Mastra, and has strong ecosystem compatibility.
-
Three UI modes cover all scenariosFrom strictly controlled to fully open, it meets the dual needs of different businesses for brand consistency and flexibility.
-
Deep integration of front-end statusUnlike ordinary chat components, CopilotKit can synchronize bidirectionally with the application's internal state.
-
Production-grade Human-in-the-LoopThe built-in approval workflow mechanism allows agents to proactively request human confirmation before critical operations, reducing risks.
-
Cross-platform integrationBased on the AG-UI protocol, the same Agent logic can run simultaneously on Web, mobile, and Slack channels.
CopilotKit project address
- GitHub repositoryhttps://github.com/CopilotKit/CopilotKit
Comparison of CopilotKit and similar competing products
| Comparison Dimensions | CopilotKit | Assistant-ui |
|---|---|---|
| Core positioning | Full-stack Agent UI infrastructure (frontend components + runtime + protocol) | An open-source React component library, focusing on AI chat interfaces. |
| UI generation method | Agent actively generates interfaces: supports three modes: controlled components, A2UI JSON mapping, and open HTML. | Static pre-built components: Thread, Message, Composer, Suggestion, etc.; the Agent does not generate new UI. |
| State Management | Two-way deep synchronization: The agent can read and write the application's internal state, and the front end responds automatically. | One-way message flow: Primarily manages the list of conversation messages; application state requires manual bridging. |
| Human-in-the-Loop | Native interruption of execution flow: Agent pauses → Rendering approval UI → User confirmation → Automatic resumption | Message-level interception: Allows insertion of custom message content, but lacks flow control mechanism. |
| Backend coupling | It comes with its own runtime and is deeply integrated with LangGraph, Mastra, CrewAI, etc. | Pure front-end, requires independent integration with back-end systems such as OpenAI, LangChain, and Convex. |
| persistence | Built-in thread persistence (memory/Redis/database), with breakpoint resume functionality. | It relies on an external backend and does not provide a storage layer itself. |
| Tool call rendering | Automatically generate corresponding interactive components (forms, buttons, charts, etc.) | The basic display tool calls names and parameters, without dynamic interactive components. |
| Protocol Standard | AG-UI protocol creator, defines Agent-UI interaction standards. | It follows a common message format and has no proprietary protocol. |
| Start-up cost | Intermediate level: Requires understanding of Runtime, Actions, and the three UI modes. | Lower level: Pure React components, simply assemble according to the documentation. |
| Applicable Scenarios | Embedding hands-on intelligent Copilot in complex SaaS | Quickly build a standard AI chatbot interface |
Application scenarios of CopilotKit
-
Copilot embedded in SaaS productsEmbed AI assistants in existing products such as CRM, ERP, and data analysis backends, allowing users to directly operate complex functions through dialogue.
-
AI native application developmentBuild a new generation of applications centered around an Agent, which can generate interactive interfaces such as forms, dashboards, and calendars in real time.
-
Long-tail function automationThe A2UI model allows the Agent to automatically generate interfaces for low-frequency functions (such as invoice requests and equipment reservations), reducing development manpower.
-
Cross-platform Agent DeploymentBased on the AG-UI protocol, the same agent can be deployed simultaneously to web applications, mobile devices, and Slack bots.