copilotkit

Build AI copilots, chatbots, and agentic UIs in React and Next.js using CopilotKit. Use this skill when the user wants to add an AI assistant, copilot, chat interface, AI-powered textarea, or agentic UI to their app. Covers setup, hooks (useCopilotAction, useCopilotReadable, useCoAgent, useAgent), chat components (CopilotPopup, CopilotSidebar, CopilotChat), generative UI, human-in-the-loop, CoAgents with LangGraph, AG-UI protocol, MCP Apps, and Python SDK integration. Triggers on CopilotKit, copilotkit, useCopilotAction, useCopilotReadable, useCoAgent, useAgent, CopilotRuntime, CopilotChat, CopilotSidebar, CopilotPopup, CopilotTextarea, AG-UI, agentic frontend, in-app AI copilot, AI assistant React, chatbot React, useFrontendTool, useRenderToolCall, useDefaultTool, useCoAgentStateRender, useLangGraphInterrupt, useCopilotChat, useCopilotAdditionalInstructions, useCopilotChatSuggestions, useHumanInTheLoop, CopilotTask, copilot runtime, LangGraphAgent, BasicAgent, BuiltInAgent, CopilotKitRemoteEndpoint, A2UI, MCP Apps, AI textarea, AI form completion, add AI to React app.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "copilotkit" with this command: npx skills add nihalnihalani/copilotkit-skill/nihalnihalani-copilotkit-skill-copilotkit

CopilotKit

Full-stack open-source framework (MIT, v1.51.3, Python SDK v0.1.78) for building agentic applications with AI copilots embedded directly in React and Angular UIs. Angular support via @copilotkitnext/angular (Angular 18+19). 28k+ GitHub stars.

When to Use This Skill

  • User wants to add an AI copilot, assistant, or chatbot to a React/Next.js app
  • User is working with CopilotKit hooks, components, or runtime
  • User asks about AI-powered text areas or form completion
  • User needs to connect a Python agent (LangGraph/CrewAI) to a React frontend
  • User is implementing human-in-the-loop or generative UI patterns
  • User asks about AG-UI protocol or MCP Apps
  • User wants to sync state between a UI and an AI agent

Architecture

┌─────────────────────────────────────────────────────────────────┐
│                                                                 │
│   F R O N T E N D    @copilotkit/react-core + react-ui          │
│                                                                 │
│   ┌──────────────────┐  ┌──────────────────┐  ┌──────────────┐ │
│   │  <CopilotPopup>  │  │ <CopilotSidebar> │  │ <CopilotChat>│ │
│   │  <CopilotTextarea>│  │   Headless UI    │  │  Custom UI   │ │
│   └────────┬─────────┘  └────────┬─────────┘  └──────┬───────┘ │
│            └──────────────┬──────┘                    │         │
│                           ▼                           │         │
│   ┌───────────────────────────────────────────────────┘         │
│   │  React Hooks                                                │
│   │  ├─ useCopilotAction()       → Define callable tools        │
│   │  ├─ useCopilotReadable()     → Expose app state to LLM     │
│   │  ├─ useAgent()               → Bidirectional state (v2)    │
│   │  ├─ useFrontendTool()        → Generative UI rendering     │
│   │  ├─ useCopilotChat()         → Headless chat control       │
│   │  └─ useLangGraphInterrupt()  → Human-in-the-loop           │
│   └─────────────────────────┬───────────────────────────────────│
│                             │                                   │
└─────────────────────────────┼───────────────────────────────────┘
                              │
                    ┌─────────▼─────────┐
                    │    AG-UI Protocol  │
                    │  (HTTP event stream│
                    │   17 event types)  │
                    └─────────┬─────────┘
                              │
┌─────────────────────────────┼───────────────────────────────────┐
│                             │                                   │
│   B A C K E N D    @copilotkit/runtime                          │
│                             ▼                                   │
│   ┌─────────────────────────────────────────────────────────┐   │
│   │  CopilotRuntime                                         │   │
│   │  ┌──────────────┐ ┌───────────────┐ ┌────────────────┐ │   │
│   │  │ LLM Adapters │ │ Backend       │ │ Thread         │ │   │
│   │  │ OpenAI       │ │ Actions       │ │ Persistence    │ │   │
│   │  │ Anthropic    │ │ (server-side  │ │ InMemory /     │ │   │
│   │  │ Google       │ │  tools)       │ │ SQLite         │ │   │
│   │  │ Groq         │ │               │ │                │ │   │
│   │  └──────────────┘ └───────────────┘ └────────────────┘ │   │
│   │  ┌──────────────────────────────────────────────────┐   │   │
│   │  │ Agent Router                                     │   │   │
│   │  │ ├─ BuiltInAgent   (direct LLM + middleware)      │   │   │
│   │  │ ├─ BasicAgent     (lightweight, no middleware)    │   │   │
│   │  │ └─ CustomHttpAgent (remote Python/JS agents) ────┼───┼─┐ │
│   │  └──────────────────────────────────────────────────┘   │ │ │
│   └─────────────────────────────────────────────────────────┘ │ │
│                                                               │ │
└───────────────────────────────────────────────────────────────┼─┘
                                                                │
                    ┌───────────────────┐                       │
                    │    AG-UI / HTTP    │◄──────────────────────┘
                    └─────────┬─────────┘
                              │
┌─────────────────────────────┼───────────────────────────────────┐
│                             ▼                                   │
│   A G E N T   L A Y E R   (optional, any AG-UI framework)      │
│                                                                 │
│   Python: copilotkit SDK v0.1.78 + FastAPI / Flask              │
│                                                                 │
│   ┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────────┐  │
│   │ LangGraph  │ │  CrewAI    │ │ Google ADK │ │ AWS Strands│  │
│   └────────────┘ └────────────┘ └────────────┘ └────────────┘  │
│   ┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────────┐  │
│   │  Mastra    │ │ PydanticAI │ │    AG2     │ │ LlamaIndex │  │
│   └────────────┘ └────────────┘ └────────────┘ └────────────┘  │
│                                                                 │
│   Protocols:  AG-UI (↔ user)  ·  MCP (↔ tools)  ·  A2A (↔ agents)│
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Quick Start

New project

npx copilotkit@latest create -f next

Existing project

npm install @copilotkit/react-core @copilotkit/react-ui @copilotkit/runtime

Environment

# .env.local
OPENAI_API_KEY="sk-..."
# or ANTHROPIC_API_KEY, GOOGLE_API_KEY, GROQ_API_KEY

Backend API route (app/api/copilotkit/route.ts)

import {
  CopilotRuntime,
  OpenAIAdapter, // or AnthropicAdapter, GoogleGenerativeAIAdapter, GroqAdapter, LangChainAdapter
  copilotRuntimeNextJSAppRouterEndpoint,
} from "@copilotkit/runtime";
import { NextRequest } from "next/server";

const serviceAdapter = new OpenAIAdapter({ model: "gpt-4o" });
const runtime = new CopilotRuntime();

export const POST = async (req: NextRequest) => {
  const { handleRequest } = copilotRuntimeNextJSAppRouterEndpoint({
    runtime,
    serviceAdapter,
    endpoint: "/api/copilotkit",
  });
  return handleRequest(req);
};

Frontend provider (layout.tsx)

import { CopilotKit } from "@copilotkit/react-core";
import "@copilotkit/react-ui/styles.css";

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        <CopilotKit runtimeUrl="/api/copilotkit">
          {children}
        </CopilotKit>
      </body>
    </html>
  );
}

Chat UI (page.tsx)

import { CopilotPopup } from "@copilotkit/react-ui"; // or CopilotSidebar, CopilotChat

export default function Home() {
  return (
    <>
      <YourApp />
      <CopilotPopup
        instructions="You are an AI assistant for this app."
        labels={{ title: "Assistant", initial: "How can I help?" }}
      />
    </>
  );
}

Core Hooks

useCopilotReadable -- Expose app state to LLM

useCopilotReadable({
  description: "Current user profile and preferences",
  value: { name: user.name, role: user.role, preferences },
});

useCopilotAction -- Define executable actions

useCopilotAction({
  name: "addItem",
  description: "Add a new item to the list",
  parameters: [
    { name: "title", type: "string", required: true },
    { name: "priority", type: "string", description: "low, medium, or high" },
  ],
  handler: async ({ title, priority = "medium" }) => {
    setItems(prev => [...prev, { id: Date.now().toString(), title, priority }]);
    return `Added "${title}" with ${priority} priority`;
  },
});

useCopilotChat -- Programmatic chat control

const { appendMessage, stopGeneration, reset, reloadMessages } = useCopilotChat();

useCopilotAdditionalInstructions -- Dynamic context-aware prompts

useCopilotAdditionalInstructions({
  instructions: "User is on the settings page. Help them configure preferences.",
});

useCopilotChatSuggestions -- Auto-generate suggestions from app state

useCopilotChatSuggestions({
  instructions: "Suggest actions based on the current app state.",
});

useAgent -- v2 agent state sync (superset of useCoAgent)

const { state, setState, run, stop } = useAgent({ name: "my_agent" });

useAgent is the v2 replacement for useCoAgent. It includes all useCoAgent functionality plus time-travel debugging and improved state management. Prefer useAgent for new projects.

CopilotTask -- Run one-off programmatic tasks

import { CopilotTask } from "@copilotkit/react-core";

const task = new CopilotTask({ instructions: "Summarize the data" });
await task.run(context);

Advanced Patterns

Detailed guides organized by topic -- load only what's needed:

UI Components

ComponentImportUse case
CopilotChat@copilotkit/react-uiEmbedded inline chat panel
CopilotSidebar@copilotkit/react-uiCollapsible sidebar chat
CopilotPopup@copilotkit/react-uiFloating popup chat
CopilotTextarea@copilotkit/react-uiAI-powered textarea drop-in

All accept instructions, labels, suggestions, custom message/input components, and observabilityHooks.

CopilotKit Provider Props

PropTypePurpose
runtimeUrlstringSelf-hosted runtime endpoint
publicApiKeystringCopilot Cloud API key
headersobjectCustom auth headers
credentialsstringCookie handling ("include" for cross-origin)
agentstringDefault agent name
propertiesobjectThread metadata, authorization
onErrorfunctionError handler callback
showDevConsolebooleanDev error banners
enableInspectorbooleanDebugging inspector tool
renderActivityMessagesarrayCustom renderers (A2UI, etc.)

Agent Protocols

ProtocolPurposePackage
AG-UIAgent <-> User interaction, event streaming@ag-ui/core, @ag-ui/client
MCPAgent <-> External toolsMCP server integration
A2AAgent <-> Agent communicationA2A protocol support

Supported Agent Frameworks

LangGraph, CrewAI, Google ADK, AWS Strands, Microsoft Agent Framework, Mastra, PydanticAI, AG2, LlamaIndex, Agno, VoltAgent, Blaxel.

LLM Adapters

OpenAIAdapter, AnthropicAdapter, GoogleGenerativeAIAdapter, GroqAdapter, LangChainAdapter, OpenAIAssistantAdapter.

Key Packages

PackagePurpose
@copilotkit/react-coreProvider + all hooks
@copilotkit/react-uiChat UI components + styles
@copilotkit/runtimeBackend runtime + LLM adapters + framework endpoints
copilotkit (Python)Python SDK for LangGraph/CrewAI agents
@copilotkitnext/angularAngular SDK (Angular 18+19)
@ag-ui/coreAG-UI protocol types/events
@ag-ui/clientAG-UI client implementation

Error Handling

Frontend onError callback

<CopilotKit
  runtimeUrl="/api/copilotkit"
  onError={(error) => {
    console.error("CopilotKit error:", error);
    toast.error("AI assistant encountered an error");
  }}
>

Tool render "failed" status

All render functions receive status === "failed" when a tool errors. Always handle this:

render: ({ status, args, result }) => {
  if (status === "failed") return <ErrorCard message="Tool execution failed" />;
  // ...
}

Python SDK exception types

ExceptionMeaning
ActionNotFoundExceptionRequested action not registered
AgentNotFoundExceptionRequested agent not found in endpoint

Versioning

Current version: v1.51.3 (Python SDK v0.1.78). The v2 runtime interface is available at the /v2 path. Next-generation packages use the @copilotkitnext/* namespace (e.g., @copilotkitnext/angular).

Common Anti-Patterns

Don'tDo Instead
Put API keys in client-side codeUse server-side env vars + runtime endpoint
Create a new CopilotRuntime per requestInstantiate once, reuse across requests
Skip status checks in render functionsAlways handle "inProgress", "complete", "failed"
Use useCoAgent for new projectsPrefer useAgent (v2 superset with time travel)
Hardcode instructions in every componentUse useCopilotAdditionalInstructions for page-specific context
Forget to import stylesAdd import "@copilotkit/react-ui/styles.css" in layout
Mix runtimeUrl and publicApiKey without reasonPick one deployment mode unless you need hybrid
Put heavy computation in action handlersReturn data from handlers, compute in render

Common Patterns Cheat Sheet

Want to...Use
Show a chat bubble<CopilotPopup>
Give LLM app contextuseCopilotReadable()
Let LLM call functionsuseCopilotAction()
Render UI from tool callsuseFrontendTool() or useRenderToolCall()
Default fallback tool rendereruseDefaultTool()
Sync state bidirectionallyuseCoAgent()
Use v2 agent state syncuseAgent() (superset of useCoAgent)
Show agent progressuseCoAgentStateRender()
Ask user for approvaluseHumanInTheLoop()
Handle LangGraph interruptsuseLangGraphInterrupt()
Control chat programmaticallyuseCopilotChat()
Run one-off tasksCopilotTask
Connect Python agentCopilotKitRemoteEndpoint + LangGraphAgent
Scaffold AG-UI appnpx create-ag-ui-app
Persist conversationsThread model + StorageRunners

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Security

AGENTIC AI GOLD STANDARD

The only agent framework that improves itself while you sleep. Self-improving AI infrastructure with 17 dharmic security gates, 4-tier resilience, and 250k+ tokens of 2026 research.

Registry SourceRecently Updated
2.2K5Profile unavailable
Coding

Ra Pay

Send compliant fiat USD payments via Ra Pay CLI — the first CLI-native AI payment platform

Registry SourceRecently Updated
2540Profile unavailable
Automation

Charmie CRM Lite

Lightweight CRM with SQLite – manage contacts. Upgrade to Pro for email, messaging, and more.

Registry SourceRecently Updated
541Profile unavailable
Coding

AgentScout

Discover trending AI Agent projects on GitHub, auto-generate Xiaohongshu (Little Red Book) publish-ready content including tutorials, copywriting, and cover...

Registry SourceRecently Updated
240Profile unavailable