parallel-execution
npx skills add https://github.com/d-oit/do-novelist-ai --skill parallel-execution
Agent 安装分布
Skill 文档
Parallel Execution
Execute multiple independent tasks simultaneously to maximize throughput and minimize total execution time.
When to Use
- Multiple independent tasks (no dependencies)
- Tasks benefit from concurrent execution
- Maximizing throughput is priority
- Available agents for parallel work
- Results can be aggregated after completion
Core Concepts
Independence
Tasks are independent when:
- â No data dependencies (one doesn’t need other’s output)
- â No resource conflicts (different files, databases)
- â No ordering requirements (either can complete first)
- â Failures are isolated (one failing doesn’t block others)
Example – Independent:
â Task A: Review code quality (code-reviewer)
â Task B: Run test suite (test-runner)
â Can run in parallel
Example – NOT Independent:
â Task A: Implement feature (feature-implementer)
â Task B: Test feature (test-runner)
â B depends on A's output, must run sequentially
Concurrency
Critical: Use single message with multiple Task tool calls
Correct:
Send one message containing:
- Task tool call #1 â Agent A
- Task tool call #2 â Agent B
- Task tool call #3 â Agent C
All three agents start simultaneously.
Incorrect:
Message 1: Task tool â code-reviewer
[wait]
Message 2: Task tool â test-runner
[wait]
This is sequential, NOT parallel!
Synchronization
Collection Point:
- Wait for all parallel agents to complete
- Collect results from each agent
- Validate each result independently
- Aggregate results into final output
Parallel Execution Process
Step 1: Identify Independent Tasks
Independence Checklist:
- No data dependencies
- No shared writes (read-only or different targets)
- No execution order requirements
- Failures don’t cascade
- Results can be validated independently
Step 2: Agent Assignment
Match Tasks to Agents:
Task 1: Review code quality â code-reviewer
Task 2: Run test suite â test-runner
Task 3: Run benchmarks â test-runner
Agent Availability Check:
- Ensure sufficient agents available
- Check for specialization overlap
- Consider workload balance
Step 3: Launch Parallel Execution
Single message with multiple Task tool calls:
<Task tool> â code-reviewer (review task)
<Task tool> â test-runner (test task)
<Task tool> â test-runner (benchmark task)
All agents start simultaneously.
Step 4: Monitor Execution
Track Progress:
Agent 1 (code-reviewer): In Progress
Task: Code quality review
Agent 2 (test-runner): Completed â
Task: Test suite
Result: 45/45 tests passed
Agent 3 (test-runner): In Progress
Task: Benchmarks
Step 5: Collect & Validate Results
As Each Agent Completes:
- Collect output
- Validate against success criteria
- Check for errors
- Mark as complete or failed
Step 6: Aggregate Results
## Parallel Execution Results
### Completed Tasks:
1. â Code quality review (code-reviewer)
- Result: 3 minor issues found
2. â Test suite (test-runner)
- Result: All tests passing (45/45)
3. â Performance benchmarks (test-runner)
- Result: All benchmarks acceptable
### Overall Status: â Success (with minor issues)
Execution Patterns
Pattern 1: Homogeneous Parallel
All agents same type, different inputs:
Use Case: Test multiple modules
ââ test-runner: Test memory-core
ââ test-runner: Test memory-storage-turso
ââ test-runner: Test memory-storage-redb
Single message, 3 Task tool calls
Pattern 2: Heterogeneous Parallel
Different agent types, related task:
Use Case: Comprehensive code check
ââ code-reviewer: Quality analysis
ââ test-runner: Test execution
ââ debugger: Performance profiling
Single message, 3 Task tool calls
Pattern 3: Parallel with Convergence
Parallel execution â Single synthesis:
Phase 1: Parallel Investigation
ââ debugger: Profile performance
ââ code-reviewer: Analyze efficiency
ââ test-runner: Run benchmarks
[All complete]
Phase 2: Synthesis
ââ Combine findings, identify root cause
Synchronization Strategies
Wait for All (AND)
Most Common:
- Wait for ALL agents to complete
- Proceed only when all finished
- Useful when all results needed
Wait for Any (OR)
Early Termination:
- Proceed when ANY agent completes successfully
- Cancel or continue others
- Useful for redundant approaches
Wait for Threshold
Partial Completion:
- Proceed when N out of M agents complete
- Useful for resilience
- Handle missing results gracefully
Resource Management
Available Agents
- code-reviewer (1 instance)
- test-runner (1 instance)
- feature-implementer (1 instance)
- refactorer (1 instance)
- debugger (1 instance)
Parallelization Limit: Maximum 5 agents simultaneously (one of each type)
Workload Balancing
Distribute Evenly:
Tasks: [T1, T2, T3, T4, T5, T6]
Agents: [A, B, C]
Distribution:
- Agent A: T1, T4 (2 tasks)
- Agent B: T2, T5 (2 tasks)
- Agent C: T3, T6 (2 tasks)
Error Handling
Independent Failures
Isolation:
- One agent failing doesn’t stop others
- Continue collecting successful results
- Report failed tasks separately
Parallel Execution:
ââ Agent A: â Success
ââ Agent B: â Failed (error in code)
ââ Agent C: â Success
Result:
- Collect: Results from A and C
- Report: B failed with error
- Decision: Retry B or proceed without
Partial Success Handling
Strategies:
- Fail Fast: If any fails, stop and report
- Best Effort: Collect all successful results
- Retry Failed: Let successful complete, retry failures
Performance Optimization
Speedup Calculation
Sequential time = T1 + T2 + T3 + ... + Tn
Parallel time = max(T1, T2, T3, ..., Tn)
Speedup = Sequential time / Parallel time
Example:
Tasks:
- Task A: 10 minutes
- Task B: 15 minutes
- Task C: 8 minutes
Sequential: 10 + 15 + 8 = 33 minutes
Parallel: max(10, 15, 8) = 15 minutes
Speedup: 33 / 15 = 2.2x faster
Optimal Parallelization
Identify Bottlenecks:
- Find longest-running task
- Can it be decomposed further?
- Can it be optimized?
- Start slow tasks first
Best Practices
DO:
â Verify independence before parallelizing â Use single message with multiple Task tool calls â Balance workload across agents â Set appropriate timeouts for each task â Handle failures gracefully (isolation) â Validate each result independently â Aggregate comprehensively at the end
DON’T:
â Parallelize dependent tasks â Send sequential messages thinking they’re parallel â Overload single agent while others idle â Skip validation because “it’s parallel” â Assume all will succeed â Ignore agent failures
Examples
Example 1: Simple Parallel Review
Task: "Check code quality and run tests"
Analysis: Independent tasks, different agents
Plan:
ââ code-reviewer: Review code quality
ââ test-runner: Run test suite
Execution: [Single message with 2 Task tool calls]
Results:
- code-reviewer: 2 issues found â
- test-runner: 45/45 tests pass â
Speedup: 2x
Example 2: Multi-Module Testing
Task: "Test all crates in workspace"
Analysis: 3 independent crates, same agent type
Plan:
ââ test-runner: Test memory-core
ââ test-runner: Test memory-storage-turso
ââ test-runner: Test memory-storage-redb
Execution: [Single message with 3 Task tool calls]
Results:
- memory-core: 25/25 pass â
- memory-storage-turso: 15/15 pass â
- memory-storage-redb: 10/10 pass â
Speedup: 3x
Example 3: Comprehensive Quality Check
Task: "Pre-release quality validation"
Analysis: 4 independent checks, maximum parallelization
Plan:
ââ code-reviewer: Code quality (fmt, clippy)
ââ test-runner: Test suite execution
ââ test-runner: Performance benchmarks
ââ debugger: Memory leak detection
Execution: [Single message with 4 Task tool calls]
Results: All checks pass â
Speedup: 4x
Integration
Parallel execution is one coordination strategy used by the agent-coordination skill:
Coordination Strategy Selection:
ââ Independent tasks â Use parallel-execution (this skill)
ââ Dependent tasks â Use sequential coordination
ââ Complex mix â Use hybrid coordination
ââ Multiple perspectives â Use swarm (with parallel)
Summary
Parallel execution maximizes efficiency for independent tasks by:
- Concurrent agent execution (single message, multiple tools)
- Independent task validation (no cross-dependencies)
- Synchronized result collection (wait for completion)
- Comprehensive aggregation (synthesize final output)
When done correctly, parallel execution provides significant speedup while maintaining quality and reliability.