Module 07: Advanced Patterns
Last updated:
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.
Before choosing a team pattern, separate the layers: the model produces tokens, a runtime harness owns a session’s model-and-tool loop, the repository harness supplies instructions and verification, and an orchestrator coordinates sessions. Agent Harness Engineering explains that model; the Agent Harness Map compares loop-owning runtimes and keeps the broader directory separate. Use Agent Tools: Beyond Claude Code for frameworks and control planes, the glossary for terms, Agent Evaluation to score the result, Session Observability to inspect execution, and Security Hardening before running work unattended.
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.