Comma Agents
@comma-agents/daemon

Protocol

WebSocket protocol overview — message envelopes, request/response pairs, and error handling.

The daemon communicates with clients over a WebSocket connection at /ws. All messages are JSON objects validated with Zod schemas. Each message has a type field that identifies its kind.

Connection Lifecycle

  1. Client opens a WebSocket to ws://host:port/ws.
  2. The daemon assigns a clientId and tracks the connection.
  3. Client sends JSON messages (requests). Daemon replies with JSON messages (responses/events).
  4. On disconnect, the daemon removes the client from all subscriptions.

A health check is available at GET /health, returning { status, uptime, activeRuns, connectedClients }.

Message Envelopes

Every message extends a base envelope.

Client Messages

All client-to-daemon messages include an optional requestId. When provided, the daemon echoes it back on the response so the client can correlate request/response pairs.

{
  "type": "ping",
  "requestId": "abc-123"
}

Daemon Messages

All daemon-to-client messages include a ts field (ISO-8601 timestamp) and an optional requestId echoed from the triggering request.

{
  "type": "pong",
  "requestId": "abc-123",
  "ts": "2025-01-15T10:30:00.000Z"
}

Message Pairs Summary

Client RequestDaemon ResponsePattern
pingpongRequest/Reply
prepare_runrun_preparedRequest/Reply
start_runstrategy_started, strategy_completed, strategy_errorFire-and-forget + async events
continue_runstrategy_started, strategy_completed, strategy_errorFire-and-forget + async events
stop_runstrategy_error (code: CANCELLED)Fire-and-forget
list_strategiesstrategy_listRequest/Reply
list_providersprovider_listRequest/Reply
get_available_modelsavailable_modelsRequest/Reply
subscribeerror (only on failure)Silent success
unsubscribe(none)Silent
user_inputerror (only if no pending request)Silent success
steer_runsteer_queued (or error if not steerable)Fire-and-forget + async event

During strategy execution, subscribers receive observation events: step_started, step_completed, agent_output, agent_streaming, and request_input.

Error Handling

The daemon sends an error message for protocol-level failures. Every error includes a machine-readable code and a human-readable message:

{
  "type": "error",
  "code": "VALIDATION_ERROR",
  "message": "Missing required field: strategyPath",
  "ts": "2025-01-15T10:30:00.000Z"
}

Error Codes

CodeWhen
PARSE_ERRORInvalid JSON received on the WebSocket
VALIDATION_ERRORJSON is valid but fails schema validation
INTERNAL_ERRORUnhandled exception in a handler
NO_PENDING_INPUTuser_input sent but no agent is waiting for input
SUBSCRIBE_ERRORsubscribe failed (run not found or client not registered)
EXECUTION_ERRORStrategy file not found, parse error, or model resolution failure
PREPARE_FAILEDStrategy or run systems could not be prepared
START_FAILEDThe requested run is unknown or was already started
CANCELLEDRun was explicitly stopped via stop_run
RUN_NOT_STEERABLEsteer_run sent for a run that is not found or has already finished

On this page