Lesson 11Sub-agents
Agent Patterns
Best practices
Parallel Research
Running multiple agents simultaneously to explore different aspects
When to use:
Exploring large codebase, gathering info from different sources
Benefits:
- ✓ Faster than sequential search
- ✓ Isolated contexts
- ✓ No information lost
// Claude launches in parallel: Task(Explore, "Find auth implementation") Task(Explore, "Find API endpoints") Task(Explore, "Find database models")
Agent Chain
Sequential execution: output of one agent → input of another
When to use:
Complex multi-step tasks with dependencies
Benefits:
- ✓ Structured process
- ✓ Each agent specialized
- ✓ Verification at each step
// Sequential chain: 1. Plan agent → creates implementation plan 2. Code agent → implements based on plan 3. Reviewer agent → reviews the code 4. Test agent → writes tests
Code Reviewer
Specialized agent for checking code quality and security
When to use:
After writing code, before commit, PR review
Benefits:
- ✓ Automatic quality check
- ✓ Finds issues before commit
- ✓ Consistent standards
// code-reviewer agent checks: - Security vulnerabilities - Best practices violations - Performance issues - Code style consistency
Debugger
Agent for systematic debugging and root cause analysis
When to use:
Complex bugs, non-obvious error causes
Benefits:
- ✓ Systematic approach
- ✓ Documents process
- ✓ Finds root cause
// Debugger pattern: 1. Reproduce the issue 2. Add logging/breakpoints 3. Trace execution flow 4. Identify root cause 5. Propose fix
Data Analyst
Agent for analyzing data, metrics, logs
When to use:
Performance analysis, finding patterns in logs
Benefits:
- ✓ Handles large volumes
- ✓ Finds non-obvious patterns
- ✓ Structured reports
// Data analysis pattern: 1. Read logs/metrics files 2. Parse and aggregate data 3. Identify anomalies 4. Generate report with visualizations
Combining Patterns
Complex tasks often require combining multiple patterns:
// Complex task: Refactor authentication system
// Phase 1: Research (parallel)
const [authFiles, securityReqs, tests] = await Promise.all([
Task(Explore, "Find all authentication related files"),
Task(Explore, "Find security requirements in docs"),
Task(Explore, "Find existing auth tests")
]);
// Phase 2: Plan
const plan = await Task(Plan, `
Create refactoring plan based on:
- Files: ${authFiles}
- Requirements: ${securityReqs}
- Tests: ${tests}
`);
// Phase 3: Implement (with review)
for (const step of plan.steps) {
await implementStep(step);
await Task(code-reviewer, "Review the changes");
}
// Phase 4: Verify
await Task(Bash, "Run all auth tests");Parallel researchPlanningImplementation + ReviewVerification
Anti-patterns
✗ BadOne agent for everything
✓ GoodSpecialized agents
✗ BadSequential search in large codebase
✓ GoodParallel Explore agents
✗ BadImplementation without plan
✓ GoodPlan → Implement → Review
When to Use Which Pattern
- Parallel Research — when you need to gather information quickly
- Chain — when steps depend on each other
- Reviewer — after any significant code changes
- Combination — for complex tasks with multiple stages
This lesson is part of a structured LLM course.
My Learning Path