Subagent Patterns Quick Reference

This page provides quick access to common subagent patterns. For detailed explanations and advanced techniques, see the Complete Multi-Agent Orchestration Guide.

Common Patterns

1. The 7-Parallel-Task Feature Implementation

This pattern maximizes parallelism for comprehensive feature development:

// Example prompt for feature implementation
const featurePattern = `
IMMEDIATE EXECUTION: Launch parallel Tasks for the shopping cart feature:
 
Task 1 - Component: Create CartComponent.tsx with proper TypeScript interfaces
Task 2 - Styles: Create CartComponent.module.css with responsive design
Task 3 - Tests: Write CartComponent.test.tsx with comprehensive coverage
Task 4 - Types: Define cart.types.ts with all necessary interfaces
Task 5 - Hooks: Create useCart.ts custom hook for cart logic
Task 6 - Integration: Update App.tsx routing and imports
Task 7 - Remaining: Update package.json, README, and configuration
`;

2. Multi-Perspective Analysis Pattern

Deploy subagents with different “personas” for comprehensive analysis:

// Example: Analyzing a codebase for refactoring
const analysisPattern = `
Analyze the authentication system using 4 specialized agents:
 
Task 1 - Security Expert: Review for vulnerabilities and best practices
Task 2 - Performance Engineer: Identify bottlenecks and optimization opportunities  
Task 3 - Maintainability Architect: Assess code quality and structure
Task 4 - User Experience Designer: Evaluate flow and error handling
 
Each agent should provide specific recommendations in their area of expertise.
`;

3. Exploratory Search Pattern

For large-scale codebase exploration:

// Example: Finding all API integrations
const searchPattern = `
Search for all external API integrations using 5 parallel agents:
 
Task 1: Search src/services for API client implementations
Task 2: Search src/hooks for data fetching hooks
Task 3: Search src/components for direct API calls
Task 4: Search config files for API endpoints
Task 5: Search tests for API mocking patterns
 
Report all findings with file paths and line numbers.
`;

4. Test-Driven Development Pattern

Parallel test creation and implementation:

// Example: TDD workflow
const tddPattern = `
Implement user registration feature using TDD approach:
 
Task 1: Write unit tests for UserRegistration component
Task 2: Write integration tests for registration API
Task 3: Write E2E tests for registration flow
Task 4: Implement UserRegistration component to pass tests
Task 5: Implement registration API endpoint
Task 6: Create necessary database migrations
`;

5. Migration Pattern

For systematic codebase migrations:

// Example: JavaScript to TypeScript migration
const migrationPattern = `
Migrate authentication module to TypeScript:
 
Task 1: Convert auth.service.js and add type definitions
Task 2: Convert auth.controller.js with proper request/response types
Task 3: Convert auth.middleware.js with Express types
Task 4: Create auth.types.ts with shared interfaces
Task 5: Update tests to TypeScript
Task 6: Update imports in dependent modules
`;

Advanced Patterns

6. Hierarchical Task Decomposition

For complex systems with nested requirements:

// Example: Building a complete feature module
const hierarchicalPattern = `
Build complete user dashboard module:
 
Phase 1 - Core Components (3 parallel tasks):
- Task 1: Dashboard layout and navigation
- Task 2: User statistics widgets
- Task 3: Activity feed component
 
Phase 2 - Data Layer (3 parallel tasks):
- Task 4: GraphQL queries and mutations
- Task 5: Redux state management
- Task 6: Data caching strategy
 
Phase 3 - Polish (2 parallel tasks):
- Task 7: Loading states and error handling
- Task 8: Responsive design and animations
`;

7. Verification and Validation Pattern

Using subagents for quality assurance:

// Example: Code review automation
const verificationPattern = `
Review the recent pull request changes:
 
Task 1: Check for security vulnerabilities
Task 2: Validate TypeScript types and interfaces
Task 3: Ensure test coverage meets standards
Task 4: Verify accessibility compliance
Task 5: Check for performance regressions
 
Each task should report specific issues with severity levels.
`;

8. Documentation Generation Pattern

Parallel documentation creation:

// Example: Comprehensive documentation
const documentationPattern = `
Generate complete documentation for the API module:
 
Task 1: Extract and document all endpoint signatures
Task 2: Generate TypeScript interface documentation
Task 3: Create usage examples for each endpoint
Task 4: Document error codes and responses
Task 5: Generate OpenAPI/Swagger specification
`;

Pattern Selection Guide

interface PatternSelection {
  taskComplexity: 'simple' | 'medium' | 'complex';
  parallelizability: 'none' | 'partial' | 'high';
  contextRequirement: 'minimal' | 'moderate' | 'extensive';
  recommendedPattern: string;
}
 
const selectPattern = (task: PatternSelection): string => {
  if (task.parallelizability === 'high' && task.complexity === 'complex') {
    return '7-Parallel-Task Pattern';
  }
  if (task.contextRequirement === 'extensive') {
    return 'Multi-Perspective Analysis Pattern';
  }
  // ... additional logic
};

Anti-Patterns to Avoid

1. Sequential Task Anti-Pattern

// ❌ Bad: Sequential tasks forced into parallel execution
const badPattern = `
Task 1: Read the config file
Task 2: Use the config from Task 1 to initialize database
Task 3: Use the database from Task 2 to run queries
`;

2. Overlapping Responsibility Anti-Pattern

// ❌ Bad: Tasks with unclear boundaries
const unclearPattern = `
Task 1: Update the user interface
Task 2: Improve the user experience  // Too much overlap!
Task 3: Enhance the frontend        // Unclear scope!
`;

3. Context Overload Anti-Pattern

// ❌ Bad: Giving subagents too much context
const overloadPattern = `
Task 1: [10 paragraphs of context] ... then do X
Task 2: [Same 10 paragraphs] ... then do Y
`;

Best Practices

  1. Clear Task Boundaries: Each subagent should have a well-defined scope
  2. Independent Operations: Minimize dependencies between tasks
  3. Appropriate Granularity: Balance between too many small tasks and too few large ones
  4. Result Synthesis: Plan how to integrate results from all subagents
  5. Error Handling: Consider what happens if individual tasks fail