Skip to main content
Hook into the agent’s lifecycle to build custom experiences on top of Crow.

Available Callbacks

CallbackFires when
onMessageA new message (user or assistant) is added
onMessageUpdateA message is updated (e.g. during streaming)
onToolCallA tool starts, completes, or a client tool is invoked
onWorkflowA workflow starts, progresses, or ends
onVerificationStatusIdentity verification status changes
onErrorAn error occurs

React SDK

Pass callbacks via the client.on() method:
import { CrowClient } from '@usecrow/client';

const client = new CrowClient({
  productId: 'YOUR_PRODUCT_ID',
  apiUrl: 'https://api.usecrow.org',
});

client.on({
  onMessage: (message) => {
    console.log(`[${message.role}] ${message.content}`);
  },

  onToolCall: (event) => {
    if (event.type === 'tool_call_start') {
      console.log(`Tool started: ${event.toolName}`);
    }
    if (event.type === 'tool_call_complete') {
      console.log(`Tool done: ${event.toolName}`, event.success);
    }
  },

  onError: (error) => {
    myErrorTracker.capture(error);
  },
});

Callback Reference

onMessage

onMessage?: (message: Message) => void
Fired when a new message is added to the conversation.
interface Message {
  id: string;
  content: string;
  role: 'user' | 'assistant';
  timestamp: Date;
  citations?: Citation[];
  thinking?: string;
}

onMessageUpdate

onMessageUpdate?: (messageId: string, updates: Partial<Message>) => void
Fired when a message is updated — typically during streaming as the assistant’s response accumulates.

onToolCall

onToolCall?: (event: ToolCallEvent) => void
Fired on tool lifecycle events:
event.typeDescription
tool_call_startServer-side tool invocation began
tool_call_completeServer-side tool finished (event.success)
client_tool_callClient-side tool was invoked in the browser

onWorkflow

onWorkflow?: (event: WorkflowEvent) => void
event.typeDescription
workflow_startedWorkflow began (event.name, event.todos)
workflow_todo_updatedA step completed (event.todoId, event.status)
workflow_endedWorkflow finished
workflow_complete_promptWorkflow requests user confirmation

onVerificationStatus

onVerificationStatus?: (isVerified: boolean) => void
Fired when the user’s identity verification status changes — useful for gating features behind verified users.

onError

onError?: (error: Error) => void
Fired on any error during streaming or tool execution.

Use Cases

Analytics — Track which tools are used and how often:
client.on({
  onToolCall: (event) => {
    if (event.type === 'tool_call_complete') {
      analytics.track('crow_tool_used', {
        tool: event.toolName,
        success: event.success,
      });
    }
  },
});
Custom loading states — Show your own UI while tools run:
client.on({
  onToolCall: (event) => {
    if (event.type === 'tool_call_start') {
      showToolSpinner(event.toolName);
    }
    if (event.type === 'tool_call_complete') {
      hideToolSpinner();
    }
  },
});
Error reporting — Pipe errors to your observability stack:
client.on({
  onError: (error) => {
    Sentry.captureException(error);
  },
});