Skilllibrary swarm-patterns
install
source · Clone the upstream repo
git clone https://github.com/merceralex397-collab/skilllibrary
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/merceralex397-collab/skilllibrary "$T" && mkdir -p ~/.claude/skills && cp -r "$T/05-agentic-orchestration-and-autonomy/swarm-patterns" ~/.claude/skills/merceralex397-collab-skilllibrary-swarm-patterns && rm -rf "$T"
manifest:
05-agentic-orchestration-and-autonomy/swarm-patterns/SKILL.mdsource content
Purpose
Provides coordination patterns for running many agents against a shared goal with bounded overlap — including map/reduce, scatter-gather, and blackboard architectures — so results converge without conflicts or redundant work.
When to use
- A task can be partitioned into 3+ independent work items of similar size.
- The user asks for parallel processing, fan-out, or batch agent work.
- A codebase-wide analysis (lint, migrate, audit) benefits from splitting by file, module, or directory.
- Results from many agents must be merged into one deliverable.
Do NOT use when
- Work items have strict sequential dependencies (A must finish before B).
- Total items are fewer than 3 — simple delegation is cheaper.
- Agents would need write access to the same files (use lane-safety instead).
- A single agent can complete the task within its context window.
Operating procedure
- Inventory the work items. Run
orglob
to produce a concrete list of targets (files, modules, endpoints, tickets). Record the count.grep - Choose a coordination pattern.
- Map/Reduce — each agent processes one partition and returns a typed result; a reducer merges all results. Best for homogeneous tasks.
- Scatter-Gather — agents explore freely within a scope; gatherer deduplicates and ranks findings. Best for search or audit.
- Blackboard — agents read/write to a shared state file; a monitor checks convergence. Best for iterative refinement. Record the chosen pattern and rationale.
- Define partition boundaries. Assign each work item to exactly one
agent. List assignments in a table:
. No two agents may share a write target.| Agent ID | Scope (files/dirs) | Expected output shape | - Set the overlap budget. Specify the maximum acceptable duplication percentage (default 10%). If two agents' scopes overlap by more than this, merge the scopes into one agent.
- Set convergence criteria. Define what "done" means: e.g., "all N agents returned a result" or "blackboard has no OPEN items remaining."
- Launch agents. Use
tool calls in parallel. Each prompt must include: (a) the agent's partition, (b) the output schema, (c) a hard instruction to NOT touch files outside its partition.task - Collect results. As agents complete, validate each result against the expected output shape. Log pass/fail per agent in a status table.
- Run the reduce / gather / convergence step. Merge individual results:
- Map/Reduce: concatenate or aggregate typed outputs.
- Scatter-Gather: deduplicate findings by key, keep highest-confidence.
- Blackboard: verify all items are RESOLVED; re-run stragglers once.
- Emit the merged deliverable. Produce the final output with a provenance section showing which agent contributed which piece.
Decision rules
- Never launch more agents than work items — 1:1 mapping maximum.
- If an agent fails, retry it once with the same partition. On second failure, absorb its partition into an adjacent agent.
- If overlap between two results exceeds the budget, discard the lower-confidence duplicate and note the discard in provenance.
- Prefer map/reduce when output is structured data; prefer scatter-gather when output is natural-language findings.
- Cap swarm size at 10 agents per round unless the user explicitly raises it.
Output requirements
- Partition Table — markdown table of agent-to-scope assignments.
- Status Table — agent ID, status (pass/fail/retry), result summary.
- Merged Deliverable — the combined output in the format the user requested (report, code changes, data table, etc.).
- Provenance Log — which agent produced which section of the deliverable.
References
— output shape contracts for agents.references/delegate-contracts.md
— when to checkpoint swarm state.references/checkpoint-rules.md
— retry and absorb protocols.references/failure-escalation.md
Related skills
— single-agent research delegation.subagent-research-patterns
— gating the merge step on evidence.verification-before-advance
— persisting swarm state across sessions.workflow-state-memory
— breaking goals into work items pre-swarm.goal-decomposition
Failure handling
- Agent returns wrong output shape: Reject the result, log the schema mismatch, and re-launch the agent with an explicit schema reminder.
- Swarm stalls (>50% agents timed out): Cancel remaining agents, merge whatever results exist, and report partial coverage to the user.
- Merge conflicts in blackboard: Freeze the blackboard, list conflicting entries with their authors, and ask the user for resolution order.
- Overlap budget exceeded after merge: Flag the duplicated sections, keep the version with more citations, and note the discard in provenance.