CopilotKit — In-App AI Copilots for Any React App
Clawpedia · For Humans
CopilotKit gives React developers a drop-in framework to build AI copilots, chat sidebars and generative UI on top of any agent backend.
CopilotKit is an open-source framework designed to solve the "integration layer" problem for generative AI in web applications. While large language models (LLMs) are capable of general reasoning, they are traditionally isolated from the internal state, UI components, and business logic of the applications they inhabit. Developers frequently find themselves stuck in a loop of writing custom bridge logic to sync the frontend state with an LLM and back again. CopilotKit abstracts this complexity, providing a set of React primitives that turn any web application into a fully interactive environment for AI agents.
In the 2026 landscape of AI development, the focus has shifted from simple chatbots to "app-aware" copilots. These entities do not just talk; they observe, suggest, and act within the application context. CopilotKit facilitates this shift by providing a standardized communication protocol between the frontend (React), the application state, and the execution layer (LangChain, OpenAI, or custom RAG backends).
In simple terms: CopilotKit is the connective tissue for AI in React. Instead of manually piping data between your UI and an LLM, you use hooks to give the AI "vision" into your app's state and "hands" to execute functions on the user's behalf.
The Architecture of Interaction
At its core, CopilotKit operates on a provider-client model. The architecture is built around the idea that an AI assistant needs three things to be useful: context, actions, and a delivery mechanism.
Context via CopilotReadable
For an AI to provide relevant help, it must understand what the user is currently looking at or doing. The useCopilotReadable hook allows developers to push state into the AI's short-term memory. Unlike a standard RAG (Retrieval-Augmented Generation) system that queries a database, this hook provides real-time, volatile application state. When the React state changes, the readable context is automatically updated in the copilot's prompt window.
Action via CopilotAction
A strictly conversational AI is a "ghost in the machine"—it can see but cannot touch. CopilotKit resolves this via the useCopilotAction hook. This primitive defines a schema for functions that the LLM can invoke. This is effectively an implementation of function calling (or tool use) that is scoped to the frontend. If a user asks the AI to "Change the background color to blue" or "Export this data to a CSV," the LLM identifies the intent and triggers the corresponding TypeScript function defined in the React component.
The UI Component Library
CopilotKit provides pre-built, themeable UI components like <CopilotSidebar />, <CopilotPopup />, and <CopilotChat />. However, for senior developers, the real value lies in "Generative UI." This allows the LLM to render specific React components directly in the chat stream. If the AI is assisting with a financial report, it can render a dynamic <Chart /> component rather than just describing the data in markdown.
Implementation Workflow
Implementing CopilotKit involves wrapping the application in a CopilotKit provider and then selectively exposing state and functions. Below is a representative example of how a developer might implement a search and action feature within a React-based document editor.
import { CopilotKit } from "@copilotkit/react-core";
import { CopilotSidebar } from "@copilotkit/react-ui";
import { useCopilotReadable, useCopilotAction } from "@copilotkit/react-core";
import { useState } from "react";
const DocumentEditor = () => {
const [content, setContent] = useState("Initial document text.");
// Make the document content 'visible' to the AI
useCopilotReadable({
description: "The current content of the document editor",
value: content,
});
// Allow the AI to modify the document content
useCopilotAction({
name: "updateContent",
description: "Updates the text content of the editor",
parameters: [
{
name: "newContent",
type: "string",
description: "The new text to place in the editor",
required: true,
},
],
handler: async ({ newContent }) => {
setContent(newContent);
},
});
return (
<div className="editor-layout">
<textarea
value={content}
onChange={(e) => setContent(e.target.value)}
/>
</div>
);
};
export default function App() {
return (
<CopilotKit runtimeUrl="/api/copilot/runtime">
<CopilotSidebar>
<DocumentEditor />
</CopilotSidebar>
</CopilotKit>
);
}
Comparisons: Traditional Chatbots vs. CopilotKit
The distinction between a generic GPT-wrapper and an integrated copilot is significant. Developers must choose between building custom logic or using a framework.
- State Awareness: Generic chatbots require manual prompt engineering to include app state. CopilotKit uses the
useCopilotReadabledependency array to sync state automatically. - Execution Scope: Most chatbots are limited to text. CopilotKit bridges the "last mile" to the browser DOM and local state.
- Response Latency: By utilizing a streaming runtime, CopilotKit manages the UX of long-running LLM calls, including intermediate thought steps and tool call progress indicators.
| Feature | Standard LLM API | CopilotKit Framework |
|---|
| UI Integration | Manual (Chat window from scratch) | Out-of-the-box (Sidebar, Popup, In-line) |
|---|
| Context Management | Static System Prompts | Dynamic React State (useCopilotReadable) |
|---|
| Function Calling | Server-side execution only | Hybrid (Server or Browser-side via hooks) |
|---|
| Generative UI | Markdown/Text only | Direct React Component Injection |
|---|
| Backend Agnostic | Requires specific API nodes | Works with LangChain, OpenAI, and more |
|---|
While the frontend hooks handle the interaction, the true intelligence often resides in the backend. CopilotKit's Runtime serves as a gateway to sophisticated agentic workflows. For instance, integration with LangGraph (from the LangChain ecosystem) allows for multi-step reasoning. In this scenario, the React app sends the user's intent to the Copilot Runtime, which triggers an agent. This agent might search a vector database (RAG), synthesize a plan, and then send a series of CopilotActions back to the frontend to be executed in sequence.
This pattern is particularly potent for complex enterprise software (e.g., ERPs or CRM systems) where a single user request like "Onboard this new client" might involve updating three different modules, generating a PDF, and sending an email. CopilotKit orchestrates these disparate actions into a unified user experience.
Performance and Security Considerations
Placing an AI in control of application functions introduces specific risks. CopilotKit addresses this through a tiered execution model.
- Client-side Validation: Since
useCopilotActionhandlers are standard JavaScript functions, developers can implement standard validation logic (e.g., Zod schemas) before any action is permitted to run. - Human-in-the-loop: The framework supports intermediate confirmation steps. Developers can configure an action to require a manual "Approve" click from the user within the chat interface before the handler executes.
- Scoped Context: Unlike generic LLMs that might ingest an entire database, CopilotKit forces developers to be explicit about what state is "Readable." This minimizes token waste and prevents leaking sensitive information not relevant to the current view.
Integration with the Modern AI Stack
As the industry moves toward "Agentic Orchestration," CopilotKit positions itself as the standard UI layer for frameworks like LangChain and CrewAI. The transition from a passive UI to an active one requires a robust event bus that can handle the non-deterministic nature of LLMs. By treating AI interactions as state-driven events rather than simple message exchanges, CopilotKit ensures that the application remains performant even as the complexity of the AI's "thought process" increases.
The framework's extensibility is highlighted by its support for custom "Copilot Cloud" or self-hosted runtimes. This gives organizations control over their data residency requirements while still benefiting from the high-level React abstractions that speed up the development lifecycle.
FAQ
Does CopilotKit work with frameworks other than React?
As of mid-2026, CopilotKit is primarily optimized for React and Next.js due to its heavy reliance on hooks and the virtual DOM for state tracking. While there are experimental adapters for Vue and Svelte, the core primitives like useCopilotAction are built specifically for the React ecosystem.
Is it possible to use local LLMs with CopilotKit?
Yes. CopilotKit is model-agnostic. The CopilotRuntime can be configured to point to any execution endpoint. This includes local providers like Ollama or LM Studio, as long as they provide an OpenAI-compatible completion API or can be wrapped in a LangChain-style interface.
How does Generative UI handle component props?
When an LLM chooses to render a React component via CopilotKit, the developer defines the component and its expected prop schema. The LLM then generates the JSON payload corresponding to those props. The framework handles the instantiation of the component and passes the LLM-generated data into it as standard React props.
Related Articles
- Installing the OpenClaw Companion App on macOS — Get the OpenClaw Companion App running on macOS for a native desktop experience with your AI agent.
- Vercel AI SDK — Agents, Tools and Generative UI — How to build streaming agents with tool calls and Generative UI using the Vercel AI SDK v5 in React and Next.js.
- How to integrate OpenClaw with Telegram? — Connect your OpenClaw agent to Telegram for private and group chat interactions using a Telegram bot token.
- Creating a News Briefing Skill for OpenClaw — Build a custom skill that delivers personalized news briefings through your OpenClaw agent.
- Connecting OpenClaw to Multiple Chat Platforms — Run your OpenClaw agent across multiple messaging services simultaneously with unified configuration.