---
description: Multi-agent orchestration for complex tasks
argument-hint: [task description]
---

# /swarm - Multi-Agent Task Orchestration

Spawns multiple specialized agents in parallel to complete complex tasks efficiently.

## Arguments

$ARGUMENTS - The task to complete (e.g., "implement user preferences with API, UI, and tests")

## Orchestration Protocol

You are now in **Swarm Mode**. Follow this systematic multi-agent process for task: **$ARGUMENTS**

### Phase 1: Task Analysis & Decomposition

1. **Analyze the task** to understand scope and requirements
2. **Break into subtasks** that can be:
   - Executed independently (parallel)
   - Or must be sequential (dependencies)
3. **Identify agent types** needed for each subtask

Use this decomposition template:

```
SUBTASK 1: [Description]
- Agent type: [Explore/Plan/write-code/code-review/write-tests/etc]
- Dependencies: [None or list subtask numbers]
- Context needed: [Files/patterns to provide]

SUBTASK 2: [Description]
...
```

### Phase 2: Research Swarm (Parallel)

**IMPORTANT**: Launch multiple Explore agents IN PARALLEL in a single message.

Spawn 2-4 Explore agents simultaneously to:

- Find existing patterns and conventions
- Locate relevant files and dependencies
- Identify test patterns to follow
- Check for similar implementations

Example parallel launch:

```
Task(Explore): "Find all files related to [feature area]"
Task(Explore): "Search for existing patterns for [pattern type]"
Task(Explore): "Locate test files and patterns for [area]"
```

### Phase 3: Planning Phase

After research completes, use the **Plan** agent to:

- Synthesize research findings
- Create a detailed implementation spec
- Define file changes needed
- Establish success criteria

The spec becomes the coordination mechanism for implementation agents.

### Phase 4: Implementation Swarm (Parallel when possible)

For independent modules, spawn multiple agents simultaneously:

**Parallel-safe tasks**:

- Different files with no dependencies
- Tests for different modules
- Documentation sections

**Must be sequential**:

- Types before implementation
- API before UI that uses it
- Implementation before tests for same file

Agent type selection guide:
| Task Type | Agent Type |
|-----------|------------|
| Write new code | `write-code` |
| Create tests | `write-tests` |
| Database changes | `database-schema-architect` |
| API endpoints | `backend-api-integration-specialist` |
| Security features | `security-hardening-specialist` |
| Fix errors | `auto-fix` |

### Phase 5: Quality Swarm (Parallel)

Launch quality agents simultaneously:

```
Task(code-review): Review all changes for issues
Task(write-tests): Ensure test coverage
Task(security-audit): Check for vulnerabilities (if applicable)
```

### Phase 6: Verification & Merge

1. **Run all tests** to verify nothing is broken
2. **Build check** to ensure compilation succeeds
3. **Summarize changes** made by all agents
4. **Report any issues** that need manual attention

## Agent Spawning Rules

1. **Always use parallel calls** for independent tasks - put multiple Task tool calls in ONE message
2. **Provide minimal, targeted context** to each agent - only what they need
3. **Include the spec** in implementation agent prompts
4. **Specify expected output format** for each agent

## Prompt Templates for Agents

### Explore Agent Prompt Template

```
Search the codebase to find [specific target].
Return:
- File paths found
- Key patterns identified
- Relevant code snippets
Focus only on [scope limitation].
```

### Write-Code Agent Prompt Template

```
Implement [feature] according to this spec:
[Include spec from Phase 3]

Files to create/modify:
- [path]: [purpose]

Follow existing patterns from:
- [reference file]

Success criteria:
- [criterion 1]
- [criterion 2]
```

### Code Review Agent Prompt Template

```
Review these changes:
[List files changed]

Check for:
- Code quality and patterns
- Potential bugs
- Missing error handling
- Security issues

Report findings and fix any issues found.
```

## Output Format

Provide a summary after completion:

```
## Swarm Execution Summary

### Agents Spawned
- [Agent type]: [Task description] - [Status]

### Files Changed
- [path]: [change description]

### Tests
- [Test status and coverage]

### Issues Found
- [Any problems or warnings]

### Manual Actions Needed
- [If any steps require human intervention]
```

## Begin Orchestration

Now analyze the task "$ARGUMENTS" and begin the swarm execution protocol. Start with Phase 1 task decomposition.
