CopilotKitCoreSubscriber
Set of optional callbacks notified of CopilotKitCore lifecycle events.
Overview
CopilotKitCoreSubscriber is the object passed to CopilotKitCore.subscribe. Every callback is optional, receives an event object that always includes the copilotkit instance, and may return void or a Promise<void>. Use it to react to connection status, tool execution, suggestions, configuration changes, and errors.
Import
import type { CopilotKitCoreSubscriber } from "@copilotkit/core";Definition
Every callback is optional, receives an event object that always includes the
copilotkit instance, and returns void or Promise<void>. The shape below
shows the representative onRuntimeConnectionStatusChanged callback; the
Properties section documents each callback's exact event shape.
interface CopilotKitCoreSubscriber {
onRuntimeConnectionStatusChanged?: (event: {
copilotkit: CopilotKitCore;
status: CopilotKitCoreRuntimeConnectionStatus;
}) => void | Promise<void>;
// ...one optional callback per lifecycle event (tool execution, agents,
// context, suggestions, properties, headers, errors, thread stores).
// See the Properties section below for each callback's event shape.
}Properties
Fired when the runtime connection status changes. Event: { copilotkit, status } where status is a CopilotKitCoreRuntimeConnectionStatus.
Fired when a frontend tool starts executing. Event: { copilotkit, toolCallId, agentId, toolName, args }.
Fired when a frontend tool finishes executing. Event: { copilotkit, toolCallId, agentId, toolName, result, error? }, where result is the stringified tool result.
Fired when the registered agents change. Event: { copilotkit, agents }.
Fired when the shared context changes. Event: { copilotkit, context }.
Fired when the suggestions configuration changes. Event: { copilotkit, suggestionsConfig }.
Fired when the generated suggestions for an agent change. Event: { copilotkit, agentId, suggestions }.
Fired when suggestion generation begins for an agent. Event: { copilotkit, agentId }.
Fired when suggestion generation completes for an agent. Event: { copilotkit, agentId }.
Fired when the forwarded properties change. Event: { copilotkit, properties }.
Fired when the request headers change. Event: { copilotkit, headers }.
Fired when an error occurs. Event: { copilotkit, error, code, context } where code is a CopilotKitCoreErrorCode.
Fired when a thread store is registered. Event: { copilotkit, agentId, store }.
Fired when a thread store is removed (by explicit unregister or by a replacing register). The previous store is delivered via prevStore. Event: { copilotkit, agentId, prevStore }.
Usage
const subscription = copilotkit.subscribe({
onRuntimeConnectionStatusChanged: ({ status }) => {
console.log("connection:", status);
},
onError: ({ code, error }) => {
console.error(code, error);
},
});
// later
subscription.unsubscribe();