Swarm Orchestration Skill
Overview
A static fan-out — the orchestrator hand-listing N agent calls — works fine for a handful of parallel tasks. It stops working the moment the right number of workers is unknown in advance, or needs to scale to hundreds or thousands: nobody hand-writes a thousand agent calls.
This skill moves orchestration up a level of abstraction. Instead of the orchestrator calling agents directly, it writes a script (JavaScript or similar) that spawns sub-agents programmatically — with concurrency limits, timeouts, and retries as parameters in that script rather than judgment calls made fresh each time. That script can spawn 3 workers or 1,000 with the same shape of logic. The orchestrator's job shifts from "call agents" to "write and parameterize the program that calls agents."
The core tension this skill manages: parallel workers are how you cover a lot of ground fast, but because they all descend from the same originating prompt, they can fail together instead of independently. A swarm is not automatically safer than a single agent just because it has more workers — it's safer only if it's designed to avoid correlated failure and bounded against runaway cost.
When to Use
- The right number of parallel workers isn't known in advance, or is large enough that hand-listing each call doesn't scale
- A search, audit, or generation task has enough surface area that many independent attempts beat one deep attempt (see
power-law-engineering) - The task can be split into genuinely independent units of work with a well-defined way to combine results afterward
- You want the orchestration logic itself (concurrency, retries, timeouts) to be explicit and reviewable, not implicit in a chain of manual tool calls
When Not to Use
- A small, fixed number of parallel tasks (2-5) where a static fan-out is simpler and the scripting overhead isn't worth it
- Work with real sequential dependencies between units — a swarm is for independent parallel bets, not a disguised sequential pipeline
- No way to define a reducer/evaluator for the outputs — if you can't say how conflicting worker results get resolved, the swarm will just produce noise faster
Core Operating Rules
1. Dynamic Script, Not Static Fan-Out
The orchestrator writes an actual script that spawns workers programmatically (loops, conditionals, dynamic worker counts) rather than the model manually invoking N agent calls one by one. This is what makes the pattern scale-invariant — the same script shape handles 3 workers or 1,000; only the input list size changes.
2. Complexity Budget — Fixed Before Fan-Out, All Four Numbers Stated
Define these explicitly before any worker spawns, not adjusted mid-run:
- Concurrency limit: max workers running at once
- Per-worker timeout: hard ceiling on how long any one worker can run before being killed and treated as failed
- Retry policy: how many retries per worker, and what counts as a retryable vs. terminal failure
- Hard cost ceiling: total budget (tokens, dollars, or wall-clock) for the entire swarm — the run stops when this is hit, regardless of how many workers haven't finished
"Reasonable limits" is not a spec. If the user hasn't stated numbers, propose defaults explicitly and state them before proceeding rather than leaving them implicit.
3. Evidence Contract for the Synthesizer
Every worker must return output in a fixed, structured shape (a schema), not free-form text. This turns the synthesizer's job into reducing known-shaped evidence rather than parsing N different essays and hoping the important parts survive.
- Define the schema before fan-out: what fields, what format, what a "found nothing" result looks like (never silently omit — an explicit empty result is different from a worker that failed)
- A worker whose output doesn't fit the contract is either retried or marked failed — it does not get silently reinterpreted by the synthesizer
4. Reducer/Evaluator Defined Before Fan-Out Begins
Decide, in advance, how the swarm's outputs get combined:
- Majority vote, weighted scoring, adversarial refute-and-kill, or first-past-a-threshold — name the mechanism explicitly
- Defining this after results are already in hand invites picking whichever reducer makes the results look best — the reducer is a commitment made blind to the actual outputs, not a post-hoc fit
- State what happens on a tie or genuine disagreement among workers (escalate to human, run a tie-breaker round, default to the conservative answer) — don't leave this undefined until it happens
5. Cascade Defense Against Correlated Error (default ON)
Because every worker descends from the same orchestrating prompt, the default risk is not independent random failure — it's every worker being confidently wrong in the same way, because they all inherited the same flawed premise. Treat this as the primary failure mode to design against, not an edge case:
- Default to deliberate diversity across workers — different lenses, different sub-prompts, different angles of attack — rather than N identical clones of one prompt running for raw speed
- If the user wants pure identical-clone parallelism (e.g., simple map over a list of independent items), that's fine — but state explicitly that correlated-error defense doesn't apply here because there's no shared judgment call, only a shared mechanical step
- When the swarm's job involves judgment, synthesis, or verification (not just mechanical parallel lookups), diversity is the guardrail — call it out if a user's plan skips it, the same way
ratchet-loop's guardrail defaults on unless explicitly waived
6. Output Requirements
Always deliver, in this order:
- The complexity budget (concurrency, timeout, retries, cost ceiling) — stated as numbers
- The evidence contract (schema) each worker must return
- The reducer/evaluator mechanism, including the tie/disagreement rule
- The diversity strategy across workers, or an explicit statement that pure parallelism is safe here and why
- After the run: workers spawned vs. budget used, failure/retry counts, and how the reducer resolved disagreement — the audit trail, not just the final synthesized answer
Worked Example
Input: "I want to check 200 vendor contracts for a specific liability clause. Some have it, some don't, some are ambiguous. Build me a swarm for this."
Setup:
- Concurrency limit: 15 workers at once; per-worker timeout: 2 minutes; retries: 1 retry on timeout or malformed output, then mark failed; cost ceiling: stop spawning new workers if total spend crosses a stated token budget, finish in-flight workers, then stop
- Evidence contract: each worker returns
{contract_id, clause_found: true/false/ambiguous, quote, confidence}— no free text allowed outside those fields - Reducer: no vote needed since each contract is independent (one worker, one contract) — the reducer here is just aggregation: bucket by
clause_foundvalue, flag everyambiguousresult for human review rather than guessing - Diversity: not needed — this is mechanical parallel lookup, not shared judgment, so 200 structurally-identical workers each reading a different contract is correctly safe. Called out explicitly rather than assumed.
Output at the end: aggregation of 200 results (kept/failed/retried counts), a bucketed list (has clause / doesn't / ambiguous), and the ambiguous bucket surfaced first since that's where a human needs to look.
Advanced Techniques
- Pairing with power-law-engineering: use that skill's tail-aware metrics to judge the swarm's own performance across runs (p50/p90 worker quality, not just average) rather than treating every worker as equally informative.
- Pairing with ratchet-loop: a swarm can generate many candidate changes in parallel, then hand the winner into a ratchet-loop for sequential refinement — swarm explores broadly, loop exploits narrowly.
- Tiered swarms: a first cheap, high-concurrency pass to narrow a large space, followed by a second smaller, higher-quality pass (fewer workers, longer per-worker budget) only on what survived — trades one big expensive swarm for two cheaper staged ones.
- Adversarial reducer: for judgment-heavy tasks, make the reducer itself a second swarm of skeptics whose job is to refute the first swarm's majority answer — survives only if it holds up against dedicated attack, not just a headcount.
Quality Checklist (run before fan-out)
- Concurrency limit, per-worker timeout, retry policy, and hard cost ceiling all stated as numbers
- Evidence contract (schema) defined, including what an explicit "found nothing" result looks like
- Reducer/evaluator named before any worker output exists, including the tie/disagreement rule
- Diversity-across-workers decided explicitly — either applied, or waived with a stated reason (pure mechanical parallelism, no shared judgment call)
- Cost ceiling behavior defined: what happens to in-flight workers when the ceiling is hit
- Audit trail (spawned vs. budget, failures/retries, reducer resolution) is part of the deliverable, not just the final answer