Principle:1jehuang Jcode Swarm Coordination
| Knowledge Sources | |
|---|---|
| Domains | Multi_Agent_Systems, Distributed_Systems |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
Coordination pattern that fans out multiple autonomous agents in parallel within a single repository, using a versioned task plan, inter-agent messaging channels, and automatic salvage of dead member assignments.
Description
Swarm coordination is a multi-agent execution model where a coordinator agent decomposes a user request into independent subtasks, spawns worker agents to execute them in parallel, and integrates the results. Unlike simple map-reduce, the workers are autonomous agents that can communicate with each other and the coordinator through typed channels (direct messages, broadcasts), modify shared files (with conflict detection), and dynamically update the plan as work progresses.
The problem solved is sequential bottleneck: a single agent processing a large task linearly is slow. By decomposing into independent subtasks and running them in parallel, throughput increases proportionally to the number of workers. The key challenges are: (1) task decomposition and scope assignment, (2) inter-agent communication, (3) conflict detection when multiple agents touch the same files, and (4) lifecycle management (detecting dead workers and reassigning their work).
The design uses a versioned plan: each plan revision has a version number, and workers can propose updates that the coordinator approves and broadcasts. This ensures all members agree on what work is assigned to whom.
Usage
Use this principle when a task is large enough to benefit from parallelism and can be decomposed into mostly-independent subtasks. The trigger is /effort swarm activation, which prompts the coordinator to decompose the request into subtasks. It is appropriate for: repository-wide refactors, multi-file feature implementation, and large-scale test suites. It is not appropriate for tightly-coupled tasks where every step depends on the previous one.
Theoretical Basis
The coordination model has four core operations:
- Decompose: The coordinator LLM parses the user request into a JSON array of subtask plans, each with a description, prompt, and subagent type.
- Spawn: For each subtask, a new session and agent are created with the coordinator's provider, model, and working directory. The worker reports back to the coordinator via
report_back_to_session_id. - Communicate: Workers and coordinator exchange messages through channels (direct message, broadcast, file-touch signals). Status updates are debounced and fanned out to all sessions.
- Integrate: When a worker completes, its output is captured and returned to the coordinator. Dead workers have their assignments salvaged to the coordinator for reassignment.
Pseudo-code logic:
# Abstract algorithm (NOT real implementation)
def run_swarm(coordinator, user_request):
# 1. Decompose
subtasks = coordinator.llm_parse(user_request, format=subtask_schema)
# 2. Spawn workers
for task in subtasks:
member = SwarmMember(
session_id=new_session(),
report_back_to=coordinator.session_id,
task_label=task.description,
)
swarm_members[member.session_id] = member
spawn_agent(member, task.prompt)
# 3. Monitor lifecycle
while swarm_has_active_members():
handle_channel_messages()
salvage_dead_member_assignments()
prune_expired_terminal_members()
# 4. Collect results
return coordinator.integrate_outputs()
The spawn tree is encoded by report_back_to_session_id: walking this chain upward reconstructs the spawn tree without a separate parent field. An agent owns its entire spawned subtree for management decisions.