Workflows API
Canonical reference: docs/api-reference.md (generated endpoint directory) — this page is a task-oriented summary.
Sol’s workflow engine orchestrates multi-step agent tasks using gen_statem instances with compensation, branching, and tree operations. This API covers the full workflow lifecycle.
Create Workflow
POST /api/v1/workflows/start
Start a new workflow from a named definition and payload.
curl -X POST https://sol.example.com/api/v1/workflows/start \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "code-review",
"payload": {},
"objective": "Review the diff for bugs",
"token_budget": 50000,
"time_budget_ms": 600000
}'
Response:
{
"workflow_id": "wf-1744730000000",
"status": "started"
}
400 if name is missing; 500 on internal failure.
List Workflows
GET /api/v1/workflows
List all workflows with their current status.
curl -H "Authorization: Bearer $TOKEN" \
https://sol.example.com/api/v1/workflows
Get Workflow
GET /api/v1/workflows/:id
Get workflow details including step statuses and results.
curl -H "Authorization: Bearer $TOKEN" \
https://sol.example.com/api/v1/workflows/wf-1744730000000
Response:
{
"id": "wf-1744730000000",
"name": "code-review",
"status": "running",
"steps": [
{"name": "analyze", "status": "completed", "result": "..."},
{"name": "fix", "status": "running"},
{"name": "verify", "status": "pending"}
]
}
Cancel Workflow
POST /api/v1/workflows/:id/cancel
Cancel a running workflow. Triggers compensation for completed steps. 409 if already completed; 403 if not the owner.
Branch Workflow
POST /api/v1/workflows/:id/branch
Create a child workflow branching from an existing one. Body fields: branch_point_idx, objective. Returns {ok: true, child_workflow_id, parent_workflow_id}.
Workflow Tree
GET /api/v1/workflows/:id/tree
Returns the full tree of the workflow and its descendants.
Workflow Lineage
GET /api/v1/workflows/:id/lineage
Returns the root-to-node lineage path. Response: {ok: true, lineage: [...]}.
Pause Workflow
POST /api/v1/workflows/:id/pause
Pause a running workflow. {status: "paused"}. 409 if already completed.
Resume Workflow
POST /api/v1/workflows/:id/resume
Resume a paused workflow (or a budget-parked one with token_budget /
time_budget_ms raised). {status: "resumed"}. 409 if already completed
or the budget is still exhausted.
Retry Pending Compensation
POST /api/v1/workflows/:id/compensation/retry
Re-runs the LIFO pending-unwind driver for a failed workflow whose last
unwind did not complete. Confirmed handlers clear from the durable pending
set, after which /resume is allowed. 202 with the pending set; 409
when nothing is pending or the workflow is still running.
Stream Workflow Events
GET /api/v1/workflows/:id/stream
Subscribe to Server-Sent Events for this workflow’s state changes (owner-checked).
Workflow Lifecycle
Workflows use gen_statem for state management:
pending -> running -> completed
\-> failed
\-> cancelled
| State | Description |
|---|---|
pending | Created, not yet started |
running | Executing steps |
completed | All steps finished successfully |
failed | A step failed (compensation triggered) |
cancelled | User cancelled (compensation triggered) |
Step Lifecycle
Each step within a workflow follows its own state machine:
pending -> running -> completed
\-> failed
\-> skipped
Multi-Step Execution
Workflows execute steps sequentially by default. Each step receives:
The original prompt Results from previous steps Step-specific configuration (mode, tools, timeout)
The user_uuid is propagated from the HTTP request through each step dispatch, ensuring multi-tenant isolation.
Step Configuration
| Field | Type | Description |
|---|---|---|
name | string | Step identifier |
prompt | string | Task prompt for the step |
mode | string | Agent mode (build/plan/explore/review/general/coordinate) |
tools | array | Restricted tool set (optional) |
timeout | number | Step timeout in seconds (optional) |
condition | string | Execution condition (optional) |
Compensation Events
When a step fails or the workflow is cancelled, the workflow engine triggers compensation events:
- Completed steps receive a
compensateevent in reverse order - Each step can define a compensation action (rollback, cleanup, notification)
- Compensation failures are logged but do not block other compensations
- The workflow transitions to
failedorcancelledafter all compensations complete
This ensures resources are cleaned up even on partial failures.
Branching
Workflows support branching for conditional execution paths:
{
"name": "conditional-review",
"steps": [
{"name": "check", "prompt": "Check if tests pass", "mode": "build"},
{
"name": "branch",
"type": "branch",
"conditions": {
"pass": {"match": "{{check.result}}", "pattern": ".*passed.*", "then": "deploy"},
"fail": {"then": "fix"}
}
},
{"name": "deploy", "prompt": "Deploy to production", "mode": "build"},
{"name": "fix", "prompt": "Fix the failing tests", "mode": "build"}
]
}
Tree Operations
Workflows can be organized as trees for complex orchestration:
Parent-child relationships between workflow instances (see Branch Workflow and Workflow Tree) Spawn child workflows from a parent step Aggregate results from child workflows Tree-level cancellation propagates to all children
Streaming Workflow Events
Workflow state changes for a specific workflow are streamed via SSE:
curl -N https://sol.example.com/api/v1/workflows/wf-1744730000000/stream \
-H "Authorization: Bearer $TOKEN"
Event types:
| Event | Description |
|---|---|
workflow:started | Workflow execution began |
workflow:step:started | A step began executing |
workflow:step:completed | A step completed |
workflow:step:failed | A step failed |
workflow:completed | Workflow finished |
workflow:failed | Workflow failed |
workflow:cancelled | Workflow was cancelled |
workflow:compensating | Compensation in progress |
Event Store Integration
Workflow events are stored in the Mnesia-backed event store (102 event types). Pre- and post-hooks enable:
Audit logging of all workflow mutations Real-time notifications via the PUB/SUB event bridge Plugin reactions to workflow state changes Historical replay for debugging
The workflow bridge subscribes to the event store and dispatches step tasks to workers via ZMQ, propagating user_uuid for multi-tenant isolation.