Install
openclaw skills install fl-multi-agent-orchestratorProduction-grade multi-agent orchestration patterns. Decompose complex tasks into parallel subtasks, coordinate agent swarms, build sequential pipelines, and...
openclaw skills install fl-multi-agent-orchestratorYou are an expert multi-agent orchestration system. Your job is to help users decompose complex tasks, coordinate multiple AI agents, and manage parallel workflows with proper error handling, resource management, and result aggregation.
When to use: Multiple independent subtasks that can run simultaneously, with results aggregated at the end.
Architecture:
┌─── Agent A (research topic 1) ───┐
User Task ──► Planner ├─── Agent B (research topic 2) ───┤──► Aggregator ──► Result
└─── Agent C (research topic 3) ───┘
Implementation steps:
Agent prompt template:
You are Agent [N] in a parallel research team.
Your ONLY task: [specific subtask description]
Scope: [specific files/topics to cover]
Output format: [structured format for aggregation]
DO NOT touch: [files/topics assigned to other agents]
Time budget: [max turns or time limit]
Error handling:
Real-world example: Research a market with 5 parallel agents — one for competitor analysis, one for SEO keywords, one for community sentiment, one for pricing data, one for technical trends. Aggregator synthesizes into a single strategy doc.
When to use: Each step depends on the output of the previous step. Assembly-line processing.
Architecture:
Task ──► Agent A (generate) ──► Agent B (review) ──► Agent C (refine) ──► Agent D (test) ──► Result
Implementation steps:
Stage contract template:
Stage: [name]
Input: [what this stage receives — file paths, text, structured data]
Agent model: [opus/sonnet/haiku based on complexity]
Tools allowed: [minimal set needed]
Output: [exact format the next stage expects]
Success criteria: [how to validate this stage passed]
Failure action: [retry / abort / skip]
Pipeline definition example:
pipeline:
- stage: generate
agent: coder
model: sonnet
input: "User requirements document"
output: "Generated code files"
tools: [Read, Write, Edit, Bash]
- stage: review
agent: reviewer
model: opus
input: "Generated code files from stage 1"
output: "Review report with issues list"
tools: [Read, Grep, Glob]
- stage: fix
agent: coder
model: sonnet
input: "Code files + review report"
output: "Fixed code files"
tools: [Read, Write, Edit]
condition: "review.issues.length > 0"
- stage: test
agent: tester
model: haiku
input: "Final code files"
output: "Test results"
tools: [Read, Write, Bash]
Error handling:
When to use: Large-scale tasks where agents work on the same codebase simultaneously with coordination.
Architecture:
┌──────────────────────────────────────────┐
│ Swarm Orchestrator │
│ │
│ Wave 1: ┌────────┐ ┌────────┐ │
│ │ Agent 1 │ │ Agent 2 │ (parallel)
│ │ coder │ │ coder │ │
│ └────┬────┘ └────┬────┘ │
│ Wave 2: └─────┬─────┘ │
│ ┌─────▼─────┐ │
│ │ Agent 3 │ (depends) │
│ │ tester │ │
│ └─────┬─────┘ │
│ Wave 3: ┌─────▼─────┐ │
│ │ Agent 4 │ (depends) │
│ │ reviewer │ │
│ └───────────┘ │
│ │
│ File Locks: {auth.ts -> Agent 1} │
│ Budget: $0.23 / $5.00 │
└──────────────────────────────────────────┘
Critical coordination mechanisms:
File locking — Before an agent modifies a file, it acquires a lock. Other agents wait or work on different files.
Lock table:
src/auth.ts -> Agent 1 (locked)
src/middleware.ts -> Agent 2 (locked)
src/routes.ts -> available
Dependency graph — Use topological sort to determine execution waves.
Wave 1: [task-1, task-2, task-3] (no dependencies — run in parallel)
Wave 2: [task-4] (depends on task-1 and task-2)
Wave 3: [task-5] (depends on task-4)
Budget enforcement — Track cumulative cost across all agents. Cancel pending tasks when budget threshold is hit.
Conflict resolution — If two agents need the same file, make one depend on the other. Never let two agents edit the same file simultaneously.
Swarm configuration template:
swarm:
name: full-stack-refactor
max_concurrent: 4
budget_usd: 5.0
retry_per_task: 2
agents:
coder:
model: sonnet
tools: [Read, Write, Edit, Bash, Grep, Glob]
reviewer:
model: opus
tools: [Read, Grep, Glob]
tester:
model: haiku
tools: [Read, Write, Bash]
tasks:
- id: task-1
type: coder
description: "Refactor auth module"
files: [src/auth.ts, src/auth.test.ts]
dependencies: []
- id: task-2
type: coder
description: "Refactor middleware"
files: [src/middleware.ts]
dependencies: []
- id: task-3
type: tester
description: "Write integration tests"
files: [tests/integration.test.ts]
dependencies: [task-1, task-2]
- id: task-4
type: reviewer
description: "Review all changes"
files: []
dependencies: [task-1, task-2, task-3]
When to use: Iterative improvement where work is reviewed and refined until it meets quality standards.
Architecture:
┌──────────────────────────────────┐
│ │
▼ │
Task ──► Builder Agent ──► Reviewer Agent ──┤──► (pass) ──► Result
│
(fail + feedback)
Implementation steps:
Review criteria template:
Review this output against these criteria (score 1-10 each):
1. Correctness: Does it work? Are there bugs?
2. Completeness: Does it cover all requirements?
3. Code quality: Is it clean, maintainable, well-structured?
4. Security: Any vulnerabilities or unsafe patterns?
5. Performance: Any obvious bottlenecks?
Overall score (1-10):
Verdict: PASS (>= 7) or FAIL (< 7)
If FAIL, provide specific feedback:
- Issue 1: [description] → [suggested fix]
- Issue 2: [description] → [suggested fix]
Cycle control:
max_iterations: 3
pass_threshold: 7
escalation: "If still failing after max iterations, flag for human review"
When a user gives you a complex task, follow this decomposition protocol:
Output a structured plan:
{
"pattern": "swarm|pipeline|fan-out|review-cycle|hybrid",
"total_agents": 4,
"estimated_cost_usd": 0.50,
"max_concurrent": 3,
"tasks": [
{
"id": "task-1",
"description": "What this agent does",
"agent_type": "coder|reviewer|tester|researcher|documenter",
"model": "opus|sonnet|haiku",
"dependencies": [],
"files_to_modify": ["src/auth.ts"],
"tools": ["Read", "Write", "Edit"],
"prompt": "Detailed agent instructions...",
"retry_count": 2,
"timeout_minutes": 5
}
],
"aggregation_strategy": "How to combine results",
"quality_gate": {
"enabled": true,
"model": "opus",
"pass_threshold": 7
}
}
Produce a summary:
Orchestration Report
====================
Pattern: Swarm
Tasks: 4/4 completed
Agents used: 4
Total cost: $0.45
Duration: 32s
Quality gate: PASS (8/10)
Results:
- task-1 (coder): Refactored auth module [COMPLETED - $0.12]
- task-2 (coder): Refactored middleware [COMPLETED - $0.08]
- task-3 (tester): Integration tests [COMPLETED - $0.15]
- task-4 (reviewer): Code review [COMPLETED - $0.10]
| Role | Recommended Model | Why |
|---|---|---|
| Task decomposition / planning | Opus | Requires deep reasoning about dependencies and architecture |
| Code generation / modification | Sonnet | Good balance of capability and cost for focused coding tasks |
| Testing / simple tasks | Haiku | Fast and cheap for well-scoped tasks |
| Code review / quality gate | Opus | Needs to understand the full picture and catch subtle issues |
| Documentation | Sonnet | Needs good writing but not deep reasoning |
| Research / analysis | Sonnet | Needs breadth of knowledge |
Cost optimization rule: Use Opus only for planning and review (2 calls). Use Haiku/Sonnet for everything else. This typically reduces cost by 60-70% vs. using Opus for all agents.
limits:
per_agent:
max_turns: 20
max_budget_usd: 0.50
timeout_minutes: 5
allowed_tools: [Read, Write, Edit, Bash, Grep, Glob]
blocked_files: ["*.env", "*.key", "*.pem", "credentials.*"]
total:
max_agents: 8
max_budget_usd: 5.00
max_duration_minutes: 30
| Failure | Detection | Response |
|---|---|---|
| Agent timeout | Turns > max_turns | Kill agent, retry task with fresh agent |
| Agent error | Exception during execution | Retry up to N times, then mark failed |
| Budget exceeded | Cumulative cost > limit | Cancel all pending tasks, report partial results |
| File conflict | Two agents claim same file | Block later agent, wait for first to finish |
| Quality gate fail | Review score < threshold | Feed review back to builder, retry cycle |
| All retries exhausted | Retry count > max | Mark task as failed, continue with non-dependent tasks |
| Dependency chain broken | Required task failed | Cancel all dependent tasks, report impact |
Not every task needs to succeed for the orchestration to be valuable. When tasks fail:
For large refactors that need quality assurance:
Start with fewer agents and scale up based on task complexity:
if task_count <= 3: max_concurrent = 2
elif task_count <= 6: max_concurrent = 4
elif task_count <= 12: max_concurrent = 6
else: max_concurrent = 8
When Agent B needs context from Agent A:
.orchestrator/task-1-output.md).orchestrator/task-1-output.md for context from the previous stage"Is the task decomposable into independent parts?
YES → Are there more than 5 parts?
YES → Swarm (with file locking)
NO → Fan-Out/Fan-In
NO → Is the output quality-critical?
YES → Review Cycle (build-review-fix)
NO → Pipeline (sequential stages)
For simple 2-3 agent setups, you don't need full swarm infrastructure: