$npx -y skills add spencermarx/open-code-review --skill swarm-orchestrationOrchestrate multi-agent swarms with agentic-flow for parallel task execution, dynamic topology, and intelligent coordination. Use when scaling beyond single agents, implementing complex workflows, or building distributed AI systems.
| 1 | # Swarm Orchestration |
| 2 | |
| 3 | ## What This Skill Does |
| 4 | |
| 5 | Orchestrates multi-agent swarms using agentic-flow's advanced coordination system. Supports mesh, hierarchical, and adaptive topologies with automatic task distribution, load balancing, and fault tolerance. |
| 6 | |
| 7 | ## Prerequisites |
| 8 | |
| 9 | - agentic-flow v3.0.0-alpha.1+ |
| 10 | - Node.js 18+ |
| 11 | - Understanding of distributed systems (helpful) |
| 12 | |
| 13 | ## Quick Start |
| 14 | |
| 15 | ```bash |
| 16 | # Initialize swarm |
| 17 | npx agentic-flow hooks swarm-init --topology mesh --max-agents 5 |
| 18 | |
| 19 | # Spawn agents |
| 20 | npx agentic-flow hooks agent-spawn --type coder |
| 21 | npx agentic-flow hooks agent-spawn --type tester |
| 22 | npx agentic-flow hooks agent-spawn --type reviewer |
| 23 | |
| 24 | # Orchestrate task |
| 25 | npx agentic-flow hooks task-orchestrate \ |
| 26 | --task "Build REST API with tests" \ |
| 27 | --mode parallel |
| 28 | ``` |
| 29 | |
| 30 | ## Topology Patterns |
| 31 | |
| 32 | ### 1. Mesh (Peer-to-Peer) |
| 33 | ```typescript |
| 34 | // Equal peers, distributed decision-making |
| 35 | await swarm.init({ |
| 36 | topology: 'mesh', |
| 37 | agents: ['coder', 'tester', 'reviewer'], |
| 38 | communication: 'broadcast' |
| 39 | }); |
| 40 | ``` |
| 41 | |
| 42 | ### 2. Hierarchical (Queen-Worker) |
| 43 | ```typescript |
| 44 | // Centralized coordination, specialized workers |
| 45 | await swarm.init({ |
| 46 | topology: 'hierarchical', |
| 47 | queen: 'architect', |
| 48 | workers: ['backend-dev', 'frontend-dev', 'db-designer'] |
| 49 | }); |
| 50 | ``` |
| 51 | |
| 52 | ### 3. Adaptive (Dynamic) |
| 53 | ```typescript |
| 54 | // Automatically switches topology based on task |
| 55 | await swarm.init({ |
| 56 | topology: 'adaptive', |
| 57 | optimization: 'task-complexity' |
| 58 | }); |
| 59 | ``` |
| 60 | |
| 61 | ## Task Orchestration |
| 62 | |
| 63 | ### Parallel Execution |
| 64 | ```typescript |
| 65 | // Execute tasks concurrently |
| 66 | const results = await swarm.execute({ |
| 67 | tasks: [ |
| 68 | { agent: 'coder', task: 'Implement API endpoints' }, |
| 69 | { agent: 'frontend', task: 'Build UI components' }, |
| 70 | { agent: 'tester', task: 'Write test suite' } |
| 71 | ], |
| 72 | mode: 'parallel', |
| 73 | timeout: 300000 // 5 minutes |
| 74 | }); |
| 75 | ``` |
| 76 | |
| 77 | ### Pipeline Execution |
| 78 | ```typescript |
| 79 | // Sequential pipeline with dependencies |
| 80 | await swarm.pipeline([ |
| 81 | { stage: 'design', agent: 'architect' }, |
| 82 | { stage: 'implement', agent: 'coder', after: 'design' }, |
| 83 | { stage: 'test', agent: 'tester', after: 'implement' }, |
| 84 | { stage: 'review', agent: 'reviewer', after: 'test' } |
| 85 | ]); |
| 86 | ``` |
| 87 | |
| 88 | ### Adaptive Execution |
| 89 | ```typescript |
| 90 | // Let swarm decide execution strategy |
| 91 | await swarm.autoOrchestrate({ |
| 92 | goal: 'Build production-ready API', |
| 93 | constraints: { |
| 94 | maxTime: 3600, |
| 95 | maxAgents: 8, |
| 96 | quality: 'high' |
| 97 | } |
| 98 | }); |
| 99 | ``` |
| 100 | |
| 101 | ## Memory Coordination |
| 102 | |
| 103 | ```typescript |
| 104 | // Share state across swarm |
| 105 | await swarm.memory.store('api-schema', { |
| 106 | endpoints: [...], |
| 107 | models: [...] |
| 108 | }); |
| 109 | |
| 110 | // Agents read shared memory |
| 111 | const schema = await swarm.memory.retrieve('api-schema'); |
| 112 | ``` |
| 113 | |
| 114 | ## Advanced Features |
| 115 | |
| 116 | ### Load Balancing |
| 117 | ```typescript |
| 118 | // Automatic work distribution |
| 119 | await swarm.enableLoadBalancing({ |
| 120 | strategy: 'dynamic', |
| 121 | metrics: ['cpu', 'memory', 'task-queue'] |
| 122 | }); |
| 123 | ``` |
| 124 | |
| 125 | ### Fault Tolerance |
| 126 | ```typescript |
| 127 | // Handle agent failures |
| 128 | await swarm.setResiliency({ |
| 129 | retry: { maxAttempts: 3, backoff: 'exponential' }, |
| 130 | fallback: 'reassign-task' |
| 131 | }); |
| 132 | ``` |
| 133 | |
| 134 | ### Performance Monitoring |
| 135 | ```typescript |
| 136 | // Track swarm metrics |
| 137 | const metrics = await swarm.getMetrics(); |
| 138 | // { throughput, latency, success_rate, agent_utilization } |
| 139 | ``` |
| 140 | |
| 141 | ## Integration with Hooks |
| 142 | |
| 143 | ```bash |
| 144 | # Pre-task coordination |
| 145 | npx agentic-flow hooks pre-task --description "Build API" |
| 146 | |
| 147 | # Post-task synchronization |
| 148 | npx agentic-flow hooks post-task --task-id "task-123" |
| 149 | |
| 150 | # Session restore |
| 151 | npx agentic-flow hooks session-restore --session-id "swarm-001" |
| 152 | ``` |
| 153 | |
| 154 | ## Best Practices |
| 155 | |
| 156 | 1. **Start small**: Begin with 2-3 agents, scale up |
| 157 | 2. **Use memory**: Share context through swarm memory |
| 158 | 3. **Monitor metrics**: Track performance and bottlenecks |
| 159 | 4. **Enable hooks**: Automatic coordination and sync |
| 160 | 5. **Set timeouts**: Prevent hung tasks |
| 161 | |
| 162 | ## Troubleshooting |
| 163 | |
| 164 | ### Issue: Agents not coordinating |
| 165 | **Solution**: Verify memory access and enable hooks |
| 166 | |
| 167 | ### Issue: Poor performance |
| 168 | **Solution**: Check topology (use adaptive) and enable load balancing |
| 169 | |
| 170 | ## Learn More |
| 171 | |
| 172 | - Swarm Guide: docs/swarm/orchestration.md |
| 173 | - Topology Patterns: docs/swarm/topologies.md |
| 174 | - Hooks Integration: docs/hooks/coordination.md |