Module 07: Advanced Patterns
Module 07: Advanced Patterns
Section titled “Module 07: Advanced Patterns”Time: 2-3 hours | Complexity: ⭐⭐⭐ Advanced
Orchestrate multi-agent workflows. Build complex automation that coordinates multiple specialized agents.
What You’ll Learn
Section titled “What You’ll Learn”- Multi-agent architecture patterns
- Orchestration strategies
- Error handling and recovery
- Production-grade automation
- Team workflows
- Real-world scenarios
Multi-Agent Systems
Section titled “Multi-Agent Systems”A multi-agent system is when multiple specialized agents work together on one goal.
Example: Code Release Workflow
Section titled “Example: Code Release Workflow”Instead of one Claude handling everything:
You: "Release version 3.5.0" ↓ ├─→ [Version Agent] Updates VERSION file │ ├─→ [Changelog Agent] Creates release notes │ ├─→ [Test Agent] Runs full test suite │ ├─→ [Security Agent] Security audit │ ├─→ [Docs Agent] Updates documentation │ └─→ [Release Agent] Tags, builds, publishes
Result: Complete, tested, documented releaseEach agent is fast at its specialized task.
Orchestration Patterns
Section titled “Orchestration Patterns”Pattern 1: Sequential (Pipeline)
Section titled “Pattern 1: Sequential (Pipeline)”Agents run one after another. Output of agent N becomes input to agent N+1.
Input ↓[Agent 1: Parse Requirements] → Output: structured requirements ↓[Agent 2: Design Schema] → Output: database schema ↓[Agent 3: Generate Code] → Output: code skeleton ↓[Agent 4: Write Tests] → Output: test suite ↓Final ResultWhen to use: Workflows where each step depends on the previous.
Example:
/agent requirements-parserParse the feature request into specifications
# Later, once we have specifications:/agent database-designerDesign the schema based on these specs
# Once schema is approved:/agent code-generatorGenerate models based on the schemaPattern 2: Parallel (Fork-Join)
Section titled “Pattern 2: Parallel (Fork-Join)”Multiple agents work simultaneously, results combined.
Input ↓ ┌──────┼──────┐ ↓ ↓ ↓ [Unit [Int. [Sec. Tests] Tests] Audit] ↓ ↓ ↓ └──────┼──────┘ ↓ Combine Results ↓ Final ReportWhen to use: Independent checks or tasks.
Example:
Request: "Review my code changes"
Parallel tasks:- Code quality agent reviews- Security agent scans- Test coverage agent checks- Performance agent analyzes
(All run at the same time)
Results combined into one reportPattern 3: Conditional (If-Then)
Section titled “Pattern 3: Conditional (If-Then)”Route to different agents based on conditions.
Input: "Fix the bug" ↓[Analyzer: Is it security?] ├─ YES → [Security Agent] ├─ PERFORMANCE → [Performance Agent] └─ LOGIC → [Logic Agent] ↓ResultExample:
/agent bug-classifierCategorize this bug: security, performance, or logic
# Based on response:# If security:/agent security-patcherFix the security vulnerability
# If performance:/agent perf-optimizerOptimize this codeBuilding a Release Workflow
Section titled “Building a Release Workflow”Scenario
Section titled “Scenario”You want to automate your release process. Right now you:
- Update VERSION file
- Update CHANGELOG
- Run tests
- Run security scan
- Create git tag
- Push to origin
- Deploy to staging
Solution: Multi-Agent Workflow
Section titled “Solution: Multi-Agent Workflow”Step 1: Create agents (each specializes in one task)
.claude/agents/version-manager.md:
---name: version-managerdescription: Manages version files and tagscapabilities: - read_files - write_files - NO: push---
# Version Manager
## PurposeUpdate VERSION files and create git tags
## Tasks- Bump version (patch, minor, major)- Update VERSION file- Update version in package.json, pyproject.toml, etc- Create annotated git tags.claude/agents/changelog-generator.md:
---name: changelog-generatordescription: Generates release notes---
# Changelog Generator
## PurposeCreate readable release notes from commits
## Output Format- Version header- Breaking changes (if any)- New features- Bug fixes- Deprecations.claude/agents/test-validator.md:
---name: test-validatordescription: Runs full test suite---
# Test Validator
## PurposeExecute all tests and verify coverage
## Minimum Requirements- All tests pass- Coverage >80%- No flaky tests.claude/agents/release-publisher.md:
---name: release-publisherdescription: Publishes and deploys---
# Release Publisher
## PurposeTag and push to origin
## Steps1. Create git tag2. Push to origin3. Trigger CI/CD pipeline4. Monitor deploymentStep 2: Create a release workflow command
.claude/commands/release-workflow.md:
Orchestrate a complete release process.
Usage:/release-workflow patch|minor|major
## Process
1. Validate release readiness2. Update version (version-manager agent)3. Generate changelog (changelog-generator agent)4. Run tests (test-validator agent)5. Security scan (security-auditor agent)6. Publish and deploy (release-publisher agent)
## Requirements- All tests passing- No outstanding security issues- Changelog updatedStep 3: Use the workflow
/release-workflow patchClaude then:
- Calls version-manager → updates VERSION
- Calls changelog-generator → creates release notes
- Calls test-validator → verifies tests pass
- Calls security-auditor → scans for vulnerabilities
- Calls release-publisher → creates tag, pushes
- You review, then approve each step
Error Handling in Multi-Agent Systems
Section titled “Error Handling in Multi-Agent Systems”Pattern: Graceful Degradation
Section titled “Pattern: Graceful Degradation”If one agent fails, others continue:
[Test Agent] ❌ FAILED: 3 test failures ↓[Security Agent] ✅ PASSED: No vulnerabilities ↓[Docs Agent] ✅ PASSED: Docs updated ↓[Aggregate Results] ⚠️ Release blocked (tests failed) ✅ Security passed ✅ Docs ready [Instructions to fix tests first]Pattern: Retry on Failure
Section titled “Pattern: Retry on Failure”For transient failures (network, timeouts):
#!/bin/bash# In a hook or skill
max_retries=3retry=0
while [ $retry -lt $max_retries ]; do if /agent test-validator run-tests; then echo "✅ Tests passed" exit 0 fi
retry=$((retry + 1)) if [ $retry -lt $max_retries ]; then echo "⚠️ Retry $retry/$max_retries" sleep 5 fidone
echo "❌ Tests failed after $max_retries attempts"exit 1Pattern: Rollback on Error
Section titled “Pattern: Rollback on Error”If something goes wrong, undo changes:
#!/bin/bash# Rollback helper
ORIGINAL_VERSION=$(git rev-parse HEAD:VERSION)ORIGINAL_TAG=$(git describe --tags --abbrev=0)
cleanup_and_exit() { echo "Rolling back..." git reset --hard HEAD~1 git tag -d "$NEW_TAG" echo "VERSION restored to: $ORIGINAL_VERSION" exit 1}
# Run release stepsif ! /agent version-manager bump-version patch; then cleanup_and_exitfi
if ! /agent test-validator validate-all; then cleanup_and_exitfi
# If we get here, release succeededexit 0Production Patterns
Section titled “Production Patterns”Pattern 1: Staged Rollout
Section titled “Pattern 1: Staged Rollout”Release to different environments progressively:
/release major ↓[Dev] Deploy and test ✅ Verified ↓[Staging] Deploy and test ✅ Verified ↓[Prod] Deploy with monitoring ✅ Monitoring green ↓Release CompletePattern 2: Approval Gates
Section titled “Pattern 2: Approval Gates”Block advancement until reviewed:
# In .claude/hooks/pre-prod-deploy.sh
echo "🚨 PRODUCTION DEPLOY"echo "Changes: $CHANGES"echo "Tests: PASSING"echo "Security: PASSING"echo ""read -p "Type 'I approve' to deploy to production: " approval
if [ "$approval" != "I approve" ]; then echo "❌ Deploy cancelled" exit 1fi
exit 0Pattern 3: Monitoring & Rollback
Section titled “Pattern 3: Monitoring & Rollback”After deployment, verify health:
#!/bin/bash# Post-deploy hook
sleep 10 # Let services start
# Health checksif ! curl -f https://api.example.com/health; then echo "❌ Health check failed" echo "Rolling back..." git revert -n HEAD git commit -m "Rollback: deployment health check failed" exit 1fi
echo "✅ Deployment successful and healthy"exit 0Exercise: Build Your First Multi-Agent Workflow
Section titled “Exercise: Build Your First Multi-Agent Workflow”Scenario
Section titled “Scenario”You have a data science project. Release checklist:
- Update model version
- Run validation tests
- Generate performance report
- Update documentation
- Create release tag
Step 1: Create Agents
Section titled “Step 1: Create Agents”Create .claude/agents/ with:
model-versioner.md- Updates VERSION, model metadatavalidator.md- Runs validation testsreport-generator.md- Creates performance metricsdoc-updater.md- Updates README, API docsrelease-tagger.md- Creates git tag
Step 2: Create the Orchestration Command
Section titled “Step 2: Create the Orchestration Command”.claude/commands/ml-release.md:
Release a new model version.
Usage:/ml-release [major|minor|patch]
## Workflow1. Version agent bumps version2. Validator runs test suite3. Report agent generates metrics4. Doc agent updates documentation5. Tagger creates release tagStep 3: Test It
Section titled “Step 3: Test It”/ml-release patchWatch as agents coordinate the full release.
Best Practices for Advanced Systems
Section titled “Best Practices for Advanced Systems”✅ Design agents to be composable (outputs fit into next agent)
✅ Log everything (helps debug failures)
✅ Test workflows on small changes first
✅ Document the orchestration flow (so others understand)
✅ Build in approval gates for risky operations
✅ Monitor after automation (verify success)
❌ Chain too many agents (>7 becomes hard to debug)
❌ Make agents interdependent (prefer loose coupling)
❌ Skip error handling (things will fail)
❌ Deploy automated releases without testing workflow first
❌ Assume agents will always agree (build conflict resolution)
Validation: You’re Ready If…
Section titled “Validation: You’re Ready If…”✓ You can explain multi-agent orchestration patterns
✓ You’ve created at least 2-3 cooperating agents
✓ You understand error handling strategies
✓ You know how to design workflows with approval gates
✓ You could build a release automation for your project
What’s Next?
Section titled “What’s Next?”You’ve completed the 7-module learning path! You now understand:
- ✅ Installation and setup
- ✅ Core loop and context
- ✅ Memory and configuration
- ✅ Agent specialization
- ✅ Skills and knowledge
- ✅ Hooks and automation
- ✅ Advanced orchestration
Next Steps
Section titled “Next Steps”Option A: Deep Dive into a Domain
- Go deeper into security:
guide/security/ - Go deeper into DevOps:
guide/ops/ - Go deeper into architecture:
guide/core/architecture.md
Option B: Build Something
- Create a multi-agent workflow for your project
- Implement one of the exercises from this path
- Build a plugin bundle and share with team
Option C: Learn from Examples
- Review production agents in
examples/agents/ - Study plugin bundles in
examples/plugins/ - Explore skills in
guide/core/skill-design-patterns.md
Option D: Self-Assess
- Take
/self-assessment comprehensiveto find gaps - Get personalized recommendations
- Create a learning plan for weak areas
Completed Module 07? → You’re a Claude Code power user! 🚀
Explore the full guide at guide/ultimate-guide.md for depth, or teach others what you’ve learned.