Workers API
Canonical reference: docs/api-reference.md (generated endpoint directory) — this page is a task-oriented summary.
REST endpoints for managing ZMQ workers, local JSONL agents, dispatching tasks, and orchestrating multi-task fan-out. ZMQ workers connect as DEALER sockets to Sol’s ROUTER on port 5555 and communicate using msgpack over ZMTP. Local JSONL agents are supervised child processes spoke to over stdio.
All endpoints require a Bearer token when authentication is enabled. Admin-only
operations (spawn, kill, dispatch) require the "*" permission.
ZMQ Workers
List ZMQ Workers
GET /api/v1/zmq/workers
Returns all currently connected ZMQ workers with their status and capabilities. Paginated.
Response (200):
{
"items": [
{
"worker_id": "luna-worker-1",
"status": "ready",
"capabilities": ["lua", "streaming", "tools"],
"connected_at": 1716192000000,
"last_heartbeat": 1716192100000,
"current_task": null
}
],
"total": 1,
"limit": 50,
"offset": 0,
"page": 1,
"total_pages": 1,
"has_more": false
}
status is stringified from the internal atom (ready, busy, stale,
disconnected). Pagination uses the standard envelope — see
Overview.
CLI:
zerg zmq-workers
ZMQ Gateway Status
GET /api/v1/zmq/status
Returns the ZMQ gateway configuration and live state. Includes the sender/events liveness probes so a dead send path is visible from the API (without reading the supervisor log).
Response (200):
{
"enabled": true,
"port": 5555,
"connected": 2,
"queue_depth": 0,
"sender_alive": true,
"events_alive": true,
"sender_socket_alive": true
}
| Field | Description |
|---|---|
enabled | Whether the ZMQ gateway is running. |
port | ROUTER socket bind port. |
connected | Number of currently connected workers. |
queue_depth | Pending tasks in the dispatch queue. |
sender_alive | + — sol_zmq_sender gen_server is alive. |
events_alive | + — sol_zmq_events gen_server is alive. |
sender_socket_alive | + — the underlying sender socket process is alive. When false, dispatches will hang (noproc on send_sync); check the supervisor log. |
When the gateway is down or throws, the endpoint still returns 200 with the
safe fallback body {"enabled":false,"connected":0,"queue_depth":0} rather
than a 5xx.
CLI:
zerg zmq-status
Dispatch Task to a Worker
POST /api/v1/zmq/dispatch
Dispatch a task to an available ZMQ worker. The gateway routes to the first ready worker.
Request Body:
{
"prompt": "Analyze the codebase and report issues",
"model": "glm-5.1",
"stream": true,
"context": "additional context for the task"
}
| Field | Required | Description |
|---|---|---|
prompt | Yes | Task prompt to send to the worker. Missing/empty → 400. |
model | No | Model override for the task. |
stream | No | Enable SSE streaming response (default: false). |
context | No | Additional context string forwarded to the worker. |
The caller’s user_uuid and permissions are injected into the dispatch opts
by the handler — do not send them in the body.
Response (non-streaming, 200):
{
"status": "ok",
"task_id": "task_abc123"
}
Response (streaming, Content-Type: text/event-stream):
event: token
data: {"content": "Analyzing..."}
event: token
data: {"content": "Found 3 issues..."}
event: result
data: {"task_id": "task_abc123", "status": "ok", "content": "Complete analysis"}
Error Responses:
| Code | Body / Condition |
|---|---|
| 400 | {"ok":false,"error":{"code":"missing prompt","message":"missing prompt"}} |
| 405 | {"ok":false,"error":{"code":"method not allowed — use POST","message":"method not allowed — use POST"}} |
| 500 | {"ok":false,"error":{"code":"dispatch failed","message":"dispatch failed"}} (catch-all on 'EXIT'/unexpected return) |
| 503 | {"ok":false,"error":{"code":"zmq disabled","message":"zmq disabled"}}, or pipeline start failed |
Background Workers
All background-worker routes are admin-only (403 forbidden
otherwise).
Start Background Worker
POST /api/v1/workers/bg/start
{ "prompt": "analyze the logs and summarize errors" }
prompt is required (missing/empty → 400 prompt required); model and
timeout are optional. The caller’s identity is captured server-side.
Response (200): {"bg_id": "bg-abc123"} — there is no status
field.
List / Status / Logs
GET /api/v1/workers/bg
GET /api/v1/workers/bg/:bg_id
GET /api/v1/workers/bg/:bg_id/logs?n=100
Logs take ?n=<lines> (positive integer, default 100); any other
parameter name or a non-positive value answers 400 invalid n parameter.
Kill Background Worker
POST /api/v1/workers/bg/:bg_id/kill
404 unknown id; 409 when the worker is in a non-killable state.
Tasks
Task Status / Result
GET /api/v1/tasks/:task_id
Get the status and result of a dispatched task. Ownership is enforced: non-admin callers receive 403/404 for tasks they do not own.
Response — completed (200):
{
"task_id": "task_abc123",
"status": "ok",
"content": "Task result content"
}
Response — in progress, with partial output (200):
If the task has not finished but has emitted at least one streamed token, the
combined token buffer is returned as content:
{
"task_id": "task_abc123",
"status": "in_progress",
"content": "partial output so far..."
}
Response — not yet running:
A task that has no result and no streamed tokens yet may be reported by its
parent orchestration as pending. See GET /api/v1/orchestrate/:id below —
each child entry is shaped as {"task_id":..., "status":"pending"} until the
worker produces output. Direct GET /api/v1/tasks/:task_id for such a task
returns 404 with the Zerg envelope code task not found, because the
task store has no result row yet.
Error Responses:
| Code | Condition |
|---|---|
| 403 | Task exists but caller is not the owner (and not admin). |
| 404 | Task not found (no result row, no tokens). |
Cancel a Task
DELETE /api/v1/tasks/:task_id
Cancel a running task. The handler first asks the ZMQ gateway to cancel, then falls back to the local worker pipeline if ZMQ has no record of it. Ownership is enforced.
Response (200):
{ "status": "cancelled" }
Error Responses:
| Code | Condition |
|---|---|
| 403 | Not the task owner. |
| 404 | Task not found in ZMQ gateway or local pipeline. |
List Tasks
GET /api/v1/tasks
List tasks. Non-admin callers see only their own tasks; admins see all. Paginated.
Response (200):
{
"items": [
{
"task_id": "task_abc123",
"status": "ok",
"created_at": 1716192000000
}
],
"total": 1,
"limit": 50,
"offset": 0,
"page": 1,
"total_pages": 1,
"has_more": false
}
Local JSONL Agents
Local agents are stdio JSONL workers managed by Sol via erlexec.
List Agents
GET /api/v1/agents
Returns the list of running local JSONL agents.
Spawn an Agent
POST /api/v1/agents/spawn
Spawn a new JSONL stdio worker process. Admin-only.
Request Body:
{
"worker_path": "client/build/luna",
"opts": {}
}
Agent Detail
GET /api/v1/agents/:id
Status of a single named agent. :id is the worker’s registered atom (e.g.
luna_worker_1).
Response (200):
{
"worker_id": "luna_worker_1",
"status": "ready",
"current_task": null
}
status is stringified from the internal atom; current_task is null when
idle. Returns 404 with the Zerg envelope code agent not found if the
atom is unknown or sol_worker:status/1 crashes.
Dispatch Task to an Agent
POST /api/v1/agents/:id/task
Send a task prompt to a local agent.
Request Body:
{
"prompt": "Summarize this file",
"stream": true
}
| Field | Required | Description |
|---|---|---|
prompt | Yes | Task prompt. Empty → 400. |
stream | No | SSE stream the response (default: true for this endpoint). |
Responses:
| Code | Body | Condition |
|---|---|---|
| 200 | {"status":"ok","task_id":"..."} | Non-streaming success. |
| 202 | {"status":"queued","task_id":"..."} | Task queued (worker busy). |
| 200 | SSE stream | Streaming success (stream: true). |
| 400 | missing prompt | Empty prompt (Zerg envelope, error.code). |
| 404 | agent not found | Unknown worker / send_task crash (Zerg envelope). |
| 502/503 | class code | Dispatch error from sol_worker:send_task/2 — classified (worker-down → 503 worker class), never a blanket 500. |
Kill an Agent
POST /api/v1/agents/:id/kill
Terminate a running local agent. Admin-only.
Method is POST, not DELETE (matches the OpenAPI spec).
Orchestration
Dispatch Multi-Task
POST /api/v1/orchestrate
Dispatch multiple tasks in parallel, sequentially, or as a decomposed workflow.
Request Body:
{
"tasks": [
{"prompt": "Analyze module A"},
{"prompt": "Analyze module B"}
],
"mode": "direct",
"strategy": "parallel",
"model": "glm-5.1",
"timeout": 120000
}
| Field | Required | Description |
|---|---|---|
tasks | Yes | Array of task objects, each with at least prompt. Empty array → 400. |
mode | No | direct (default) or workflow. workflow decomposes via sol_coordinator. |
strategy | No | parallel (default) or sequential. |
model | No | Model override applied to all tasks. |
timeout | No | Overall timeout in ms (default 120000). timeout_ms is accepted as an alias. |
Responses:
| Code | Body | Condition |
|---|---|---|
| 200 | direct mode: array of per-task results; workflow mode: coordinator result with mode:"workflow" added | Success. |
| 400 | invalid tasks: non-empty list required / invalid timeout: positive integer required | Malformed tasks / timeout (Zerg envelope). |
| 422 | <formatted reason> | Workflow decomposition failed (Zerg envelope). |
Orchestration Detail
GET /api/v1/orchestrate/:id
Returns the child tasks of an orchestration parent.
Response (200):
{
"orchestration_id": "orch_xyz",
"children": [
{"task_id": "task_1", "status": "ok", "content": "..."},
{"task_id": "task_2", "status": "pending"}
]
}
Each child entry is either {task_id, status, content} (completed child) or
{task_id, status:"pending"} (child whose result row does not exist yet —
** behaviour**).
Error Responses:
| Code | Condition |
|---|---|
| 404 | Neither children nor a parent row exist for :id. |
Authentication
curl -H "Authorization: Bearer $TOKEN" \
http://localhost:21434/api/v1/zmq/workers
See Authentication for token acquisition and the priority order of
Authorization header vs zerg_session cookie vs ?token= query.
ZMQ Protocol
Workers connect as DEALER sockets to Sol’s ROUTER on port 5555. The wire protocol uses msgpack. See Workers and Agents for the full protocol specification and worker implementation examples.