Parallel Agent Coordination Prompt
Purpose: Coordinate multiple agents running in parallel to maximize efficiency and avoid conflicts.
Overview
When tasks can be decomposed into independent subtasks, running agents in parallel dramatically reduces total execution time. This prompt helps identify parallelizable work and coordinate agents effectively.
Parallel Execution Rules
When to Use Parallel Agents
✅ Good candidates for parallel execution:
- Independent code reviews (different files/modules)
- Multiple test suites (unit, integration, e2e)
- Multi-repo operations (deployments, updates)
- Data processing (different data sets)
- Documentation generation (different sections)
- Multiple bug investigations (unrelated issues)
- Feature implementations in different modules
❌ Bad candidates (must be sequential):
- Dependent operations (A must complete before B)
- Shared resource modifications (database schema changes)
- Operations requiring previous results as input
- Mutex-protected resources
Dependency Analysis
Before parallelizing, check:
For each subtask:
1. **Reads from**: [files/resources/data]
2. **Writes to**: [files/resources/data]
3. **Depends on**: [other subtasks]
4. **Blocks**: [other subtasks]
Conflict detection:
- Do any tasks write to the same file? → CONFLICT
- Do any tasks depend on each other's output? → SEQUENTIAL
- Are resources independent? → PARALLEL OK
Parallel Agent Patterns
Pattern 1: Fork-Join (Map-Reduce)
Use case: Process multiple independent items, aggregate results
# Example: Review multiple PRs
Parallel phase (Fork):
- Agent 1: Review PR #42
- Agent 2: Review PR #43
- Agent 3: Review PR #44
Sequential phase (Join):
- Aggregate all reviews
- Generate summary report
- Post consolidated feedback
Pattern 2: Pipeline (Producer-Consumer)
Use case: Chain of processing stages with parallel workers per stage
# Example: Multi-stage test pipeline
Stage 1 (Parallel):
- Agent 1: Lint code
- Agent 2: Type check
- Agent 3: Security scan
Stage 2 (Parallel, after Stage 1):
- Agent 1: Unit tests
- Agent 2: Integration tests
- Agent 3: E2E tests
Stage 3 (Sequential, after Stage 2):
- Agent 1: Generate coverage report
Pattern 3: Broadcast (All-at-Once)
Use case: Same operation across multiple targets
# Example: Update all repositories
Parallel execution:
- Agent 1: Update repo-1 dependencies
- Agent 2: Update repo-2 dependencies
- Agent 3: Update repo-3 dependencies
- Agent 4: Update repo-4 dependencies
Each agent:
1. Run npm audit
2. Apply safe updates
3. Run tests
4. Create PR if tests pass
Pattern 4: Race Condition (First-Win)
Use case: Multiple approaches, use first successful result
# Example: Bug investigation
Parallel execution:
- Agent 1: Search error logs for patterns
- Agent 2: Review recent code changes
- Agent 3: Check similar known issues
First agent with findings:
- Share results
- Other agents terminate
Coordination Template
# Parallel Agent Coordination Plan
## Objective
[High-level goal]
## Task Decomposition
### Subtask 1: [NAME]
- **Agent**: [agent-name]
- **Reads**: [resources]
- **Writes**: [resources]
- **Estimated time**: [duration]
- **Dependencies**: [none/list]
- **Can run in parallel with**: [subtask IDs]
### Subtask 2: [NAME]
- **Agent**: [agent-name]
- **Reads**: [resources]
- **Writes**: [resources]
- **Estimated time**: [duration]
- **Dependencies**: [none/list]
- **Can run in parallel with**: [subtask IDs]
[... more subtasks ...]
## Execution Plan
### Phase 1: Parallel Execution
- Start agents: [list]
- Wait for: [all/any/specific agents]
### Phase 2: Sequential (if needed)
- Agent: [agent-name]
- Input: [results from Phase 1]
### Phase 3: Aggregation
- Collect results from all agents
- Generate unified output
## Conflict Resolution
- **File conflicts**: [strategy]
- **Resource contention**: [strategy]
- **Failure handling**: [continue/abort/retry]
## Success Criteria
- [ ] All parallel agents complete successfully
- [ ] Results aggregated correctly
- [ ] No resource conflicts
- [ ] Total time < sequential execution
Example: Feature Implementation Across Modules
# Parallel Agent Coordination Plan
## Objective
Implement "user preferences" feature across frontend, backend, and database
## Task Decomposition
### Subtask 1: Database Schema
- **Agent**: database
- **Reads**: existing schema
- **Writes**: migrations/001_add_user_preferences.sql
- **Estimated time**: 15 min
- **Dependencies**: none
- **Can run in parallel with**: Subtask 2, 3
### Subtask 2: Backend API
- **Agent**: implementation
- **Reads**: existing API code
- **Writes**: src/api/preferences.ts, tests/api/preferences.test.ts
- **Estimated time**: 30 min
- **Dependencies**: none (can mock DB)
- **Can run in parallel with**: Subtask 1, 3
### Subtask 3: Frontend UI
- **Agent**: implementation
- **Reads**: existing UI components
- **Writes**: src/components/PreferencesPanel.tsx, src/components/PreferencesPanel.test.tsx
- **Estimated time**: 45 min
- **Dependencies**: none (can mock API)
- **Can run in parallel with**: Subtask 1, 2
## Execution Plan
### Phase 1: Parallel Implementation (0-45 min)
Launch in single message with multiple Task tool calls:
- Task(database, "Create user_preferences table with columns: user_id, theme, notifications, language...")
- Task(implementation, "Create preferences API endpoints: GET/PUT /api/user/preferences...")
- Task(implementation, "Create PreferencesPanel component with theme selector, notification toggles...")
Wait for all to complete.
### Phase 2: Integration (45-60 min)
Sequential (needs results from Phase 1):
- Review all implementations
- Wire up frontend → API → database
- Add integration tests
- Verify end-to-end flow
### Phase 3: Testing (60-75 min)
Parallel execution:
- Task(browser-testing, "Test preferences UI with visual validation")
- Task(implementation, "Run API integration tests")
- Task(database, "Verify migration and rollback")
## Conflict Resolution
- **File conflicts**: None expected (different directories)
- **Resource contention**: None (isolated modules)
- **Failure handling**:
- If database fails: Abort (others need schema)
- If API fails: Continue (can mock for frontend)
- If frontend fails: Continue (API still valuable)
## Success Criteria
- [x] All three agents complete successfully
- [x] Integration tests pass
- [x] No file conflicts during merge
- [x] Total time ~75 min (vs ~90 min sequential)
## Actual Execution
Invoke parallel agents:
In conductor agent:
"I need to implement user preferences feature across frontend, backend, and database in parallel.
Task 1: Create database schema for user_preferences
Task 2: Implement backend API for preferences
Task 3: Implement frontend PreferencesPanel UI
These tasks are independent and can run in parallel. Please coordinate their execution."
Or use Task tool directly:
# Single message with multiple Task calls
Task(database, "Create user_preferences table...")
Task(implementation, "Create preferences API endpoints...")
Task(implementation, "Create PreferencesPanel component...")
Anti-Patterns
❌ Don't: Sequential Execution of Independent Tasks
# BAD - sequential (90 min total)
1. Complete database schema (15 min)
2. Wait...
3. Complete backend API (30 min)
4. Wait...
5. Complete frontend UI (45 min)
✅ Do: Parallel Execution
# GOOD - parallel (45 min total)
1. Start all three agents simultaneously
2. Wait for all to complete (45 min = max of 15, 30, 45)
3. Integrate results
❌ Don't: Parallelize Dependent Operations
# BAD - will fail
Agent 1: Run database migration
Agent 2: Seed data (needs migration first)
# Agent 2 will fail - migration not complete yet!
✅ Do: Respect Dependencies
# GOOD - sequential
1. Agent 1: Run database migration
2. Wait for completion
3. Agent 2: Seed data
Monitoring Parallel Agents
While agents run in background:
# Check status
- Agent 1: database (status: in_progress)
- Agent 2: implementation/backend (status: in_progress)
- Agent 3: implementation/frontend (status: in_progress)
# Use TodoWrite to track:
"Creating database schema" - in_progress
"Implementing backend API" - in_progress
"Implementing frontend UI" - in_progress
# When complete, mark done:
"Creating database schema" - completed
"Implementing backend API" - completed
"Implementing frontend UI" - completed
Time Savings Calculation
Sequential time = Sum of all task times
Parallel time = Max of all task times (in same phase)
Example:
- Task A: 15 min
- Task B: 30 min
- Task C: 45 min
Sequential: 15 + 30 + 45 = 90 min
Parallel: max(15, 30, 45) = 45 min
Savings: 50% (45 min saved)
Best Practices
- Start with dependency analysis - Don't assume tasks are independent
- Use TodoWrite - Track all parallel tasks for visibility
- Single message invocation - Launch all parallel agents in one message
- Plan aggregation - Know how you'll combine results
- Handle failures gracefully - One agent failing shouldn't break others
- Monitor resource usage - Too many parallel agents can overwhelm system
- Document coordination - Make parallelization explicit in code/PRs
Limits
Practical limits:
- Max ~5 agents in parallel (system resource consideration)
- Each agent should take >2 min (overhead of parallelization)
- Tasks should be truly independent (no hidden dependencies)
Integration with Conductor
# Conductor agent should:
1. Analyze issue/task
2. Break into subtasks
3. Check dependencies
4. Identify parallelizable work
5. Use this prompt to coordinate
6. Launch agents in parallel
7. Aggregate results
8. Proceed to next phase
Templates for Common Scenarios
Multi-Repo Operation
Parallel agents for repos: [repo1, repo2, repo3, ...]
Operation: [update-deps/deploy/test/security-scan]
Launch with:
Task(agent, "operate on repo1")
Task(agent, "operate on repo2")
Task(agent, "operate on repo3")
Code Review Split
Parallel review by file type:
Task(code-reviewer, "review backend changes")
Task(code-reviewer, "review frontend changes")
Task(code-reviewer, "review database changes")
Test Suite Parallel Execution
Parallel test suites:
Task(implementation, "run unit tests")
Task(implementation, "run integration tests")
Task(browser-testing, "run e2e tests")
Notes
- This prompt is reusable across all repos and workflows
- Always prefer parallel when possible (faster feedback)
- Use TodoWrite to visualize parallel work
- Monitor for hidden dependencies
- Aggregate results thoughtfully