Skip to content

WebSocket protocol

Protocol version: v1. See wire protocol concept for the narrative; this page is the schema reference.

wss://<brain>/ws
Authorization: Bearer <agent-token>

Subprotocol: none (plain WS + JSON frames).

Every frame:

{
"type": "<string>",
...type-specific fields...
}
{
type: "hello",
protocol: "v1",
agent_name: string,
framework: "django" | "flask" | "fastapi" | "bare",
framework_version: string,
engines: string[],
schedulers: string[],
capabilities: Record<string, EngineCapabilities | SchedulerCapabilities>,
metadata: { hostname: string, pid: number, ... }
}
{
type: "event_batch",
seq: number, // monotonic per agent
events: TaskEvent[]
}

TaskEvent:

{
event_type: "task_sent" | "task_started" | "task_succeeded"
| "task_failed" | "task_retry" | "task_cancelled"
| "task_expired",
task_id: string,
engine: string,
ts: string, // RFC 3339
name: string,
args_redacted: any[],
kwargs_redacted: Record<string, any>,
queue?: string,
routing_key?: string,
error?: { exc_type: string, exc_msg: string, traceback_redacted: string },
group_id?: string,
parent_id?: string,
retry_of?: string
}
{ type: "heartbeat", ts: string }
{
type: "command_result",
cmd_id: string,
ok: boolean,
error?: { code: string, message: string },
result?: any
}

Full schedule list; sent after hello and every 5 minutes.

{
type: "schedule_snapshot",
scheduler: string,
schedules: Schedule[]
}

Delta update.

{
type: "schedule_update",
scheduler: string,
added?: Schedule[],
modified?: Schedule[],
removed?: string[] // schedule ids
}

Acknowledges an event_batch.

{ type: "ack", seq: number }
{
type: "command",
cmd_id: string, // UUID
cmd: "retry_task" | "cancel_task" | "bulk_retry" | "purge_queue"
| "schedule_create" | "schedule_update" | "schedule_delete"
| "schedule_pause" | "schedule_resume"
| "restart_agent" | "query_state",
args: Record<string, any>
}

Fatal protocol error; brain will close the socket.

{ type: "error", code: string, message: string }
CodeMeaning
1000Normal closure
4001Protocol version mismatch
4002Invalid token
4003Agent revoked
4004Agent name conflict
4005Malformed frame

Agents should reconnect with exponential backoff on 1006 / 1011 / 4005 and similar transient codes. On 4001 / 4002 / 4003, stop and log - these are configuration errors.