Overview
Agents emit observability events for state changes, RPC calls, connections, schedules, workflows, MCP operations, and emails. Events are published to diagnostic channels and can be consumed via subscribers or Tail Workers.Event Channels
Events are published to named diagnostic channels:Channel
State updates (
state:update)Channel
RPC method calls (
rpc, rpc:error)Channel
WebSocket messages, tool calls (
message:*, tool:*)Channel
Scheduled tasks and queues (
schedule:*, queue:*)Channel
Connection lifecycle (
connect, disconnect, destroy)Channel
Workflow events (
workflow:*)Channel
MCP operations (
mcp:*)Channel
Email routing (
email:*)subscribe()
Subscribe to a typed observability channel.keyof ChannelEventMap
required
Channel name (“rpc”, “state”, “lifecycle”, etc.)
(event: ChannelEventMap[K]) => void
required
Callback to handle events
() => void - Function to unsubscribe
Event Types
State Events
state:update
Emitted when Agent state changes.RPC Events
rpc
Emitted when an RPC method is called.method: string- Method namestreaming?: boolean- Whether the method is streaming
rpc:error
Emitted when an RPC call fails.method: string- Method nameerror: string- Error message
Lifecycle Events
connect
Emitted when a WebSocket connection is established.connectionId: string- Connection ID
disconnect
Emitted when a WebSocket connection closes.connectionId: string- Connection IDcode: number- Close codereason: string- Close reason
Schedule Events
schedule:execute
Emitted when a scheduled task executes.callback: string- Callback namescheduleId: string- Schedule IDtype: string- Schedule type (“cron”, “delayed”, etc.)
queue:execute
Emitted when a queued task executes.callback: string- Callback name
Workflow Events
workflow:start
Emitted when a workflow is started.workflowName: string- Workflow binding nameinstanceId: string- Workflow instance ID
workflow:progress
Emitted when a workflow reports progress.workflowId: string- Workflow instance IDprogress: unknown- Progress data
workflow:complete
Emitted when a workflow completes.workflowId: string- Workflow instance IDresult: unknown- Workflow result
workflow:error
Emitted when a workflow errors.workflowId: string- Workflow instance IDerror: string- Error message
MCP Events
mcp:client:connect
Emitted when connecting to an MCP server.url: string- Server URLtransport: string- Transport typestate: string- Connection stateerror?: string- Error message (if failed)
mcp:client:discover
Emitted when discovering MCP server capabilities.Email Events
email:receive
Emitted when an email is received.from: string- Sender addressto: string- Recipient addresssubject?: string- Email subject
email:reply
Emitted when a reply is sent.from: string- Sender addressto: string- Recipient addresssubject?: string- Reply subject
Custom Observability
Overrideobservability on the Agent to use a custom implementation:
Tail Workers
In production, events are automatically forwarded to Tail Workers viaevent.diagnosticsChannelEvents:
Event Structure
All events have the same base structure:Best Practices
Subscribe Early
Filter Events
Aggregate Metrics
Use Type Narrowing
Related
- Agent Class - Observability property
- Node.js diagnostics_channel - Underlying API