AI

CopilotKit: The Open-Source Frontend Stack for Building In-App AI Copilots

CopilotKit is an open-source SDK with 30K stars for building full-stack agentic applications with generative UI, shared state, and human-in-the-loop workflows.

CopilotKit: The Open-Source Frontend Stack for Building In-App AI Copilots

Building AI-powered applications traditionally meant stitching together a chat UI, an AI backend, state management, and tool execution – all while ensuring the AI could actually interact with your application’s data and UI. CopilotKit solves this problem by providing a complete open-source stack for adding AI copilots to any React application, handling the complex plumbing of streaming AI responses, generative UI, and shared state so you can focus on the application logic.

With over 30,000 GitHub stars, CopilotKit has become the leading framework for building what the team calls “in-app AI.” Unlike standalone chatbots that operate in a separate window, CopilotKit’s copilots are deeply integrated into your application – they can read and modify application state, render custom UI components inside their responses, and execute actions that affect the actual application.

The magic happens through CopilotKit’s AG-UI protocol (Agentic Generative UI), an open specification for real-time communication between AI agents and UI components. This protocol enables AI to render dynamic forms, charts, and tables directly in the chat, and for user interactions with those components to flow back to the agent as context for the next action.


What Are CopilotKit’s Core Components?

CopilotKit provides a set of React components and hooks designed to work together seamlessly.

graph TD
    A[CopilotKit\nRoot Provider] --> B[CopilotSidebar\nFull Chat Interface]
    A --> C[CopilotPopup\nFloating Widget]
    A --> D[useCopilotAction\nRegister Tools]
    A --> E[useCopilotReadable\nExpose State]
    A --> F[useCopilotChat\nProgrammatic Control]
    B --> G[Your React App]
    D --> H[Backend Agent\nLangChain / OpenAI / Custom]
    E --> H
    F --> H
    H --> I[Generative UI\nRendered Components]
    I --> J[User Interactions\nFlow Back to Agent]
Component/HookPurposeConfiguration
CopilotKit (provider)Root wrapper providing AI context to appAPI endpoint, agent configuration
CopilotSidebarSidebar panel for in-depth AI conversationsPosition, width, custom header
CopilotPopupFloating chat bubble for quick interactionsPosition, trigger element
useCopilotActionRegister tools and actions the AI can invokeName, description, parameters, handler function
useCopilotReadableExpose application state to the AIDescription, state value, categories
useCopilotChatProgrammatic control over chatSend message, set context, clear history

How Does the AG-UI Protocol Work?

The AG-UI protocol is the architectural foundation that enables CopilotKit’s generative UI capabilities. It defines how AI agents and UI components communicate in real-time.

graph LR
    A[AI Agent] -->|Streams UI definition\nJSON schema| B[AG-UI Protocol]
    B -->|Renders component| C[React Component\nForm / Chart / Table]
    C -->|User interacts| D[User Input]
    D -->|Sends interaction\nback to agent| A
    A -->|Updates state| E[Application State]
    E -->|Readable by agent| A
Protocol FeatureDescription
UI streamingAgent streams component definitions as JSON during response generation
Bi-directional eventsUser interactions with rendered UI flow back to the agent
State synchronizationAgent can read and modify application state through CopilotReadable
Tool executionAgent can invoke any registered useCopilotAction tool
Response loadingAgent shows intermediate states while tools execute

The protocol is designed to be framework-agnostic. While CopilotKit’s reference implementation targets React, the protocol itself can be implemented for any UI framework. This means your backend agents built with the AG-UI protocol can potentially serve multiple frontends.


What Frameworks and Integrations Does CopilotKit Support?

CopilotKit’s integration ecosystem covers both frontend frameworks and backend AI orchestration tools.

CategorySupported Technologies
Frontend FrameworksNext.js 14/15 (App Router + Pages Router), Vite + React, Remix, plain React
AI OrchestrationLangChain, LangGraph, LangServe, OpenAI Assistants API, custom API endpoints
Vector StoresPinecone, Chroma, Weaviate, Supabase, custom vector stores
LLM ProvidersClaude (Anthropic), GPT-4o (OpenAI), Gemini (Google), local models via LangChain

How Does CopilotKit Handle State Management?

CopilotKit’s state integration is one of its most powerful features. Through the useCopilotReadable hook, you expose parts of your application state to the AI. The AI can then reference this state naturally in conversations.

State AspectHook/MethodExample
Expose state to AIuseCopilotReadable“Current cart has 3 items, total $45.20”
Register AI actionsuseCopilotAction“Add item to cart”, “Apply discount code”
Execute operationsAction handler functionAPI calls, database updates, form submissions
State syncAutomatic via React stateAI sees latest state after every change

For example, if your e-commerce app exposes the shopping cart via useCopilotReadable, the AI copilot can answer questions like “What’s in my cart?”, “What’s the total?”, and – through registered actions – “Add the blue sweater in size medium to my cart.” The application state and the AI conversation stay in sync automatically.


Why Would You Use CopilotKit Instead of Building a Custom Chat UI?

Building a custom AI chat interface requires solving a series of non-trivial problems: streaming AI responses to the UI, parsing and rendering tool calls, handling generative UI, maintaining state synchronization, and managing conversation history. CopilotKit solves all of these out of the box.

ConcernCustom BuildCopilotKit
Streaming responsesManual SSE/WebSocket handlingBuilt-in, optimized streaming
Tool executionCustom parser for tool callsDeclarative useCopilotAction
Generative UICustom protocol designAG-UI protocol included
State syncManual state managementAutomatic via useCopilotReadable
React renderingCustom chat componentsCopilotSidebar, CopilotPopup
Multi-model supportCustom adapter per modelLangChain integration

For teams building production agentic applications, CopilotKit eliminates weeks of infrastructure work and provides battle-tested patterns for the most challenging aspects of AI UI integration.


FAQ

What is CopilotKit? CopilotKit is an open-source SDK with over 30,000 GitHub stars for building full-stack agentic AI applications. It provides React components and hooks that let you add in-app AI copilots with generative UI, shared application state management, and human-in-the-loop workflows. It abstracts the complexity of streaming AI responses, tool execution, and state synchronization between the AI and your application.

What are CopilotKit’s core components? CopilotKit has four core components: CopilotSidebar (chat sidebar that can read/write app state), CopilotPopup (floating chat widget for quick AI interactions), CopilotKit (root provider wrapping your app), and hooks like useCopilotAction (register tools the AI can call), useCopilotReadable (expose app state to the AI), and useCopilotChat (programmatic chat control).

What is the AG-UI protocol? The AG-UI (Agentic Generative UI) protocol is CopilotKit’s open specification for real-time communication between AI agents and UI components. It defines how agents can render dynamic UI elements (forms, charts, tables) within chat responses, how user interactions with those elements flow back to the agent, and how the agent can read and modify application state. The protocol is framework-agnostic and designed for interoperability.

What React frameworks does CopilotKit support? CopilotKit supports all major React frameworks including Next.js (App Router and Pages Router), Vite + React, Remix, and plain React. The SDK includes framework-specific optimizations for server-side rendering, streaming, and deployment. Support for Vue, Svelte, and other frameworks is available through the community or the AG-UI protocol implementation.

What integrations does CopilotKit support? CopilotKit integrates with multiple AI providers and services. For AI orchestration, it supports LangChain, LangGraph, LangServe, OpenAI Assistants API, and custom endpoints. For vector stores and retrieval, it integrates with Pinecone, Chroma, Weaviate, and Supabase. For LLMs, it supports any model accessible through LangChain or direct API integration, including Claude, GPT-4o, Gemini, and open-source models.


Further Reading

TAG
CATEGORIES