AgentSkillsCN

parallel-execution

适用于并行子智能体执行的模式,可最大化效率并减少上下文占用。 适用场景: - 当您需要同时进行多项独立的分析或评审时; - 当任务可以无依赖地并发执行时; - 当代码评审需要多方视角时; - 当您希望从不同角度探索代码库时。 触发短语:并行评审、并发智能体、多智能体、独立分析、同时运行。

SKILL.md
--- frontmatter
name: parallel-execution
description: |
  Patterns for parallel subagent execution to maximize efficiency and reduce context usage.
  Use when:
  - Multiple independent analyses or reviews are needed
  - Tasks can run concurrently without dependencies
  - Code review requires multiple perspectives
  - Exploration of codebase from different angles
  Trigger phrases: parallel review, concurrent agents, multi-agent, independent analysis, run simultaneously
allowed-tools: Read, Glob, Grep, Task
model: sonnet
user-invocable: true
context: fork
agent: general-purpose

Parallel Agent Execution

Techniques for running multiple subagents concurrently to maximize efficiency and minimize main context usage.

Core Principles

From Claude Code Best Practices:

  1. Subagents preserve context - Exploration happens in isolation
  2. Only results return - Main context stays clean
  3. Independence enables parallelism - No dependencies = run together
  4. Aggregation happens in main - Combine results intelligently

When to Use Parallel Execution

Suitable Tasks

Task TypeAgentsWhy Parallel
Code reviewqa, security, styleIndependent perspectives
Codebase explorationMultiple ExploreDifferent search angles
Test coverageunit, integration, e2eIndependent scopes
DocumentationAPI docs, user guide, changelogDifferent audiences
Architecture analysisfrontend, backend, infraDifferent domains

Not Suitable

  • Tasks with dependencies (must be sequential)
  • Tasks that modify same files (conflicts)
  • Tasks requiring shared state
  • Simple single-file operations

Parallel Review Pattern

Multi-Perspective Code Review

code
Run these checks in parallel where possible:

1. qa-engineer agent
   Task: Review test coverage for [files]
   Output: Test gap report with confidence scores

2. security-auditor agent
   Task: Security audit for [files]
   Output: Vulnerability findings (confidence >= 70)

3. code-quality skill (run in main context)
   Task: Lint and style check for [files]
   Output: Quality issues and fixes

4. verification-specialist agent
   Task: Validate findings from other parallel agents
   Output: Verification status (VERIFIED/PARTIAL/UNVERIFIED) with file:line cross-checks

Execution

The orchestrator:

  1. Launches all agents simultaneously
  2. Each runs in isolated context
  3. Results stream back as agents complete
  4. Main context aggregates findings

Result Aggregation

After parallel completion:

markdown
## Combined Review Results

### Critical Issues (must fix)
- [From security-auditor] SQL injection in auth.ts:45 (confidence: 95) [VERIFIED]
- [From qa-engineer] Missing test for payment flow (confidence: 92) [VERIFIED]

### Important Issues (should fix)
- [From code-quality] Unused import in utils.ts [VERIFIED]
- [From qa-engineer] Edge case not covered in validation [PARTIAL]

### Suggestions (consider)
- [From code-quality] Could use early return pattern [UNVERIFIED]

### Verification Summary
- [From verification-specialist] 3 VERIFIED, 1 PARTIAL, 1 UNVERIFIED

Parallel Exploration Pattern

Codebase Discovery

When understanding unfamiliar codebase:

code
Launch exploration agents in parallel:

1. Explore agent
   Task: Find all API endpoints and their handlers

2. Explore agent
   Task: Trace authentication flow from login to session

3. Explore agent
   Task: Map database models and their relationships

Combining Insights

Results create comprehensive picture without consuming main context on exploration:

markdown
## Codebase Understanding

### API Layer (from Agent 1)
- 23 REST endpoints in /api/
- Uses Express with middleware pattern
- Auth middleware on /api/protected/*

### Authentication (from Agent 2)
- JWT-based auth
- Refresh token rotation
- Session stored in Redis

### Data Layer (from Agent 3)
- PostgreSQL with Prisma
- 15 models, User is central
- Soft deletes on most entities

Sequential vs Parallel Decision

Use Sequential When

code
Task A: Create database schema
    ↓
Task B: Generate Prisma client (depends on A)
    ↓
Task C: Write repository layer (depends on B)

Use Parallel When

code
Task A: Review frontend code ──┐
Task B: Review backend code   ──┼── Aggregate results
Task C: Review infrastructure ──┘

Confidence Score Aggregation

When multiple agents report on same issue:

Agent CountConfidence Adjustment
1 agent reportsUse agent's score
2 agents agreeBoost score +10
3+ agents agreeTreat as confirmed
Agents disagreeAverage scores, flag for review

Implementation Checklist

Before launching parallel agents:

  • Tasks are truly independent
  • No shared file modifications
  • Each agent has clear scope
  • Output format is consistent
  • Aggregation criteria defined

Background Agent Pattern

For long-running analyses:

code
Launch in background:
- Full security audit (may take time)
- Complete test suite run
- Dependency vulnerability scan

Continue with:
- Implementation work
- Documentation
- Other reviews

Check background results when ready.

Anti-Patterns

Anti-PatternWhy BadInstead
Parallel with dependenciesRace conditions, wrong orderSequence dependent tasks
Too many parallel agentsOverwhelming, hard to aggregateMax 3-4 for reviews
Same files, parallel writesConflicts, lost changesCoordinate file access
No aggregation planScattered insightsDefine merge strategy

Example: Full Feature Review

markdown
## Launching Parallel Review for: User Dashboard Feature

### Agents to Launch

1. **code-explorer** (background)
   - Trace all data flows in dashboard components
   - Map component hierarchy

2. **qa-engineer** (parallel)
   - Review test coverage
   - Identify missing edge cases

3. **security-auditor** (parallel)
   - Check for XSS vulnerabilities
   - Verify auth on all endpoints

4. **architect** (parallel)
   - Evaluate component structure
   - Check for coupling issues

### Aggregation Strategy

- Critical issues from ANY agent → Must address
- Performance concerns → Prioritize by impact
- Style issues → Bundle into single cleanup PR
- Architecture suggestions → Discuss with team

Rules (L1 - Hard)

Critical for conflict-free parallel execution.

  • ALWAYS verify tasks are independent before parallelizing (prevent race conditions)
  • NEVER run parallel agents that modify same files (causes conflicts)
  • NEVER skip result aggregation (scattered insights are useless)

Defaults (L2 - Soft)

Important for effective parallelism. Override with reasoning when appropriate.

  • Define aggregation strategy before launching
  • Include confidence scores in agent outputs
  • Limit to 3-4 parallel agents for manageability
  • Use consistent output format across agents

Guidelines (L3)

Recommendations for optimal parallel execution.

  • Consider using background agents for long-running analyses
  • Prefer boosting confidence scores when multiple agents agree
  • Consider flagging conflicting findings for human review