Advanced swarm patterns with dynamic topology switching and self-organizing behaviors for complex multi-agent coordination
Inherits all available tools
Additional assets for this skill
This skill inherits all available tools. When active, it can use any tool Claude has access to.
process-diagram.gvprocess.mdreadme.mdname: when-using-advanced-swarm-use-swarm-advanced description: Advanced swarm patterns with dynamic topology switching and self-organizing behaviors for complex multi-agent coordination version: 1.0.0 tags:
This skill implements advanced swarm patterns with dynamic topology switching, self-organizing behaviors, and intelligent coordination for complex multi-agent systems. It enables sophisticated swarm orchestration with adaptive topology selection and performance optimization.
Role: Tree-based coordination with leader-follower patterns Responsibilities:
Role: Peer-to-peer coordination with full connectivity Responsibilities:
Role: Dynamic topology switching based on workload Responsibilities:
Establish foundation for advanced swarm coordination with proper topology and agent configuration.
# Initialize hierarchical swarm
npx claude-flow@alpha swarm init --topology hierarchical --max-agents 10
# Initialize mesh swarm
npx claude-flow@alpha swarm init --topology mesh --max-agents 8
# Initialize adaptive swarm
npx claude-flow@alpha swarm init --topology adaptive --max-agents 12 --strategy balanced
# Verify initialization
npx claude-flow@alpha swarm status --verbose
# Setup memory coordination
npx claude-flow@alpha memory store --key "swarm/topology" --value "hierarchical"
npx claude-flow@alpha memory store --key "swarm/max-agents" --value "10"
// Initialize swarm with MCP
mcp__claude-flow__swarm_init({
topology: "hierarchical",
maxAgents: 10,
strategy: "balanced"
})
// Alternative: Mesh topology
mcp__claude-flow__swarm_init({
topology: "mesh",
maxAgents: 8,
strategy: "specialized"
})
// Alternative: Adaptive topology
mcp__claude-flow__swarm_init({
topology: "adaptive",
maxAgents: 12,
strategy: "adaptive"
})
# Store swarm configuration
npx claude-flow@alpha memory store \
--key "swarm/config" \
--value '{"topology":"hierarchical","maxAgents":10,"strategy":"balanced"}'
# Store agent assignments
npx claude-flow@alpha memory store \
--key "swarm/agents/coordinator-1" \
--value '{"type":"hierarchical-coordinator","status":"active","level":0}'
Select and configure optimal topology pattern based on task requirements and complexity.
# Spawn hierarchical coordinator
npx claude-flow@alpha agent spawn \
--type coordinator \
--role "hierarchical-coordinator" \
--capabilities "task-delegation,hierarchy-management"
# Spawn mesh coordinator
npx claude-flow@alpha agent spawn \
--type coordinator \
--role "mesh-coordinator" \
--capabilities "peer-coordination,consensus"
# Spawn adaptive coordinator
npx claude-flow@alpha agent spawn \
--type coordinator \
--role "adaptive-coordinator" \
--capabilities "topology-switching,optimization"
# Configure topology
npx claude-flow@alpha swarm configure \
--topology hierarchical \
--levels 3 \
--branching-factor 3
# Verify topology
npx claude-flow@alpha swarm status --show-topology
// Spawn coordinator agents
mcp__claude-flow__agent_spawn({
type: "coordinator",
name: "hierarchical-coordinator",
capabilities: ["task-delegation", "hierarchy-management"]
})
mcp__claude-flow__agent_spawn({
type: "coordinator",
name: "mesh-coordinator",
capabilities: ["peer-coordination", "consensus"]
})
mcp__claude-flow__agent_spawn({
type: "coordinator",
name: "adaptive-coordinator",
capabilities: ["topology-switching", "optimization"]
})
Hierarchical:
Mesh:
Star:
Ring:
Adaptive:
# Store topology configuration
npx claude-flow@alpha memory store \
--key "swarm/topology/config" \
--value '{"type":"hierarchical","levels":3,"branchingFactor":3}'
# Store baseline metrics
npx claude-flow@alpha memory store \
--key "swarm/metrics/baseline" \
--value '{"latency":45,"throughput":120,"agentUtilization":0.75}'
Spawn specialized agents based on topology and assign roles with proper coordination.
# Spawn specialized agents for hierarchical topology
npx claude-flow@alpha agent spawn --type researcher --capabilities "analysis,patterns"
npx claude-flow@alpha agent spawn --type coder --capabilities "implementation,testing"
npx claude-flow@alpha agent spawn --type reviewer --capabilities "quality,security"
# Assign agents to hierarchy levels
npx claude-flow@alpha swarm assign \
--agent-id "agent-001" \
--level 1 \
--parent "coordinator-1"
# Spawn agents for mesh topology
npx claude-flow@alpha agent spawn --type analyst --peer-mode enabled
npx claude-flow@alpha agent spawn --type optimizer --peer-mode enabled
# Configure peer connections
npx claude-flow@alpha swarm connect-peers --all
# List all agents
npx claude-flow@alpha agent list --show-roles --show-connections
// Spawn specialized agents
mcp__claude-flow__agent_spawn({
type: "researcher",
capabilities: ["analysis", "patterns", "research"]
})
mcp__claude-flow__agent_spawn({
type: "coder",
capabilities: ["implementation", "testing", "debugging"]
})
mcp__claude-flow__agent_spawn({
type: "analyst",
capabilities: ["optimization", "performance", "metrics"]
})
// Check agent status
mcp__claude-flow__agent_list({
filter: "active"
})
mcp__claude-flow__agent_metrics({
metric: "all"
})
Hierarchical Assignment:
# Level 0: Root coordinator
# Level 1: Department coordinators
# Level 2: Task executors
# Level 3: Specialized workers
npx claude-flow@alpha memory store \
--key "swarm/hierarchy/level-0" \
--value '{"agent":"coordinator-1","role":"root"}'
npx claude-flow@alpha memory store \
--key "swarm/hierarchy/level-1" \
--value '["agent-001","agent-002","agent-003"]'
Mesh Assignment:
# All agents are peers with direct connections
npx claude-flow@alpha memory store \
--key "swarm/mesh/peers" \
--value '["agent-001","agent-002","agent-003","agent-004"]'
# Store agent roster
npx claude-flow@alpha memory store \
--key "swarm/agents/roster" \
--value '{"total":8,"active":8,"idle":0,"roles":{"researcher":2,"coder":3,"reviewer":2,"optimizer":1}}'
# Store agent capabilities
npx claude-flow@alpha memory store \
--key "swarm/agents/agent-001/capabilities" \
--value '["analysis","patterns","research","documentation"]'
Track swarm performance metrics, identify bottlenecks, and gather optimization data.
# Monitor swarm status
npx claude-flow@alpha swarm monitor --interval 5 --duration 60
# Get agent metrics
npx claude-flow@alpha agent metrics --all --format json
# Check task performance
npx claude-flow@alpha task status --show-timing
# Analyze bottlenecks
npx claude-flow@alpha performance analyze --detect-bottlenecks
# Export metrics
npx claude-flow@alpha metrics export --output ./swarm-metrics.json
# Generate performance report
npx claude-flow@alpha performance report \
--include-agents \
--include-topology \
--output ./performance-report.md
// Monitor swarm in real-time
mcp__claude-flow__swarm_monitor({
duration: 60,
interval: 5
})
// Get comprehensive metrics
mcp__claude-flow__agent_metrics({
metric: "all"
})
// Check task status
mcp__claude-flow__task_status({
detailed: true
})
// Run performance benchmarks
mcp__claude-flow__benchmark_run({
type: "swarm",
iterations: 10
})
Swarm-Level Metrics:
Agent-Level Metrics:
Topology-Level Metrics:
# Store performance snapshot
npx claude-flow@alpha memory store \
--key "swarm/metrics/snapshot-$(date +%s)" \
--value '{"throughput":145,"latency":38,"utilization":0.82,"errors":2}'
# Store bottleneck analysis
npx claude-flow@alpha memory store \
--key "swarm/analysis/bottlenecks" \
--value '{"coordinator-1":{"type":"high-load","severity":"medium","recommendation":"add-peer"}}'
Apply dynamic optimizations including topology switching, agent rebalancing, and resource allocation.
# Analyze optimization opportunities
npx claude-flow@alpha performance analyze --recommend-optimizations
# Switch topology dynamically
npx claude-flow@alpha swarm reconfigure --topology mesh
# Rebalance agents
npx claude-flow@alpha swarm rebalance --strategy adaptive
# Scale swarm
npx claude-flow@alpha swarm scale --target-agents 12
# Apply neural optimizations
npx claude-flow@alpha neural train --pattern convergent
# Validate improvements
npx claude-flow@alpha performance compare \
--baseline ./baseline-metrics.json \
--current ./current-metrics.json
# Generate optimization report
npx claude-flow@alpha performance report \
--show-improvements \
--output ./optimization-report.md
// Get optimization recommendations
mcp__claude-flow__benchmark_run({
type: "swarm",
iterations: 5
})
// Train neural patterns
mcp__claude-flow__neural_train({
agentId: "adaptive-coordinator",
iterations: 10
})
// Check neural patterns
mcp__claude-flow__neural_patterns({
pattern: "all"
})
Topology Switching:
# Switch from hierarchical to mesh if bottleneck detected
if [ "$COORDINATOR_LOAD" -gt 80 ]; then
npx claude-flow@alpha swarm reconfigure --topology mesh
fi
# Switch to ring for sequential processing
if [ "$TASK_TYPE" == "pipeline" ]; then
npx claude-flow@alpha swarm reconfigure --topology ring
fi
Agent Rebalancing:
# Identify underutilized agents
npx claude-flow@alpha agent metrics --filter "utilization<0.3"
# Reassign tasks from overloaded agents
npx claude-flow@alpha swarm rebalance --threshold 0.8
# Add agents if all are highly utilized
if [ "$AVG_UTILIZATION" -gt 0.9 ]; then
npx claude-flow@alpha agent spawn --type optimizer --auto-assign
fi
Resource Allocation:
# Allocate more memory to high-priority agents
npx claude-flow@alpha agent configure \
--agent-id "agent-001" \
--memory-limit 2048MB
# Adjust coordination intervals
npx claude-flow@alpha swarm configure --sync-interval 3s
# Store optimization actions
npx claude-flow@alpha memory store \
--key "swarm/optimization/actions" \
--value '{"timestamp":"2025-10-30T10:30:00Z","action":"topology-switch","from":"hierarchical","to":"mesh","reason":"coordinator-bottleneck"}'
# Store improvement metrics
npx claude-flow@alpha memory store \
--key "swarm/optimization/improvements" \
--value '{"throughput":{"before":120,"after":175,"improvement":45.8},"latency":{"before":45,"after":32,"improvement":28.9}}'
Symptoms: High latency, coordinator CPU >90% Solution: Switch to mesh topology or add peer coordinators
Symptoms: Many agents idle, unbalanced load Solution: Rebalance task assignment, reduce agent count
Symptoms: Errors during reconfiguration, lost connections Solution: Drain tasks before switching, validate agent states
Symptoms: Agents have inconsistent state Solution: Increase sync frequency, use distributed consensus
After completing this skill: