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/coreQuick 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
- 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.