CopilotKit
Reference / core

@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

Quick start

import { CopilotKitCore } from "@copilotkit/core";

const copilotkit = new CopilotKitCore({
  runtimeUrl: "/api/copilotkit",
});

// Register a frontend tool the agent can call.
copilotkit.addTool({
  name: "showAlert",
  handler: ({ message }: { message: string }) => {
    window.alert(message);
  },
});

// Agents populate after the runtime responds. In real apps, react via
// `copilotkit.subscribe({ onAgentsChanged })`; here we assume it's ready.
const agent = copilotkit.getAgent("default");
if (agent) {
  await copilotkit.runAgent({ agent });
}

Reference