@copilotkit/ core
Framework-agnostic TypeScript client for CopilotKit. Runs anywhere JavaScript runs.
@copilotkit/core is the framework-agnostic TypeScript client at the heart of CopilotKit. It connects to a CopilotRuntime over the AG-UI protocol, manages agents, frontend tools, shared context, and suggestions, and emits state changes to subscribers. It has no UI or React dependency, so it runs in browsers, Node, workers, and inside the React, Angular, and vanilla bindings.
Install
npm install @copilotkit/core zodQuick start
import { CopilotKitCore } from "@copilotkit/core";
import { z } from "zod";
const copilotkit = new CopilotKitCore({
runtimeUrl: "/api/copilotkit",
});
// Register a frontend tool the agent can call.
copilotkit.addTool({
name: "showAlert",
parameters: z.object({ message: z.string() }),
handler: async ({ message }) => {
window.alert(message);
return "Alert shown";
},
});
// Agents load after the runtime responds.
const sub = copilotkit.subscribe({
onAgentsChanged: async ({ agents }) => {
const agent = agents["default"];
if (!agent) return;
sub.unsubscribe();
agent.addMessage({
id: crypto.randomUUID(),
role: "user",
content: "Show an alert that says hi",
});
await copilotkit.runAgent({ agent });
},
});Reference
- CopilotKitCore: the main client class.
- ProxiedCopilotRuntimeAgent: AG-UI agent that proxies a CopilotRuntime agent.
- CopilotKitCoreConfig: options accepted by the
CopilotKitCoreconstructor. - ProxiedCopilotRuntimeAgentConfig: options accepted by the
ProxiedCopilotRuntimeAgentconstructor. - FrontendTool: shape of a tool registered with
addTool. - CopilotKitCoreSubscriber: callbacks passed to
subscribe. - Suggestion / SuggestionsConfig: suggestion data and configuration.
- ToolCallStatus: tool-call lifecycle states.
- CopilotKitCoreErrorCode: error codes surfaced through
onError. - CopilotKitCoreRuntimeConnectionStatus: runtime connection states.
How is this guide?