Loading...
Loading...
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.
npx skill4agent add nihalnihalani/copilotkit-skill copilotkit@copilotkitnext/angular+---------------------------------------------------------+
| Frontend Layer |
| @copilotkit/react-core - Provider, hooks |
| @copilotkit/react-ui - Chat components, styles |
+-------------------+-------------------------------------+
| AG-UI Protocol (HTTP event streaming)
+-------------------v-------------------------------------+
| Backend Layer |
| @copilotkit/runtime - CopilotRuntime |
| LLM Adapters: OpenAI, Anthropic, Google, Groq, etc |
+-------------------+-------------------------------------+
| HTTP (AG-UI events)
+-------------------v-------------------------------------+
| Agent Layer (optional) |
| copilotkit (Python SDK) - LangGraph, CrewAI, etc |
| Or: Google ADK, AWS Strands, Microsoft Agent FW, etc |
+---------------------------------------------------------+npx copilotkit@latest create -f nextnpm install @copilotkit/react-core @copilotkit/react-ui @copilotkit/runtime# .env.local
OPENAI_API_KEY="sk-..."
# or ANTHROPIC_API_KEY, GOOGLE_API_KEY, GROQ_API_KEYapp/api/copilotkit/route.tsimport {
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);
};layout.tsximport { 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>
);
}page.tsximport { 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?" }}
/>
</>
);
}useCopilotReadableuseCopilotReadable({
description: "Current user profile and preferences",
value: { name: user.name, role: user.role, preferences },
});useCopilotActionuseCopilotAction({
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`;
},
});useCopilotChatconst { appendMessage, stopGeneration, reset, reloadMessages } = useCopilotChat();useCopilotAdditionalInstructionsuseCopilotAdditionalInstructions({
instructions: "User is on the settings page. Help them configure preferences.",
});useCopilotChatSuggestionsuseCopilotChatSuggestions({
instructions: "Suggest actions based on the current app state.",
});useAgentconst { state, setState, run, stop } = useAgent({ name: "my_agent" });useAgentuseCoAgentuseCoAgentuseAgentCopilotTaskimport { CopilotTask } from "@copilotkit/react-core";
const task = new CopilotTask({ instructions: "Summarize the data" });
await task.run(context);| Component | Import | Use case |
|---|---|---|
| | Embedded inline chat panel |
| | Collapsible sidebar chat |
| | Floating popup chat |
| | AI-powered textarea drop-in |
instructionslabelssuggestionsobservabilityHooks| Prop | Type | Purpose |
|---|---|---|
| | Self-hosted runtime endpoint |
| | Copilot Cloud API key |
| | Custom auth headers |
| | Cookie handling ( |
| | Default agent name |
| | Thread metadata, authorization |
| | Error handler callback |
| | Dev error banners |
| | Debugging inspector tool |
| | Custom renderers (A2UI, etc.) |
| Protocol | Purpose | Package |
|---|---|---|
| AG-UI | Agent <-> User interaction, event streaming | |
| MCP | Agent <-> External tools | MCP server integration |
| A2A | Agent <-> Agent communication | A2A protocol support |
OpenAIAdapterAnthropicAdapterGoogleGenerativeAIAdapterGroqAdapterLangChainAdapterOpenAIAssistantAdapter| Package | Purpose |
|---|---|
| Provider + all hooks |
| Chat UI components + styles |
| Backend runtime + LLM adapters + framework endpoints |
| Python SDK for LangGraph/CrewAI agents |
| Angular SDK (Angular 18+19) |
| AG-UI protocol types/events |
| AG-UI client implementation |
onError<CopilotKit
runtimeUrl="/api/copilotkit"
onError={(error) => {
console.error("CopilotKit error:", error);
toast.error("AI assistant encountered an error");
}}
>"failed"status === "failed"render: ({ status, args, result }) => {
if (status === "failed") return <ErrorCard message="Tool execution failed" />;
// ...
}| Exception | Meaning |
|---|---|
| Requested action not registered |
| Requested agent not found in endpoint |
/v2@copilotkitnext/*@copilotkitnext/angular| Don't | Do Instead |
|---|---|
| Put API keys in client-side code | Use server-side env vars + runtime endpoint |
| Create a new CopilotRuntime per request | Instantiate once, reuse across requests |
Skip | Always handle "inProgress", "complete", "failed" |
Use | Prefer |
| Hardcode instructions in every component | Use |
| Forget to import styles | Add |
Mix | Pick one deployment mode unless you need hybrid |
| Put heavy computation in action handlers | Return data from handlers, compute in render |
| Want to... | Use |
|---|---|
| Show a chat bubble | |
| Give LLM app context | |
| Let LLM call functions | |
| Render UI from tool calls | |
| Default fallback tool renderer | |
| Sync state bidirectionally | |
| Use v2 agent state sync | |
| Show agent progress | |
| Ask user for approval | |
| Handle LangGraph interrupts | |
| Control chat programmatically | |
| Run one-off tasks | |
| Connect Python agent | |
| Scaffold AG-UI app | |
| Persist conversations | Thread model + StorageRunners |