Promise.all, while, and if to fan out work, collect
results, and make decisions.
There is no graph DSL and no separate workflow format. The program is the
orchestration. Swarm adds awaitable collector children, structured results,
bounded concurrency, and progress reporting to that program.
Enable Swarm
The recommended path is Settings → Labs → Swarm in the Control UI. The toggle takes effect immediately and writestools.swarm.enabled to your
configuration.
You can also enable Swarm directly in openclaw.json:
Numeric values must be positive integers. OpenClaw bounds
maxConcurrent to 1–1000, maxChildrenPerGroup to 1–10000,
maxTotalPerGroup to 1–100000, and waitTimeoutSecondsMax to
1–86400.
You can override Swarm for one configured agent with
agents.list[].tools.swarm. The per-agent object merges over the top-level
tools.swarm object.
Requirements
Theagents.run, phase, and log guest globals require both Swarm and
OpenClaw Code Mode:
sessions_spawn. Tool profiles,
allow/deny policy, provider rules, and sandbox policy can remove that tool.
See Code Mode activation and
Sub-agents if a script reports that sessions_spawn is
unavailable.
defaultAgentId and per-run agentId values must name a configured target
permitted by the requester’s subagents.allowAgents policy. OpenClaw rejects
an unknown or disallowed target instead of falling back to another agent.
Write a Swarm script
When Swarm is enabled, Code Mode exposes this guest API:schema, agents.run() resolves to the child’s final text. With a
JSON Schema, it resolves to the value submitted through the child’s
structured_output tool. A failed, killed, timed-out, or schema-invalid child
rejects the promise with a SwarmAgentError. Read the exact generated
declarations and short orchestration idioms from API.read("agents.d.ts")
inside Code Mode.
Use label for a recognizable child name in the dashboard and sidebar. Use
phase in the options to publish a phase immediately before that child
starts, or call phase() when several children belong to the same stage.
log() publishes a short progress note. Progress calls are fire-and-forget;
they do not delay the script if the UI is unavailable.
Fan out in parallel with structured results
This example launches one researcher per topic, waits for all of them, then asks a final child to synthesize their structured reports:Promise.all is the fan-out and fan-in boundary. OpenClaw starts up to
maxConcurrent children for the group and queues the rest in submission
order.
Loop on a decision gate
Use a boundedwhile loop when each pass decides whether another pass is
needed:
maxTotalPerGroup is the final safety backstop,
not a substitute for a clear stopping condition.
Process the first child that finishes
agents.run() returns an ordinary promise, so Promise.race can react to the
first Code Mode child. For harnesses that call the lower-level tools,
agents_wait provides the same first-completion boundary: it returns as soon
as at least one requested run completes, or when the bounded timeout expires.
See Use Swarm from other harnesses for the
complete drain loop.
How collector children behave
Collector children are ordinary isolated sub-agent sessions with a different completion path. They write a durable collector result for the parent to await instead of announcing or steering a reply back into the parent session. The target agent resolves in this order:agentIdon the spawn oragents.run()call.tools.swarm.defaultAgentId.- The requesting agent.
worker agent id; configure one before naming it as the default.
Harden that worker with tools.swarm: false in its per-agent configuration so
it can be spawned but cannot start swarms from its own top-level sessions:
structured_output tool to
the child and validates its payload against the supplied JSON Schema. An
invalid or missing payload gets one corrective nudge. If the retry still does
not validate, the collector completion keeps the child’s raw text, leaves
structured unset, and includes schemaError. The low-level agents_wait
result exposes those fields for explicit recovery logic.
Children are leaves
Swarm children are leaves by default. The universalagents.defaults.subagents.maxSpawnDepth guard prevents a child from spawning
its own children at the default depth of 1. The usual orchestration idiom is
to return work to the parent, not spawn more work from a child:
agents.defaults.subagents.maxSpawnDepth and are discouraged for Swarm.
Group caps, budgets, and observability all assume flat collector groups.
Every child has one admission owner. Announce and interactive children use
agents.defaults.subagents.maxChildrenPerAgent (default 5) and do not count
collector children. Collector children use only maxChildrenPerGroup and
maxTotalPerGroup; they do not consume the per-session child budget. The spawn
depth guard still applies to both modes.
After admission, children above maxConcurrent queue FIFO within their swarm
group, nested inside the global sub-agent lane. These concurrency layers queue
work rather than rejecting it. A collector spawn that exceeds either group cap
is rejected with the relevant config key in the error.
Observe a Swarm
Open the parent session’s dashboard in the Control UI while a swarm is active. The Swarm widget renders each active collector group as one dot per child with queued, running, done, or failed state. Labels appear in dot tooltips, so short stable labels make larger swarms easier to read. The session sidebar keeps the normal parent/child tree. Expand the parent row to inspect a collector child or open its transcript without losing the swarm hierarchy. Collector results remain waitable until their group is archived. After every member reaches its retention deadline, OpenClaw archives the group’s children as a batch so completed swarms do not remain in the live session tree.Use Swarm from other harnesses
You can use Swarm without OpenClaw Code Mode. Its core tools are harness-independent: start collector children withsessions_spawn({ collect: true }) and drain them with bounded agents_wait
calls.
Codex Code Mode automatically exposes eligible dynamic OpenClaw tools under
tools.*. It does not use OpenClaw’s QuickJS guest API or require
tools.codeMode, but tools.swarm must still be enabled. Codex harness
agents_wait calls support the full 600-second timeout. Use this pattern:
agents_wait call accepts 1–1000 run ids. It returns:
pending is empty. Collector mode supports native
OpenClaw sub-agents; it does not support ACP runtime, thread binding, visible
sessions, or persistent session mode.
Limits and roadmap
Swarm v1 runs one-shot collector children; the plannedagents.session() API
will add stateful multi-turn workers. Children currently run on the local
Gateway’s sub-agent lane; cloud placement is planned as an explicit spawn
option. Saved workflow definitions and a graph DSL are not part of Swarm’s
current direction.
Related
- Code Mode for the QuickJS guest runtime and activation rules
- Sub-agents for child policy, isolation, and session behavior
- Multi-agent sandbox tools for per-agent restrictions
- Tools overview for tool profiles and policy routing