---
name: multi-agent
description: Orchestrate multiple specialized AI agents for complex tasks
---

# Multi-Agent Orchestration Skill

## Description

This skill enables multi-agent collaboration where specialized AI agents work together on complex tasks. Each agent has a specific role and expertise, coordinated by an orchestrator to achieve better results than a single agent approach.

## When to Use

- Complex feature implementation requiring design, code, tests, and documentation
- Large refactoring tasks needing careful planning and review
- Bug fixing requiring debugging, fixing, testing, and review
- Tasks that benefit from specialized expertise at each stage

## Commands

```
/multi-agent <task>                    # Run full workflow
/multi-agent --type feature <task>     # Specify workflow type
/multi-agent --agents arch,impl <task> # Specify agents
/multi-agent --plan <task>             # Show plan without executing
```

## Agent Roles

| Role | Description | Expertise |
|------|-------------|-----------|
| **Architect** | System design and architecture | Patterns, APIs, structure |
| **Implementer** | Code writing and implementation | Clean code, efficiency |
| **Reviewer** | Code review and quality check | Bugs, security, standards |
| **Tester** | Test writing and execution | Unit tests, coverage |
| **Documenter** | Documentation creation | READMEs, API docs, comments |
| **Debugger** | Bug analysis and fixing | Root cause, debugging |
| **Researcher** | Solution research | Libraries, best practices |
| **Planner** | Task decomposition | Planning, coordination |

## Workflow Types

### Feature Implementation
```
Architect → Implementer → Tester → Reviewer → Documenter
```

1. **Architect**: Designs the feature architecture
2. **Implementer**: Writes the code
3. **Tester**: Creates tests
4. **Reviewer**: Reviews code quality
5. **Documenter**: Updates documentation

### Bug Fix
```
Debugger → Implementer → Tester → Reviewer
```

1. **Debugger**: Analyzes and locates the bug
2. **Implementer**: Implements the fix
3. **Tester**: Writes regression tests
4. **Reviewer**: Verifies the fix

### Refactoring
```
Architect → Implementer → Reviewer
```

1. **Architect**: Plans the refactoring approach
2. **Implementer**: Performs the refactoring
3. **Reviewer**: Ensures quality maintained

## How to Use

### Step 1: Describe Your Task

Provide a clear description of what you want to accomplish:

```
/multi-agent Implement user authentication with OAuth2
```

### Step 2: Review the Plan

The orchestrator will show the execution plan:
- Which agents will be involved
- Task breakdown
- Dependencies and order

### Step 3: Agents Execute

Each agent works on their part:
- Architect designs the solution
- Implementer writes code
- Tester creates tests
- etc.

### Step 4: Review Results

Get combined output from all agents with:
- Design decisions
- Implementation details
- Test results
- Review findings
- Documentation

## Agent Communication

Agents share context through:
- **Shared Context**: Key information passed between agents
- **Artifacts**: Files and outputs produced
- **Dependencies**: Results from previous agents

Example flow:
```
Architect outputs: "Use JWT tokens, store in HttpOnly cookies"
    ↓
Implementer sees context and implements accordingly
    ↓
Tester creates tests for JWT handling
```

## Best Practices

1. **Clear Task Descriptions**: Provide detailed requirements
2. **Right Workflow**: Choose appropriate workflow type
3. **Review Intermediate Results**: Check agent outputs
4. **Iterate if Needed**: Run additional passes if required

## Examples

### Example 1: New Feature

**User Request:**
```
/multi-agent Implement a caching layer for API responses
```

**Execution:**
1. Architect: Designs cache strategy (Redis, TTL, invalidation)
2. Implementer: Writes cache middleware
3. Tester: Creates cache hit/miss tests
4. Reviewer: Checks for race conditions
5. Documenter: Documents cache configuration

### Example 2: Bug Fix

**User Request:**
```
/multi-agent --type bugfix Fix memory leak in image processing
```

**Execution:**
1. Debugger: Profiles and identifies leak source
2. Implementer: Fixes resource cleanup
3. Tester: Adds memory leak test
4. Reviewer: Verifies fix completeness

### Example 3: Custom Agents

**User Request:**
```
/multi-agent --agents researcher,architect Research best practices for API rate limiting and design implementation
```

**Execution:**
1. Researcher: Investigates rate limiting approaches
2. Architect: Designs based on research findings

## Parallel Execution

When possible, independent tasks run in parallel:

```
         ┌─ Unit Tests
         │
Task → ──┼─ Integration Tests  → Review
         │
         └─ Documentation
```

## Output Format

Final output combines all agent results:

```markdown
## Architect Output
[Design decisions and architecture]

## Implementer Output
[Implementation details and code changes]

## Tester Output
[Test results and coverage]

## Reviewer Output
[Review findings and recommendations]

## Documenter Output
[Documentation updates]
```

## Notes

- Agents work sequentially by default (respecting dependencies)
- Each agent has access to previous agents' output
- Failed agent stops the workflow
- Results can be used for iterative improvement
- Complex tasks may need multiple runs
