🐝Swarm Tools
Packagesopencode-swarm-plugin

Swarm Tools

Task decomposition, parallel orchestration, and learning systems

Swarm Tools

Task decomposition, parallel orchestration, and learning systems. Swarm tools handle multi-agent coordination with file reservations and outcome tracking.

Swarm Mail Tools

Inter-agent messaging with file reservations. Backed by event sourcing via swarm-mail package.

swarmmail_init

Initialize Swarm Mail session. MANDATORY before using other swarmmail tools.

Parameters:

ParameterTypeRequiredDescription
project_pathstringAbsolute path to project
agent_namestringCustom agent name (auto-generated if omitted)
task_descriptionstringCurrent task description

Example:

swarmmail_init({
  project_path: "/Users/joel/projects/my-app",
  task_description: "bd-123.2: Implementing OAuth service"
})
// Returns: { agent_name: "BlueLake", project_key: "/Users/joel/projects/my-app" }

Critical: Call this FIRST before modifying files in swarm workflows.


swarmmail_send

Send a message to other agents.

Parameters:

ParameterTypeRequiredDescription
tostring[]Recipient agent names
subjectstringMessage subject
bodystringMessage body
thread_idstringThread ID (use cell ID for swarm work)
importance"low" | "normal" | "high" | "urgent"Message priority (default: "normal")
ack_requiredbooleanRequire acknowledgment (default: false)

Example:

// Progress update to coordinator
swarmmail_send({
  to: ["coordinator"],
  subject: "Progress: bd-123.2",
  body: "Schema defined, starting service layer. ETA 20min.",
  thread_id: "bd-123"
})

// Blocker notification
swarmmail_send({
  to: ["coordinator"],
  subject: "BLOCKED: bd-123.2 needs database schema",
  body: "Can't proceed without db migration from bd-123.1",
  importance: "high",
  thread_id: "bd-123"
})

Returns: { message_id: 42, thread_id: "bd-123", recipient_count: 1 }


swarmmail_inbox

Fetch inbox messages. Context-safe: enforces limit: 5 max, excludes bodies by default.

Parameters:

ParameterTypeRequiredDescription
limitnumberMax messages (capped at 5)
urgent_onlybooleanOnly urgent messages

Example:

swarmmail_inbox({ limit: 5 })
// Returns headers only (no bodies)

Critical: Bodies excluded by default to preserve context. Use swarmmail_read_message for individual bodies.


swarmmail_read_message

Fetch ONE message body by ID.

Parameters:

ParameterTypeRequiredDescription
message_idnumberMessage ID from inbox

Example:

swarmmail_read_message({ message_id: 42 })
// Returns: { id: 42, subject: "...", body: "...", from: "...", ... }

swarmmail_reserve

Reserve file paths for exclusive editing. Prevents conflicts with other agents.

Parameters:

ParameterTypeRequiredDescription
pathsstring[]File paths or patterns
reasonstringReservation reason (include cell ID)
exclusivebooleanExclusive lock (default: true)
ttl_secondsnumberLock TTL (default: 3600)

Example:

swarmmail_reserve({
  paths: ["src/auth/**", "src/lib/jwt.ts"],
  reason: "bd-123.2: Auth service implementation",
  ttl_seconds: 3600
})
// Returns: { granted: [{ id: 1, path_pattern: "src/auth/**", ... }] }

Critical: Reserve BEFORE editing files. Use cell ID in reason for traceability.


swarmmail_release

Release file reservations.

Parameters:

ParameterTypeRequiredDescription
pathsstring[]Specific paths to release
reservation_idsnumber[]Specific reservation IDs

Example:

// Release all reservations for current agent
swarmmail_release()

// Release specific paths
swarmmail_release({ paths: ["src/auth/**"] })

Critical: Auto-released by swarm_complete. Manual release only needed if aborting early.


Orchestration Tools

swarm_init

Initialize swarm session and check tool availability.

Parameters:

ParameterTypeRequiredDescription
project_pathstringProject path (defaults to cwd)

Example:

swarm_init({ project_path: "/Users/joel/projects/my-app" })
// Returns: { hive_available: true, swarmmail_available: true, ... }

swarm_select_strategy

Analyze task and recommend decomposition strategy (file-based, feature-based, risk-based).

Parameters:

ParameterTypeRequiredDescription
taskstringTask description
codebase_contextstringOptional codebase context

Example:

swarm_select_strategy({
  task: "Add OAuth authentication with refresh tokens"
})
// Returns: { strategy: "feature-based", rationale: "...", confidence: 0.85 }

swarm_decompose

Generate decomposition prompt with CASS history queries.

Parameters:

ParameterTypeRequiredDescription
taskstringTask description
max_subtasksnumberMax subtasks (default: 5)
query_cassbooleanQuery CASS history (default: true)
contextstringAdditional context
cass_limitnumberCASS result limit (default: 3)

Example:

swarm_decompose({
  task: "Add OAuth authentication",
  max_subtasks: 5,
  query_cass: true
})
// Returns prompt string with CASS context

swarm_validate_decomposition

Validate decomposition response against CellTreeSchema. Detects file conflicts and instruction conflicts.

Parameters:

ParameterTypeRequiredDescription
responsestringAgent's decomposition response

Example:

swarm_validate_decomposition({
  response: `{ "epic": {...}, "subtasks": [...] }`
})
// Returns: { valid: true, data: {...} } or { valid: false, errors: [...] }

swarm_plan_prompt

Generate strategy-specific decomposition prompt.

Parameters:

ParameterTypeRequiredDescription
taskstringTask description
strategy"file-based" | "feature-based" | "risk-based" | "auto"Strategy (default: "auto")
max_subtasksnumberMax subtasks (default: 5)
contextstringAdditional context
query_cassbooleanQuery CASS (default: true)
cass_limitnumberCASS limit (default: 3)

Example:

swarm_plan_prompt({
  task: "Add OAuth authentication",
  strategy: "feature-based",
  max_subtasks: 5
})

swarm_subtask_prompt

Generate worker agent prompt with cell context and Agent Mail instructions.

Parameters:

ParameterTypeRequiredDescription
agent_namestringWorker agent name
cell_idstringSubtask cell ID
epic_idstringEpic cell ID
subtask_titlestringSubtask title
subtask_descriptionstringSubtask description
filesstring[]Files to modify
shared_contextstringShared context from epic

Example:

swarm_subtask_prompt({
  agent_name: "BlueLake",
  cell_id: "bd-123.2",
  epic_id: "bd-123",
  subtask_title: "Implement OAuth flow",
  files: ["src/auth/oauth.ts", "src/auth/tokens.ts"],
  shared_context: "Use JWT with 5min refresh buffer"
})
// Returns full worker agent prompt

swarm_spawn_subtask

Prepare subtask for spawning with Task tool.

Parameters:

ParameterTypeRequiredDescription
cell_idstringSubtask cell ID
epic_idstringEpic cell ID
subtask_titlestringSubtask title
subtask_descriptionstringSubtask description
filesstring[]Files to modify
shared_contextstringShared context

Example:

swarm_spawn_subtask({
  cell_id: "bd-123.2",
  epic_id: "bd-123",
  subtask_title: "Implement OAuth flow",
  files: ["src/auth/oauth.ts"]
})
// Returns: { prompt: "...", files: [...] }

swarm_status

Get swarm progress by epic ID.

Parameters:

ParameterTypeRequiredDescription
epic_idstringEpic cell ID
project_keystringProject path

Example:

swarm_status({
  epic_id: "bd-123",
  project_key: "/Users/joel/projects/my-app"
})
// Returns: { total: 5, completed: 3, in_progress: 1, blocked: 1 }

swarm_progress

Report progress on a subtask to coordinator.

Parameters:

ParameterTypeRequiredDescription
project_keystringProject path
agent_namestringWorker agent name
cell_idstringSubtask cell ID
status"in_progress" | "blocked" | "completed" | "failed"Status
messagestringStatus message
progress_percentnumberProgress 0-100
files_touchedstring[]Files modified

Example:

swarm_progress({
  project_key: "/Users/joel/projects/my-app",
  agent_name: "BlueLake",
  cell_id: "bd-123.2",
  status: "in_progress",
  message: "Schema defined, starting service layer",
  progress_percent: 40,
  files_touched: ["src/auth/schema.ts"]
})

swarm_complete

Complete subtask with automatic release and learning signals.

Parameters:

ParameterTypeRequiredDescription
project_keystringProject path (finds cells via minimatch)
agent_namestringWorker agent name
cell_idstringSubtask cell ID
summarystringCompletion summary
files_touchedstring[]Files modified
evaluationstringSelf-evaluation

Example:

swarm_complete({
  project_key: "/Users/joel/projects/my-app",
  agent_name: "BlueLake",
  cell_id: "bd-123.2",
  summary: "OAuth flow implemented with JWT strategy",
  files_touched: ["src/auth/oauth.ts", "src/auth/tokens.ts"],
  evaluation: "Completed successfully, added unit tests"
})
// Auto-releases reservations, records learning signals

Critical: Workers MUST use this (not hive_close directly). Handles cleanup and learning.

Worker Handoff Protocol (v0.31+)

Workers complete tasks using swarm_complete, which orchestrates the full completion sequence:

What It Does:

  1. Finds cells - Uses path-based project_key with minimatch pattern matching
  2. Releases reservations - Auto-releases all file locks held by the worker
  3. Records learning signals - Tracks duration, errors, retries for pattern learning
  4. Closes the cell - Updates cell status to closed with completion reason

Why Not hive_close Directly?

Direct hive_close skips critical cleanup:

  • Reservations stay locked (blocks other agents)
  • No learning signals (decomposition patterns don't improve)

TDD Mandate (v0.31+)

All worker prompts now include TDD instructions:

  1. RED - Write a failing test first (if it passes, the test is wrong)
  2. GREEN - Minimum code to make it pass (hardcode if needed)
  3. REFACTOR - Clean up while tests stay green

This applies to:

  • Feature implementation
  • Bug fixes (write test that reproduces bug FIRST)
  • Refactoring (characterization tests before changes)

Workers are expected to follow this discipline. No exceptions for swarm work.


swarm_record_outcome

Record subtask outcome for learning (duration, errors, retries).

Parameters:

ParameterTypeRequiredDescription
cell_idstringSubtask cell ID
duration_msnumberDuration in milliseconds
successbooleanWhether subtask succeeded
error_countnumberNumber of errors
retry_countnumberNumber of retries
files_touchedstring[]Files modified
strategy"file-based" | "feature-based" | "risk-based"Strategy used
criteriastring[]Evaluation criteria

Example:

swarm_record_outcome({
  cell_id: "bd-123.2",
  duration_ms: 1200000, // 20 minutes
  success: true,
  error_count: 0,
  retry_count: 0,
  files_touched: ["src/auth/oauth.ts"],
  strategy: "feature-based"
})

swarm_evaluation_prompt

Generate self-evaluation prompt for a completed subtask.

Parameters:

ParameterTypeRequiredDescription
cell_idstringSubtask cell ID
subtask_titlestringSubtask title
files_touchedstring[]Files modified

Example:

swarm_evaluation_prompt({
  cell_id: "bd-123.2",
  subtask_title: "Implement OAuth flow",
  files_touched: ["src/auth/oauth.ts"]
})
// Returns prompt asking agent to self-evaluate

Complete Swarm Workflow

// 1. Initialize swarm
swarm_init({ project_path: "/my/project" })

// 2. Decompose task
const prompt = swarm_decompose({
  task: "Add OAuth authentication",
  max_subtasks: 5,
  query_cass: true
})

// Agent responds with CellTree JSON

// 3. Validate decomposition
const validation = swarm_validate_decomposition({
  response: agentResponse
})

// 4. Create epic + subtasks
hive_create_epic({
  epic_title: "User Authentication",
  subtasks: validation.data.subtasks
})

// 5. Each worker agent:
swarmmail_init({ project_path: "/my/project" })
swarmmail_reserve({
  paths: ["src/auth/**"],
  reason: "bd-123.2: Auth service"
})
// ... do work following TDD (Red → Green → Refactor) ...
swarm_complete({
  project_key: "/my/project",
  agent_name: "BlueLake",
  cell_id: "bd-123.2",
  summary: "OAuth flow implemented",
  files_touched: ["src/auth/oauth.ts"]
})

Next Steps

On this page