swarmlab
Run a swarmlab multi-agent experiment end to end with the swarmlab CLI. Use when asked to design, smoke, launch (locally or on HF Jobs), analyse, report on, or publish a swarmlab experiment, or to resume or fork a swarmlab run.
Warnings for the author
- "name" should match the name of the directory that holds SKILL.md
- Not listed through the skills extension: the directory must be named after the skill.
swarmlab experimenter workflow
A swarmlab experiment runs LLM-agent swarms on a task world in rounds and logs every event. You change the
hypothesis in a YAML spec; the CLI does the execution. Every step below is a command; every
command takes --json (one JSON object on stdout) and exits 0 on success, 2 on an invalid spec,
1 otherwise. swarmlab COMMAND --help is the reference for flags.
Spend is real money. Each step that spends ends on a check you can see before the next one starts: a run summary, an estimate, a replay that matches.
Install
From a clone of the repo (uv sync --extra anthropic --extra hub gives the CLI as
uv run swarmlab), copy this file into your agent's skill directory:
| agent | user-level path |
|---|---|
| Claude Code | ~/.claude/skills/swarmlab/SKILL.md |
| Codex | ~/.agents/skills/swarmlab/SKILL.md |
| OpenCode | ~/.config/opencode/skills/swarmlab/SKILL.md (it also reads ~/.claude/skills/) |
for d in ~/.claude/skills ~/.agents/skills ~/.config/opencode/skills; do
mkdir -p "$d/swarmlab" && cp skill/SKILL.md "$d/swarmlab/SKILL.md"; done
Project-level copies work too: .claude/skills/swarmlab/, .agents/skills/swarmlab/,
.opencode/skills/swarmlab/ inside the repo.
First real run: the checklist
Size it to the budget first. Put the user's total in the spec as budget: {total_usd: T} (top
level): swarmlab run then never starts a run that could push the experiment past T. The
spend is shared through runs/<experiment>.ledger.jsonl, so separate invocations, parallel
shells and swarmlab run --parallel N all count against the same T (same --out). A run whose
hard_usd fits only after runs in flight end waits for them (total cap: waiting to start ...);
hard ceilings far above the real cost per run make runs wait, so size hard_usd from measured
spend.
- Total under $2: the short checklist. A separate smoke run and a second-agent review would
eat a large share of the money, and one round's worst-case estimate can be a fifth of the
total, so size the caps from measured spend, not from the estimate:
swarmlab doctor SPEC.yamlandswarmlab validate SPEC.yaml(items 1-2 below).- Dry run with
fake:reader(item 3; free): checks the metrics and the replay. A dry arm (onlyfake:models and scripted agents) needs nohard_usdand does not count towardtotal_usd. - Prompt review without a second agent:
swarmlab prompts SPEC.yaml --arm A > A.txtfor every arm, thendiff A.txt B.txt-> only the manipulated text differs, no correctness hints, every needed tool named. - Caps go in each arm's own
budget:(arms.A.budget: {soft_usd: 0, hard_usd: X}), not the top level: budgets are part of the spec hash, so changing a top-level cap later would make the finished first arm look like a different run. Keep onlytotal_usd: Tat the top. swarmlab preflight SPEC.yaml --arm Afor every arm with a real model -> exit 0: one real request per participant group with the arm's exactextraand tools; it shows the provider's HTTP error if a body field is rejected (cents at most;--max-usdcaps it).- First real arm = smoke = data, at N <= 6 agents, with
hard_usd= 50% of the total and no soft cap (soft_usd: 0: a soft cap at this size stops the run a round early):swarmlab run SPEC.yaml --arm FIRST --seed S->end=max_rounds. Note its actual spend (spend=$Xon the status line,spend_usdunder--json) and X / rounds = its measured per-round cost. The run is kept as the arm's data, not repeated. - Set the second arm's
hard_usdfrom that measurement: about 1.5 x the first arm's actualspend_usd(same model and N, one variable changed), and no more than T minus that spend;soft_usd: 0.swarmlab run SPEC.yamlthen skips the finished first arm and prints anexisting:line with its actual spend and per-round cost;total_usdcounts that spend (including anything added byresume) before starting the second arm. - A
hard_ceilingend (round in flight discarded) orhard_ceiling_probes(last round kept, some probes skipped):swarmlab resume RUN_DIR --add-budget Dif T minus the spend so far allows (resume itself does not checktotal_usd), else report the rounds you have. swarmlab report runs/ --out report.md; it lists skipped probes per arm.
- Total of $2 or more: the full checklist below, all eleven items.
Do these in order. Each item is done when its check holds; a failing check is fixed before the next item.
- Environment.
swarmlab doctor SPEC.yaml-> exit 0 (keys, extras, provider reachability, clean git). A new experiment starts fromswarmlab init NAME(writesNAME.yaml,NAME.py) in a project directory outside the swarmlab checkout (uv run --project <repo> swarmlab ...from there);swarmlab runrefuses to writeruns/inside the checkout unless--outis given. - Spec.
swarmlab validate SPEC.yaml-> every arm resolves; its table shows each arm's agents, models, soft/hard/measurement caps, probes and metrics: check them against the plan.swarmlab spec-referencelists every YAML key and its shape (e.g.medium: {topology: {type: gossip, params: {k: 1}}}, per-armbudget:); a shape error names the key and the shape expected there.swarmlab metricslists every metric name with what it measures (e.g.comm.post_rate,comm.posts_per_roundper agent). Model ids come fromswarmlab models --tools --search QWEN(prices are looked up, never typed). Every arm that calls a paid model hasbudget: {hard_usd: X};hard_usd: 0means no ceiling. - Dry run with scripted agents. Copy the arm into a dry-run arm whose participants are
{type: evidence_aggregator, count: N}or{type: llm, params: {model: "fake:reader"}}, thenswarmlab run SPEC.yaml --arm dry --seed 0 --yes->status=ended, metrics present, no spend.swarmlab replay RUN_DIR-> exit 0. - Prompts review by a second agent.
swarmlab prompts SPEC.yaml --arm A > prompts-A.txtfor every arm (no model call). Hand the files to a reviewer agent that did not write the spec; it checks that each arm's system prompt and round-1 message differ only in the manipulated variable, carry no correctness hints, and name every tool the arm needs. Fix the spec and re-render until the reviewer signs off. - Preflight, then smoke at N=4 with a hard ceiling. First
swarmlab preflight SPEC.yaml --arm Afor every arm with a real model -> exit 0, every grouptool call parsed(one real request per participant group with the arm's exactextraand tools; a rejected body field shows the provider's HTTP error here instead of as a run of errored turns). Then a smoke arm: the real model,count: 4,options: {max_rounds: 3},budget: {hard_usd: 0.50, measurement_usd: 0.10}.swarmlab run SPEC.yaml --arm smoke --seed 0->end=max_rounds(nothard_ceiling), thenswarmlab report RUNS_DIR-> tool protocol health shows no errored turns and fewlength/max_tokensfinishes (truncated replies). Ahard_ceilingend (the round in flight was discarded) orhard_ceiling_probes(the last round was kept, some of its probes were skipped) means raise the budget or cut rounds;swarmlab resume RUN_DIR --add-budget Dcontinues the same run with D more dollars (--budget-hard Xsets the run's total, spend so far and discarded rounds included). - Estimate.
swarmlab estimate SPEC.yaml --from runs/SMOKE_RUN_ID-> total for every arm x seed, priced with the smoke run's measured calls per turn, prompt-token growth per round, completion tokens and probe cost; without--fromthe worst case (each group'smax_calls, else the runner cap) overstates real spend 4-6x. The user approves the total before launch. - Launch. Local:
swarmlab run SPEC.yaml(every arm x seed; asks before spending; already finished runs are skipped). Self-hosted model on HF Jobs (spec modelsvllm:<model>):swarmlab job run SPEC.yaml --model ORG/MODELprints the plan and estimate; add--launchafter approval. - Watch. Local runs print a summary per run. Jobs:
swarmlab job status JOB_ID,swarmlab job logs JOB_ID --follow. - Fetch (jobs):
swarmlab job fetch RUN_ID --out runs/for each run id the log names ->swarmlab replay runs/RUN_IDexits 0. - Report.
swarmlab report runs/ --out report.md-> one row per arm (dry runs onfake:models are listed as simulated and kept out of the tables and spend); read it before claiming any effect, and say how many seeds stand behind each number. - Publish.
swarmlab publish runs/ --repo OWNER/EXPERIMENT-> private dataset repo with tables, sessions, raw logs and a card.swarmlab view RUN_DIR --publish OWNER/EXPERIMENTadds the replay page.--public(makes the repo public and tags it for the Hub's trace viewer) only when the user asks for it, after they have read the traces.
Rules
- Change the spec, never the code, to change the hypothesis. One arm per condition; arms of
one experiment differ only in the manipulated variable.
swarmlab promptsshows what differs. - Change prompts through params, then diff. An
llmgroup'ssystem_prompt_append: "..."adds text after the default prompt's task section (before the tool list);system_promptreplaces the whole Jinja2 template (variablesagent,role,description,tools,system_prompt_append;file:<path>works). Prefer the append: copying the template invites accidental differences.swarmlab prompts SPEC.yaml --arm A > A.txtper arm, thendiff, must show only the manipulated text. The default prompt already lists every tool (read_board,post), so a "mention the board" arm is a nudge, not awareness. - Resume or fork instead of rerunning. A crashed or budget-ended run continues with
swarmlab resume RUN_DIR [--add-budget D]; a counterfactual from round R isswarmlab fork RUN_DIR --at R --spec edited.yaml. Both reuse the inference cache, so the shared prefix costs nothing. - Re-running a finished run is a skip.
swarmlab runskips run dirs with the same spec hash;--rerunwritesRUN_ID__rNbeside it when you need a repeat. After a spec edit the hash differs andrunrefuses that run (both hashes in the error, outcomefailed):--rerun(new__rNdir) or--outelsewhere; nothing is overwritten. - Replay before you trust a run.
swarmlab replay RUN_DIRrecomputes metrics and score from the log with zero provider calls and exits 1 on any mismatch. - Analyse from exports.
swarmlab export RUN_DIRwritesexport/tables/<family>.parquet(turns, tool_calls, posts, deliveries, reads, actions, inference, probes, metrics, interventions, rounds, run, other, discarded_inference; keysexperiment, arm, seed, run, round, agent;run.jsonhasspendfrom the ledger andspend_discarded_usd) and one pi session per agent inexport/sessions/for reading a conversation turn by turn. - Look at one run by eye with
swarmlab view RUN_DIR(writesview.html, no server). - Restore a published run with
swarmlab fetch-published OWNER/EXPERIMENT RUN_ID --out runs/; it replays like a local one. - Slow providers and sequential commit do not mix:
commit: immediateputs every call on the critical path; keep it to fast providers or small N (swarmlab estimatedoes not model this). - Reasoning models need room: set
max_tokens: 2048or turn thinking off throughextra, in the serving provider's own field:{chat_template_kwargs: {enable_thinking: false}}for Qwen3 on vLLM/SGLang/DeepInfra,{reasoning_effort: "none"}on Cerebras (which rejectschat_template_kwargs; Qwen3.8 there reasons by default).swarmlab preflightchecks the field is accepted;swarmlab reportcountslengthandmax_tokensfinishes. - An
erroredrun is not data.WARNING: E/T turns errored (first error: ...), outcomeerroredand exit 1 mean most turns raised (usually a provider error); fix the spec (runpreflight) and rerun with--rerun, do not analyse it.
Files of this skill
This skill has no supporting files.