Loading...
Loading...
Use when building AI-powered features with CopilotKit v2 -- adding chat interfaces, registering frontend tools, sharing application context with agents, handling agent interrupts, and working with the CopilotKit runtime.
npx skill4agent add copilotkit/skills copilotkit-developcopilotkit-docssearch-docssearch-code.mcp.json@ag-ui/client@ag-ui/core@copilotkit/runtime@copilotkit/core@copilotkit/react@ag-ui/clientCopilotRuntimeCopilotSseRuntimeCopilotIntelligenceRuntimecreateCopilotEndpointcreateCopilotEndpointExpressimport { CopilotRuntime, createCopilotEndpoint } from "@copilotkit/runtime";
import { LangGraphAgent } from "@ag-ui/langgraph";
const runtime = new CopilotRuntime({
agents: {
myAgent: new LangGraphAgent({ /* ... */ }),
},
});
const app = createCopilotEndpoint({
runtime,
basePath: "/api/copilotkit",
});import { CopilotKitProvider } from "@copilotkit/react";
function App() {
return (
<CopilotKitProvider runtimeUrl="/api/copilotkit">
<YourApp />
</CopilotKitProvider>
);
}<CopilotChat><CopilotPopup><CopilotSidebar>import { CopilotChat } from "@copilotkit/react";
function ChatPage() {
return <CopilotChat agentId="myAgent" />;
}import { useFrontendTool } from "@copilotkit/react";
import { z } from "zod";
useFrontendTool({
name: "highlightCell",
description: "Highlight a spreadsheet cell",
parameters: z.object({ row: z.number(), col: z.number() }),
handler: async ({ row, col }) => {
highlightCell(row, col);
return "done";
},
});import { useAgentContext } from "@copilotkit/react";
useAgentContext({
description: "The user's current shopping cart",
value: cart, // any JSON-serializable value
});import { useInterrupt } from "@copilotkit/react";
useInterrupt({
render: ({ event, resolve }) => (
<div>
<p>{event.value.question}</p>
<button onClick={() => resolve({ approved: true })}>Approve</button>
</div>
),
});import { useRenderTool } from "@copilotkit/react";
import { z } from "zod";
useRenderTool({
name: "searchDocs",
parameters: z.object({ query: z.string() }),
render: ({ status, parameters, result }) => {
if (status === "executing") return <Spinner>Searching {parameters.query}...</Spinner>;
if (status === "complete") return <Results data={result} />;
return <div>Preparing...</div>;
},
}, []);| Hook | Purpose |
|---|---|
| Register a tool the agent can call in the browser |
| Register a React component as a chat-rendered tool (convenience wrapper around |
| Share JSON-serializable application state with the agent |
| Get the |
| Handle |
| Register a tool that pauses execution until the user responds via a rendered UI |
| Register a renderer for tool calls (by name or wildcard |
| Register a wildcard |
| Internal hook returning a function to resolve the correct renderer for a given tool call |
| Internal hook for rendering activity messages by type |
| Internal hook for rendering custom message decorators |
| Read the current suggestion list and control reload/clear |
| Register static or dynamic (LLM-generated) suggestion configs |
| List, rename, archive, and delete Intelligence platform threads |
| Component | Purpose |
|---|---|
| Root provider -- configures runtime URL, headers, agents, error handler |
| Full chat interface connected to an agent (inline layout) |
| Chat in a floating popup with toggle button |
| Chat in a collapsible sidebar with toggle button |
| Headless chat view with slots for message view, input, scroll, suggestions |
| Chat input textarea with send/stop/transcribe controls |
| Renders the message list |
| Renders suggestion pills |
| Export | Purpose |
|---|---|
| Auto-detecting runtime (delegates to SSE or Intelligence) |
| Explicit SSE-mode runtime |
| Intelligence-mode runtime with durable threads |
| Create a Hono app with all CopilotKit routes |
| Create an Express router with all CopilotKit routes |
| Intelligence platform client configuration |