Your first agent workflow
Goal: stand up a three-node agentic loop driven by WorkflowRuntime,
see it through one complete iteration, inspect the immutable
agent_runs_v2 rows it produces.
Why
AgentSpec + AgentRuntime is AlphaSwarm's "skill artifact" — every agent
run is hash-locked into agent_spec_versions and audited through
agent_runs_v2. Combined with the additive WorkflowRuntime
(orchestration adapter pattern), this is how AlphaSwarm composes
multi-agent pipelines without losing replay or kill-switch
semantics. See Concept: workflow studio.
Step 1 — author the workflow
Create configs/workflows/my_first_workflow.yaml:
name: MyFirstResearchLoop
adapter_kind: graph
nodes:
- id: research
agent_spec: configs/agents/research_lite.yaml
inputs:
universe: [SPY, QQQ, IWM]
lookback_days: 30
- id: selection
agent_spec: configs/agents/selection_lite.yaml
depends_on: [research]
- id: trader
agent_spec: configs/agents/trader_paper.yaml
depends_on: [selection]
edges:
- { from: research, to: selection }
- { from: selection, to: trader }
cost_caps:
per_node_max_tokens: 4000
per_run_max_usd: 0.50
halt_check_seconds: 5
Step 2 — snapshot + run
curl -X POST http://localhost:8000/workflows/MyFirstResearchLoop/run \
-d '{}'
WorkflowRuntime:
- Hash-locks the spec into
workflow_spec_versions. - Reads each referenced
AgentSpecand hash-locks them intoagent_spec_versions. - Begins traversing the DAG, calling each agent through
AgentRuntime. - Emits canonical progress frames per AGENTS rule 4.
- Writes
agent_runs_v2andworkflow_runsrows.
Step 3 — watch the breadcrumbs
The operator UI renders the workflow live at
/workflows/runs/<run_id>. From the CLI:
docker exec alphaswarm-api python -c "from alphaswarm.ws.broker import subscribe; \
[print(m) for m in subscribe('<run_task_id>')]"
Step 4 — inspect the ledger
SELECT id, workflow_name, status, started_at, ended_at, total_tokens, total_cost_usd
FROM workflow_runs ORDER BY started_at DESC LIMIT 1;
SELECT id, agent_name, node_id, status, total_tokens
FROM agent_runs_v2
WHERE workflow_run_id = '<from_above>'
ORDER BY started_at;
You should see three agent_runs_v2 rows — one per node.
Step 5 — replay
curl -X POST http://localhost:8000/workflows/runs/<workflow_run_id>/replay
Same hash-locked spec versions, new run row.
Step 6 — halt
The kill switch fans out:
curl -X POST http://localhost:8000/workflows/halt
Every running workflow stops; agent_runs_v2 rows close with
status=halted.
Verify
-
workflow_spec_versionsrow with aspec_hash. - Three
agent_spec_versionsrows (one per node). - One
workflow_runsrow + threeagent_runs_v2rows. - Total cost in USD ≤
per_run_max_usdfrom the spec. - Replay produces a new
workflow_runsrow but reuses the same spec-version rows.
What next
- Concept: agentic pipeline — the full five-stage lifecycle (models, data, snapshot, dispatch, review) and how this tutorial maps to it.
- Concept: workflow studio — the seven adapter kinds (graph / crew / debate / fusion / execution / schedule / studio).
- Concept: multi-agent patterns — Sequential / Parallel / Debate / Coordinator / ReAct topologies.
- Tutorial: first RL experiment — hand RL outputs into an agent loop.