| name | when-deploying-cloud-swarm-use-flow-nexus-swarm |
| description | Deploy cloud-based AI agent swarms with event-driven workflow automation using Flow Nexus platform. Supports hierarchical, mesh, ring, and star topologies with E2B sandbox distribution. |
Flow Nexus Cloud Swarm Deployment SOP
metadata:
skill_name: when-deploying-cloud-swarm-use-flow-nexus-swarm
version: 1.0.0
category: platform-integration
difficulty: advanced
estimated_duration: 40-70 minutes
trigger_patterns:
- "deploy cloud swarm"
- "flow nexus swarm"
- "distributed workflow"
- "event-driven agents"
- "cloud agent coordination"
dependencies:
- flow-nexus MCP server
- Claude Flow hooks
- E2B account (optional)
agents:
- hierarchical-coordinator (swarm orchestrator)
- flow-nexus-swarm (cloud platform manager)
- adaptive-coordinator (dynamic optimization)
success_criteria:
- Swarm initialized successfully
- Agents deployed to cloud
- Workflows executing correctly
- Performance metrics tracked
- Auto-scaling functional
Overview
Deploy cloud-based AI agent swarms with event-driven workflow automation using Flow Nexus platform. Supports hierarchical, mesh, ring, and star topologies with E2B sandbox distribution.
Prerequisites
Required:
- Flow Nexus MCP server installed
- Flow Nexus account (authenticated)
- Basic understanding of swarm patterns
Optional:
- E2B API key for cloud sandboxes
- Anthropic API key for Claude Code
- Existing workflow definitions
Verification:
npx flow-nexus@latest --version
mcp__flow-nexus__auth_status
Agent Responsibilities
hierarchical-coordinator (Swarm Orchestrator)
Role: Coordinate multi-level swarm hierarchy, manage agent lifecycles, optimize task distribution
Expertise:
- Hierarchical swarm patterns
- Task decomposition
- Agent coordination
- Resource allocation
Output: Swarm topology, agent assignments, coordination protocols
flow-nexus-swarm (Cloud Platform Manager)
Role: Manage Flow Nexus platform integration, E2B sandbox deployment, cloud resources
Expertise:
- Flow Nexus platform APIs
- E2B sandbox management
- Cloud infrastructure
- Distributed systems
Output: Cloud deployment, sandbox configuration, resource management
adaptive-coordinator (Dynamic Optimization)
Role: Monitor swarm performance, adapt topology, optimize resource usage dynamically
Expertise:
- Performance monitoring
- Dynamic optimization
- Resource management
- Adaptive algorithms
Output: Performance metrics, optimization recommendations, scaling policies
Phase 1: Initialize Cloud Swarm
Objective: Initialize swarm with selected topology and agent configuration
Evidence-Based Validation:
- Swarm created successfully
- Topology configured correctly
- Swarm ID stored in memory
- Configuration validated
hierarchical-coordinator Actions:
npx claude-flow@alpha hooks pre-task --description "Initialize cloud swarm deployment"
npx claude-flow@alpha hooks session-restore --session-id "cloud-swarm-$(date +%s)"
mkdir -p swarm/{config,agents,workflows,monitoring,docs}
cat > swarm/config/topology.json << 'EOF'
{
"topology": "hierarchical",
"maxAgents": 8,
"strategy": "adaptive",
"roles": {
"coordinator": {
"count": 1,
"capabilities": ["task_delegation", "monitoring", "optimization"]
},
"supervisor": {
"count": 2,
"capabilities": ["team_management", "task_execution", "reporting"]
},
"worker": {
"count": 5,
"capabilities": ["task_execution", "specialization"]
}
},
"communication": {
"protocol": "event-driven",
"queue": "message-queue",
"realtime": true
}
}
EOF
npx claude-flow@alpha hooks post-edit --file "swarm/config/topology.json" --memory-key "swarm/topology"
flow-nexus-swarm Actions:
mcp__flow-nexus__swarm_init {
"topology": "hierarchical",
"maxAgents": 8,
"strategy": "adaptive"
}
SWARM_ID="[returned_swarm_id]"
npx claude-flow@alpha memory store --key "swarm/swarm-id" --value "$SWARM_ID"
mcp__flow-nexus__swarm_status { "swarm_id": "$SWARM_ID" }
mcp__flow-nexus__swarm_templates_list {
"category": "specialized",
"includeStore": true
}
npx claude-flow@alpha memory store \
--key "swarm/config" \
--value "{\"swarm_id\": \"$SWARM_ID\", \"topology\": \"hierarchical\", \"max_agents\": 8, \"timestamp\": \"$(date -Iseconds)\"}"
npx claude-flow@alpha hooks notify --message "Cloud swarm initialized: $SWARM_ID"
adaptive-coordinator Actions:
cat > swarm/monitoring/config.json << 'EOF'
{
"metrics": {
"swarm": ["agent_count", "task_throughput", "response_time"],
"agents": ["utilization", "success_rate", "error_rate"],
"resources": ["cpu_usage", "memory_usage", "network_io"]
},
"thresholds": {
"high_utilization": 0.85,
"low_utilization": 0.2,
"max_response_time_ms": 5000,
"max_error_rate": 0.05
},
"scaling": {
"scale_up": {
"trigger": "utilization > 0.85 for 5 minutes",
"action": "add 2 agents"
},
"scale_down": {
"trigger": "utilization < 0.2 for 10 minutes",
"action": "remove 1 agent"
}
}
}
EOF
npx claude-flow@alpha hooks post-edit --file "swarm/monitoring/config.json" --memory-key "swarm/monitoring-config"
Success Criteria:
Memory Persistence:
npx claude-flow@alpha memory store \
--key "swarm/phase1-complete" \
--value "{\"status\": \"complete\", \"swarm_id\": \"$SWARM_ID\", \"topology\": \"hierarchical\", \"timestamp\": \"$(date -Iseconds)\"}"
Phase 2: Deploy Agents to Cloud
Objective: Deploy specialized agents to E2B sandboxes with role-specific configurations
Evidence-Based Validation:
- All agents deployed successfully
- Sandboxes running
- Agent capabilities configured
- Communication established
hierarchical-coordinator Actions:
cat > swarm/agents/specifications.json << 'EOF'
{
"coordinator": {
"type": "coordinator",
"capabilities": ["task_delegation", "monitoring", "optimization"],
"resources": {
"template": "nodejs",
"memory": "2GB",
"cpus": 2
}
},
"supervisors": [
{
"type": "supervisor",
"name": "supervisor-backend",
"capabilities": ["backend_tasks", "database", "api"],
"specialization": "backend"
},
{
"type": "supervisor",
"name": "supervisor-frontend",
"capabilities": ["frontend_tasks", "ui", "testing"],
"specialization": "frontend"
}
],
"workers": [
{
"type": "worker",
"name": "worker-coder-1",
"capabilities": ["coding", "implementation"],
"specialization": "coder"
},
{
"type": "worker",
: ,
: [, ],
:
},
{
: ,
: ,
: [, ],
:
},
{
: ,
: ,
: [, ],
:
},
{
: ,
: ,
: [, ],
:
}
]
}
EOF
npx claude-flow@alpha hooks post-edit --file --memory-key
flow-nexus-swarm Actions:
SWARM_ID=$(npx claude-flow@alpha memory retrieve --key "swarm/swarm-id" | jq -r '.value')
mcp__flow-nexus__agent_spawn {
"type": "coordinator",
"name": "coordinator-main",
"capabilities": ["task_delegation", "monitoring", "optimization"]
}
COORDINATOR_ID="[returned_agent_id]"
npx claude-flow@alpha memory store --key "swarm/coordinator-id" --value "$COORDINATOR_ID"
for spec in "backend" "frontend"; do
mcp__flow-nexus__agent_spawn {
"type": "analyst",
"name": "supervisor-$spec",
"capabilities": ["team_management", "task_execution", "reporting"]
}
done
for spec in "coder" "coder" "tester" "reviewer" "documentation"; do
mcp__flow-nexus__agent_spawn {
"type": "coder",
"name": "worker-$spec",
"capabilities": ["task_execution", "specialization"]
}
mcp__flow-nexus__agent_list { : }
npx claude-flow@alpha memory store --key --value
mcp__flow-nexus__swarm_scale {
: ,
: 8
}
npx claude-flow@alpha hooks notify --message
adaptive-coordinator Actions:
cat > swarm/monitoring/monitor-agents.sh << 'EOF'
SWARM_ID="${SWARM_ID:-$(npx claude-flow@alpha memory retrieve --key swarm/swarm-id | jq -r '.value')}"
echo "Monitoring swarm: $SWARM_ID"
echo "================================"
mcp__flow-nexus__agent_metrics --agentId="all"
mcp__flow-nexus__swarm_status --swarm_id="$SWARM_ID"
UTILIZATION=$(mcp__flow-nexus__agent_metrics | jq '.avg_utilization')
if (( $(echo "$UTILIZATION > 0.85" | bc -l) )); then
echo "WARNING: High utilization detected ($UTILIZATION)"
echo "Consider scaling up the swarm"
fi
echo "================================"
echo "Monitoring complete"
EOF
chmod +x swarm/monitoring/monitor-agents.sh
npx claude-flow@alpha hooks post-edit --file "swarm/monitoring/monitor-agents.sh" --memory-key "swarm/monitor-script"
Success Criteria:
Memory Persistence:
npx claude-flow@alpha memory store \
--key "swarm/phase2-complete" \
--value "{\"status\": \"complete\", \"agents_deployed\": 8, \"coordinator\": \"$COORDINATOR_ID\", \"timestamp\": \"$(date -Iseconds)\"}"
Phase 3: Coordinate Workflows
Objective: Create event-driven workflows with agent coordination and task routing
Evidence-Based Validation:
- Workflows created successfully
- Tasks being executed
- Event-driven processing active
- Message queue operational
hierarchical-coordinator Actions:
cat > swarm/workflows/main-workflow.json << 'EOF'
{
"id": "main-workflow",
"name": "Full-Stack Development Workflow",
"description": "Coordinate backend and frontend development with testing",
"steps": [
{
"id": "step1",
"name": "Requirements Analysis",
"agent": "coordinator",
"action": "analyze_requirements",
"output": "requirements_doc"
},
{
"id": "step2",
"name": "Backend Development",
"agent": "supervisor-backend",
"action": "coordinate_backend",
"dependencies": ["step1"],
"parallel": true,
"subtasks": [
{
"name": "API Development",
"agent": "worker-coder-1"
},
{
"name": "Database Schema",
"agent": "worker-coder-2"
}
]
},
{
"id": "step3",
"name": "Frontend Development",
"agent": "supervisor-frontend",
: ,
: [],
: ,
: [
{
: ,
:
}
]
},
{
: ,
: ,
: ,
: ,
: [, ]
},
{
: ,
: ,
: ,
: ,
: []
},
{
: ,
: ,
: ,
: ,
: []
}
],
: [
{
: ,
:
},
{
: ,
:
}
]
}
EOF
npx claude-flow@alpha hooks post-edit --file --memory-key
flow-nexus-swarm Actions:
mcp__flow-nexus__workflow_create {
"name": "Full-Stack Development Workflow",
"description": "Coordinate backend and frontend development with testing",
"steps": [
{
"name": "Requirements Analysis",
"agent_type": "coordinator"
},
{
"name": "Backend Development",
"agent_type": "supervisor",
"parallel": true
},
{
"name": "Frontend Development",
"agent_type": "supervisor",
"parallel": true
},
{
"name": "Testing",
"agent_type": "worker"
},
{
"name": "Code Review",
"agent_type": "worker"
},
{
"name": "Documentation",
"agent_type": "worker"
}
],
"triggers": [
{ "event": "pull_request_created" },
{ "event": "code_pushed" }
],
"priority": 8,
"metadata": {
"category": "development",
"tags": ["fullstack", "automated"]
}
}
WORKFLOW_ID=
npx claude-flow@alpha memory store --key --value
mcp__flow-nexus__workflow_agent_assign {
: ,
: ,
:
}
mcp__flow-nexus__workflow_execute {
: ,
: {
: ,
:
},
:
}
EXECUTION_ID=
npx claude-flow@alpha memory store --key --value
npx claude-flow@alpha hooks notify --message
adaptive-coordinator Actions:
cat > swarm/monitoring/monitor-workflow.sh << 'EOF'
WORKFLOW_ID="${WORKFLOW_ID:-$(npx claude-flow@alpha memory retrieve --key swarm/workflow-id | jq -r '.value')}"
echo "Monitoring workflow: $WORKFLOW_ID"
echo "================================"
mcp__flow-nexus__workflow_status \
--workflow_id="$WORKFLOW_ID" \
--include_metrics=true
mcp__flow-nexus__workflow_queue_status \
--include_messages=true
mcp__flow-nexus__workflow_audit_trail \
--workflow_id="$WORKFLOW_ID" \
--limit=50
echo "================================"
EOF
chmod +x swarm/monitoring/monitor-workflow.sh
npx claude-flow@alpha hooks post-edit --file "swarm/monitoring/monitor-workflow.sh" --memory-key "swarm/workflow-monitor"
Success Criteria:
Memory Persistence:
npx claude-flow@alpha memory store \
--key "swarm/phase3-complete" \
--value "{\"status\": \"complete\", \"workflow_id\": \"$WORKFLOW_ID\", \"execution_id\": \"$EXECUTION_ID\", \"timestamp\": \"$(date -Iseconds)\"}"
Phase 4: Monitor Performance
Objective: Track swarm performance, collect metrics, identify bottlenecks
Evidence-Based Validation:
- Metrics being collected
- Performance within acceptable range
- No critical bottlenecks
- Dashboards accessible
hierarchical-coordinator Actions:
cat > swarm/monitoring/analyze-performance.sh << 'EOF'
SWARM_ID="${SWARM_ID:-$(npx claude-flow@alpha memory retrieve --key swarm/swarm-id | jq -r '.value')}"
echo "Performance Analysis: $SWARM_ID"
echo "================================"
echo "Agent Metrics:"
mcp__flow-nexus__agent_metrics --metric="all"
echo -e "\nWorkflow Metrics:"
mcp__flow-nexus__workflow_status --include_metrics=true
echo -e "\nSystem Health:"
mcp__flow-nexus__system_health
echo -e "\n================================"
echo "Performance Summary:"
echo "- Average agent utilization: [calculated]"
echo "- Workflow completion rate: [calculated]"
echo "- Average response time: [calculated]"
echo "- Error rate: [calculated]"
echo "================================"
EOF
chmod +x swarm/monitoring/analyze-performance.sh
npx claude-flow@alpha hooks post-edit --file "swarm/monitoring/analyze-performance.sh" --memory-key "swarm/perf-analysis"
flow-nexus-swarm Actions:
SWARM_ID=$(npx claude-flow@alpha memory retrieve --key "swarm/swarm-id" | jq -r '.value')
mcp__flow-nexus__swarm_status {
"swarm_id": "$SWARM_ID",
"verbose": true
}
mcp__flow-nexus__agent_metrics { "metric": "all" }
WORKFLOW_ID=$(npx claude-flow@alpha memory retrieve --key "swarm/workflow-id" | jq -r '.value')
mcp__flow-nexus__workflow_status {
"workflow_id": "$WORKFLOW_ID",
"include_metrics": true
}
npx claude-flow@alpha memory store \
--key "swarm/performance-metrics" \
--value "{\"avg_utilization\": 0.72, \"throughput_tps\": 12, \"avg_response_ms\": 2400, \"error_rate\": 0.02, \"timestamp\": \"$(date -Iseconds)\"}"
adaptive-coordinator Actions:
cat > swarm/monitoring/performance-report.md << 'EOF'
**Generated:** $(date -Iseconds)
**Swarm ID:** $SWARM_ID
- **Topology:** Hierarchical
- **Total Agents:** 8 (1 coordinator, 2 supervisors, 5 workers)
- **Active Workflows:** 1
- Average: 72%
- Coordinator: 85%
- Supervisors: 78%
- Workers: 68%
- Tasks per second: 12
- Tasks completed: [calculated]
- Tasks pending: [calculated]
- Average: 2.4s
- p50: 1.8s
- p95: 4.2s
- p99: 6.8s
- Overall: 2%
- By agent type:
- Coordinator: 0%
- Supervisors: 1%
- Workers: 3%
- Worker-coder-1 at 95% utilization (bottleneck)
- Message queue backlog: 23 tasks
1. Scale up worker agents (+2)
2. Optimize task distribution algorithm
3. Increase message queue capacity
4. Consider specialized worker for high-load tasks
- CPU: 65% average
- Memory: 4.2GB / 16GB
- Network I/O: 120 Mbps
Based on current metrics:
- **Immediate**: Add 1 worker agent
- **Short-term**: Optimize coordinator algorithm
- **Long-term**: Implement auto-scaling policies
EOF
npx claude-flow@alpha hooks post-edit --file "swarm/monitoring/performance-report.md" --memory-key "swarm/perf-report"
Success Criteria:
Memory Persistence:
npx claude-flow@alpha memory store \
--key "swarm/phase4-complete" \
--value "{\"status\": \"complete\", \"performance_good\": true, \"bottleneck_identified\": true, \"timestamp\": \"$(date -Iseconds)\"}"
Phase 5: Scale and Optimize
Objective: Implement auto-scaling, optimize performance, adapt topology dynamically
Evidence-Based Validation:
- Scaling policies active
- Performance improved
- Auto-scaling working
- Optimization applied
hierarchical-coordinator Actions:
cat > swarm/config/scaling-policy.json << 'EOF'
{
"auto_scaling": {
"enabled": true,
"min_agents": 5,
"max_agents": 15,
"rules": [
{
"name": "scale_up_high_utilization",
"condition": "avg_utilization > 0.80 for 5 minutes",
"action": "add_agents",
"count": 2,
"cooldown": 300
},
{
"name": "scale_down_low_utilization",
"condition": "avg_utilization < 0.30 for 10 minutes",
"action": "remove_agents",
"count": 1,
"cooldown": 600
},
{
"name": "scale_up_queue_backlog",
"condition": "queue_size > 50",
"action": "add_agents",
"count": 3,
"cooldown": 180
}
]
},
"optimization": {
"task_distribution": "load_balanced",
"agent_specialization": true,
"dynamic_reassignment": true,
"priority_queuing": true
}
}
EOF
npx claude-flow@alpha hooks post-edit --file "swarm/config/scaling-policy.json" --memory-key "swarm/scaling-policy"
npx claude-flow@alpha hooks post-task --task-id
flow-nexus-swarm Actions:
SWARM_ID=$(npx claude-flow@alpha memory retrieve --key "swarm/swarm-id" | jq -r '.value')
mcp__flow-nexus__swarm_scale {
"swarm_id": "$SWARM_ID",
"target_agents": 10
}
mcp__flow-nexus__agent_spawn {
"type": "coder",
"name": "worker-coder-3",
"capabilities": ["task_execution", "specialization"]
}
mcp__flow-nexus__agent_spawn {
"type": "coder",
"name": "worker-coder-4",
"capabilities": ["task_execution", "specialization"]
}
mcp__flow-nexus__swarm_status {
"swarm_id": "$SWARM_ID",
"verbose": true
}
npx claude-flow@alpha memory store \
--key "swarm/final-config" \
--value "{\"swarm_id\": \"$SWARM_ID\", \"agents\": 10, \"scaled\": true, \"timestamp\": \"$(date -Iseconds)\"}"
adaptive-coordinator Actions:
cat > swarm/monitoring/auto-scale-monitor.sh << 'EOF'
SWARM_ID="${SWARM_ID:-$(npx claude-flow@alpha memory retrieve --key swarm/swarm-id | jq -r '.value')}"
echo "Auto-Scaling Monitor: $SWARM_ID"
echo "================================"
while true; do
METRICS=$(mcp__flow-nexus__agent_metrics --metric="all")
UTILIZATION=$(echo "$METRICS" | jq '.avg_utilization')
AGENT_COUNT=$(mcp__flow-nexus__swarm_status --swarm_id="$SWARM_ID" | jq '.agent_count')
echo "[$(date -Iseconds)] Utilization: $UTILIZATION, Agents: $AGENT_COUNT"
if (( $(echo "$UTILIZATION > 0.80" | bc -l) )); then
echo "High utilization detected. Scaling up..."
NEW_COUNT=$((AGENT_COUNT + 2))
if [ $NEW_COUNT -le 15 ]; then
mcp__flow-nexus__swarm_scale --swarm_id="$SWARM_ID" --target_agents=$NEW_COUNT
fi
elif (( $(echo "$UTILIZATION < 0.30" | bc -l) )); then
NEW_COUNT=$((AGENT_COUNT - ))
[ -ge 5 ];
mcp__flow-nexus__swarm_scale --swarm_id= --target_agents=
300
EOF
+x swarm/monitoring/auto-scale-monitor.sh
> swarm/docs/DEPLOYMENT-SUMMARY.md <<
**Deployment Date:** $( -Iseconds)
**Swarm ID:**
- **Topology:** Hierarchical
- **Initial Agents:** 8
- **Final Agents:** 10
- **Auto-scaling:** Enabled (5-15 agents)
- coordinator-main: Task delegation, monitoring, optimization
- supervisor-backend: Backend development coordination
- supervisor-frontend: Frontend development coordination
- worker-coder-1, 2, 3, 4: Implementation
- worker-tester: Testing and validation
- worker-reviewer: Code review
- worker-docs: Documentation
- Full-Stack Development Workflow (executing)
- Event-driven processing enabled
- Message queue operational
- Average utilization: 72%
- Throughput: 12 TPS
- Response : 2.4s avg
- Error rate: 2%
- Real- metrics collection
- Auto-scaling monitor running
- Performance analysis available
- Audit trail active
1. Monitor auto-scaling behavior
2. Optimize task distribution
3. Fine-tune performance thresholds
4. Add custom workflows as needed
5. Review and adjust scaling policies
- Swarm status: `mcp__flow-nexus__swarm_status`
- Agent metrics: `mcp__flow-nexus__agent_metrics`
- Workflow status: `mcp__flow-nexus__workflow_status`
- Performance: `./swarm/monitoring/analyze-performance.sh`
EOF
npx claude-flow@alpha hooks post-edit --file --memory-key
npx claude-flow@alpha hooks post-edit --file --memory-key
npx claude-flow@alpha hooks session-end --export-metrics
Success Criteria:
Memory Persistence:
npx claude-flow@alpha memory store \
--key "swarm/phase5-complete" \
--value "{\"status\": \"complete\", \"agents\": 10, \"auto_scaling\": true, \"optimized\": true, \"timestamp\": \"$(date -Iseconds)\"}"
npx claude-flow@alpha memory store \
--key "swarm/workflow-complete" \
--value "{\"status\": \"success\", \"swarm_id\": \"$SWARM_ID\", \"agents\": 10, \"workflow_executing\": true, \"auto_scaling\": true, \"timestamp\": \"$(date -Iseconds)\"}"
Workflow Summary
Total Estimated Duration: 40-70 minutes
Phase Breakdown:
- Initialize Cloud Swarm: 5-10 minutes
- Deploy Agents to Cloud: 10-15 minutes
- Coordinate Workflows: 10-15 minutes
- Monitor Performance: 10-15 minutes
- Scale and Optimize: 5-15 minutes
Key Deliverables:
- Cloud swarm deployment
- 10 specialized agents
- Event-driven workflows
- Performance monitoring
- Auto-scaling system
- Complete documentation
Evidence-Based Success Metrics
Swarm Deployment:
- Swarm initialized successfully
- All agents deployed (10)
- Topology configured correctly
Workflows:
- Workflow executing
- Event-driven processing active
- Task completion rate >90%
Performance:
- Average utilization 70-80%
- Response time <3s
- Error rate <5%
- Throughput >10 TPS
Scaling:
- Auto-scaling functional
- Scaling policies effective
- Performance improved after scaling
Troubleshooting
Swarm Initialization Failed:
- Verify Flow Nexus authentication
- Check account credits
- Review topology configuration
Agent Deployment Issues:
- Check E2B sandbox availability
- Verify agent specifications
- Review resource limits
Workflow Execution Errors:
- Check agent assignments
- Verify task dependencies
- Review event triggers
Performance Issues:
- Analyze bottlenecks
- Scale up agents
- Optimize task distribution
Auto-scaling Not Working:
- Verify scaling policies
- Check metric thresholds
- Review cooldown periods
Best Practices
- Topology Selection: Choose based on task complexity
- Agent Specialization: Assign clear roles
- Monitoring: Track all metrics
- Scaling: Start small, scale gradually
- Optimization: Iterate based on metrics
- Documentation: Keep updated
- Testing: Validate workflows thoroughly
- Resources: Monitor costs and usage
References