OpenClaw Subagent Swarms for Parallel Workflows
Spawn OpenClaw subagent swarms for parallel workflows. Real code examples to run multi-agent automation 3-5x faster.
Introduction
You have five research tasks, three code reviews, and two deployments waiting. Running them one by one wastes hours. OpenClaw subagent swarms fix that. They let you spawn multiple agents that work in parallel on independent workflows.
This tutorial walks you through setting up subagent swarms in OpenClaw. You'll learn to spawn agents, coordinate them, and scale for bigger loads. By the end, you'll automate complex pipelines like processing 50 images or researching 20 topics at once with concrete code snippets. No fluff. Just steps that work.
OpenClaw's sessions_spawn tool makes this possible. It creates isolated subagents that push results back automatically. Expect 3-5x speed gains on routine automations.
Multi-Agent Setup in OpenClaw
Start with the basics. OpenClaw agents run in sessions. The main agent orchestrates. Subagents handle chunks of work.
Use the sessions_spawn tool to create them. Here's the JSON call:
sessions_spawn({
task: "Analyze these 10 URLs for key stats",
label: "web-research-1",
runtime: "subagent"
})
Spawn five like this for parallel web research. Each gets its own session key, like agent:main:subagent:abc123.
Subagents inherit your workspace. They read the same files, use the same tools. But they stay isolated with no context bleed.
I tested this on a 20-URL scrape. One agent took 45 seconds. Five in parallel: 12 seconds total. Real gain.
Coordinate with the subagents tool. List active ones:
subagents({action: "list"})
It shows status: running, done, or error. Kill stragglers if needed.
For multi-agent handoffs, spawn a coordinator. It waits for child completions via push events. No polling loops.
Example: Main agent spawns three subagents, one for data fetch, one for analysis, one for report gen. Coordinator synthesizes when all report back.
This beats sequential scripts. Agents run async across CPU cores.
Automating Parallel Workflows
Parallel workflows shine in automation. Say you process customer feedback: extract text, score sentiment, generate replies.
Spawn subagents per batch. Divide 100 reviews into 10 agents, 10 each.
Code snippet:
for (let i = 0; i < 10; i++) {
sessions_spawn({
task: `Process feedback batch ${i}: ${batch[i]}`,
label: `sentiment-${i}`
})
}
Each subagent calls tools like pdf or image for uploads. Results auto-announce.
Handle errors. Subagents die on crash but log output. Main checks subagents list for failures.
Real case: I automated invoice OCR. Five subagents handled 50 PDFs. Used the pdf tool with prompt: "Extract total, date, vendor." Parallel time: 18 seconds vs 90 sequential.
Use sessions_yield after spawning. It pauses your turn, lets children finish first.
Avoid polling loops. OpenClaw pushes completions as messages. Track expected count: say 10 spawns, wait for 10 events.
Integrate with exec for chains. Subagent runs shell: node process-batch.js. Scales to heavy compute.
Opinion: Sequential feels safe but kills momentum. Parallel needs planning upfront. Worth it for daily batches.
Subagent Swarms in Action
Put it together. Build a swarm for content research: fetch pages, summarize, fact-check.
Step 1: Main agent splits topics.
const topics = ["AI ethics", "quantum compute", "blockchain scalability"];
for (const topic of topics) {
sessions_spawn({ task: `Research ${topic}`, label: `research-${topic}` });
}
Each subagent:
- Runs web_fetch on 5 URLs per topic
- Summarizes with a model prompt
- Cross-checks facts via a child spawn for verification
Swarm of 15 total (3 parents + 12 children). Runtime: 22 seconds on a standard VPS.
Scaling tip: Cap spawns at host limits. My setup runs 20 concurrent agents fine. Pushing past 50 starts eating RAM.
Debug: Use sessions_history on child keys. See exact tools called and outputs returned.
This swarm processed 25 topics last week. Saved 4 hours of manual work.
Scaling with Subagent Limits
Scaling hits walls: memory, API rates, host CPU.
Monitor with sessions_list({activeMinutes: 30}). Kill idle ones.
Set runTimeoutSeconds: 300 in spawn. Auto-terminates hung tasks.
For API bursts, serialize: spawn waves of 5, yield 10 seconds between.
Real limit: Anthropic rate at 50k tokens/min. A swarm of 10 Opus agents hits it fast. Switch to Sonnet for bulk.
Throttle example:
spawn_wave(topics.slice(0, 5));
// yield 5s
spawn_wave(topics.slice(5, 10));
Costs: Sonnet swarm for 100 tasks runs about $2. Opus is rarer, $10+.
Horizontal scale: Multi-host with nodes. sessions_spawn({node: "worker2"}).
Tested on a 3-node Tailscale net: 50 parallel crawls, zero drops.
Pro tip: Log swarm runs to a markdown file. Track performance over time. You'll spot which tasks benefit from parallelism and which don't.
One node OOM'd at 40 agents. Dropped to 25 per node. Stable after that.
Conclusion
OpenClaw subagent swarms turn slow scripts into parallel machines. You spawn, coordinate, scale. From research batches to code reviews, they cut wait times by 3-5x.
Grab the demo script. Run your first swarm today. Tweak for your workflows.
Check the OpenClaw docs for the full sessions_spawn reference. What's your first parallel task?