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:
| Parameter | Type | Required | Description |
|---|---|---|---|
project_path | string | ✅ | Absolute path to project |
agent_name | string | ❌ | Custom agent name (auto-generated if omitted) |
task_description | string | ❌ | Current 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:
| Parameter | Type | Required | Description |
|---|---|---|---|
to | string[] | ✅ | Recipient agent names |
subject | string | ✅ | Message subject |
body | string | ✅ | Message body |
thread_id | string | ❌ | Thread ID (use cell ID for swarm work) |
importance | "low" | "normal" | "high" | "urgent" | ❌ | Message priority (default: "normal") |
ack_required | boolean | ❌ | Require 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:
| Parameter | Type | Required | Description |
|---|---|---|---|
limit | number | ❌ | Max messages (capped at 5) |
urgent_only | boolean | ❌ | Only 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:
| Parameter | Type | Required | Description |
|---|---|---|---|
message_id | number | ✅ | Message 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:
| Parameter | Type | Required | Description |
|---|---|---|---|
paths | string[] | ✅ | File paths or patterns |
reason | string | ❌ | Reservation reason (include cell ID) |
exclusive | boolean | ❌ | Exclusive lock (default: true) |
ttl_seconds | number | ❌ | Lock 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:
| Parameter | Type | Required | Description |
|---|---|---|---|
paths | string[] | ❌ | Specific paths to release |
reservation_ids | number[] | ❌ | 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:
| Parameter | Type | Required | Description |
|---|---|---|---|
project_path | string | ❌ | Project 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:
| Parameter | Type | Required | Description |
|---|---|---|---|
task | string | ✅ | Task description |
codebase_context | string | ❌ | Optional 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:
| Parameter | Type | Required | Description |
|---|---|---|---|
task | string | ✅ | Task description |
max_subtasks | number | ❌ | Max subtasks (default: 5) |
query_cass | boolean | ❌ | Query CASS history (default: true) |
context | string | ❌ | Additional context |
cass_limit | number | ❌ | CASS result limit (default: 3) |
Example:
swarm_decompose({
task: "Add OAuth authentication",
max_subtasks: 5,
query_cass: true
})
// Returns prompt string with CASS contextswarm_validate_decomposition
Validate decomposition response against CellTreeSchema. Detects file conflicts and instruction conflicts.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
response | string | ✅ | Agent'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:
| Parameter | Type | Required | Description |
|---|---|---|---|
task | string | ✅ | Task description |
strategy | "file-based" | "feature-based" | "risk-based" | "auto" | ❌ | Strategy (default: "auto") |
max_subtasks | number | ❌ | Max subtasks (default: 5) |
context | string | ❌ | Additional context |
query_cass | boolean | ❌ | Query CASS (default: true) |
cass_limit | number | ❌ | CASS 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:
| Parameter | Type | Required | Description |
|---|---|---|---|
agent_name | string | ✅ | Worker agent name |
cell_id | string | ✅ | Subtask cell ID |
epic_id | string | ✅ | Epic cell ID |
subtask_title | string | ✅ | Subtask title |
subtask_description | string | ❌ | Subtask description |
files | string[] | ✅ | Files to modify |
shared_context | string | ❌ | Shared 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 promptswarm_spawn_subtask
Prepare subtask for spawning with Task tool.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
cell_id | string | ✅ | Subtask cell ID |
epic_id | string | ✅ | Epic cell ID |
subtask_title | string | ✅ | Subtask title |
subtask_description | string | ❌ | Subtask description |
files | string[] | ✅ | Files to modify |
shared_context | string | ❌ | Shared 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:
| Parameter | Type | Required | Description |
|---|---|---|---|
epic_id | string | ✅ | Epic cell ID |
project_key | string | ✅ | Project 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:
| Parameter | Type | Required | Description |
|---|---|---|---|
project_key | string | ✅ | Project path |
agent_name | string | ✅ | Worker agent name |
cell_id | string | ✅ | Subtask cell ID |
status | "in_progress" | "blocked" | "completed" | "failed" | ✅ | Status |
message | string | ❌ | Status message |
progress_percent | number | ❌ | Progress 0-100 |
files_touched | string[] | ❌ | 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:
| Parameter | Type | Required | Description |
|---|---|---|---|
project_key | string | ✅ | Project path (finds cells via minimatch) |
agent_name | string | ✅ | Worker agent name |
cell_id | string | ✅ | Subtask cell ID |
summary | string | ✅ | Completion summary |
files_touched | string[] | ❌ | Files modified |
evaluation | string | ❌ | Self-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 signalsCritical: 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:
- Finds cells - Uses path-based
project_keywith minimatch pattern matching - Releases reservations - Auto-releases all file locks held by the worker
- Records learning signals - Tracks duration, errors, retries for pattern learning
- 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:
- RED - Write a failing test first (if it passes, the test is wrong)
- GREEN - Minimum code to make it pass (hardcode if needed)
- 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:
| Parameter | Type | Required | Description |
|---|---|---|---|
cell_id | string | ✅ | Subtask cell ID |
duration_ms | number | ✅ | Duration in milliseconds |
success | boolean | ✅ | Whether subtask succeeded |
error_count | number | ❌ | Number of errors |
retry_count | number | ❌ | Number of retries |
files_touched | string[] | ❌ | Files modified |
strategy | "file-based" | "feature-based" | "risk-based" | ❌ | Strategy used |
criteria | string[] | ❌ | 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:
| Parameter | Type | Required | Description |
|---|---|---|---|
cell_id | string | ✅ | Subtask cell ID |
subtask_title | string | ✅ | Subtask title |
files_touched | string[] | ✅ | 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-evaluateComplete 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
- Hive Tools - Git-backed issue tracking
- Skills Tools - Knowledge injection
- Swarm Mail Architecture - Event sourcing internals