@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 zod

Quick 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

How is this guide?