Mastering AI Development: Multi-Agent Patterns and Production Quality
In Article 1, we identified six problems that make developers 19% slower with AI assistants.
In Article 2, we built the foundation:
- CLAUDE.md for clear direction
- Test-Driven Development for built-in verification
- Phase-based development for a manageable scope
- Session management for context preservation
If you’ve been implementing these patterns for a couple of weeks, you’ve probably noticed a shift. The AI feels more reliable. Your code quality is improving. You’re catching bugs earlier.
Good.
Now let’s take it further.
In this article, I’m showing you the advanced patterns that took my projects from good to exceptional. From 80% test coverage to 90%+. From zero security issues to comprehensive security reviews. From solo development to scalable team processes.
These patterns are what separate “using AI” from “mastering AI-assisted development.”
Pattern 4: Multi-Agent Orchestration
Here’s a question: Would you hire one person to do architecture, testing, implementation, security reviews, and DevOps?
No. You’d have specialists.
Same principle with AI.
The Agent Philosophy
Different problems need different approaches:
- Architecture decisions need broad thinking about trade-offs
- Test design needs paranoia about edge cases
- Implementation needs to focus on passing specific tests
- Security review needs an adversarial mindset
- Code review needs objectivity about what was built
No single agent can wear all these hats effectively. So we use multiple agents, each specialized for specific tasks.
Defining Your Agents
Add this to your CLAUDE.md:
## Available Agents
### Primary Agents
1. **Architect Agent** (python-expert)
**Role:** System design and architecture decisions
**Invoke for:**
- Major design decisions (database choice, patterns, structure)
- Module architecture
- Evaluating trade-offs
**Use when:** Designing new modules or making architectural choices
**Context to provide:** PRD, existing architecture, constraints
2. **Test Designer Agent** (python-expert / test-orchestrator)
**Role:** Test strategy and comprehensive test case design
**Invoke for:**
- Test planning for new features
- Edge case identification
- Test data generation
- Integration test strategies
**Use when:** Starting a new feature or complex component
**Context to provide:** Feature requirements, implementation details
3. **Implementation Agent** (python-expert)
**Role:** Code implementation following TDD
**Invoke for:** Writing production code to pass tests
**Use when:** You have failing tests that define success
**Context to provide:** Failing tests, design specifications, type hints
4. **Security Analyst** (Security Expert)
**Role:** Security reviews and vulnerability assessment
**Invoke for:**
- Authentication/authorization implementation
- Credential handling
- Encryption decisions
- Data validation
**Frequency:** EVERY auth implementation, before phase completion
**Context to provide:** Security requirements, compliance needs
5. **Code Reviewer** (python-expert)
**Role:** Objective review of completed work
**Invoke for:**
- End-of-phase reviews
- Refactoring suggestions
- Performance optimization
**Use when:** Feature is complete and tested
**Context to provide:** The code, tests, and original requirements
### Specialist Sub-Agents
1. **AI Engineering Expert** (ai-engineering-expert)
**Role:** MCP protocol, LLM integration
**Invoke for:** MCP tool design, protocol compliance
**Use when:** Building AI-related features
2. **FastAPI Expert** (fastapi-expert)
**Role:** API design and implementation
**Invoke for:** REST API endpoints, request validation
**Use when:** Building HTTP interfaces
3. **Docker Expert** (docker-expert)
**Role:** Containerization and deployment
**Invoke for:** Dockerfile creation, multi-stage builds
**Use when:** Containerizing the application
4. **GitLab CI/CD Expert** (gitlab-cicd-expert)
**Role:** Pipeline design and optimization
**Invoke for:** CI/CD pipeline creation, test automation
**Use when:** Setting up automated testing and deployment
Orchestration Patterns
Here are proven workflows for invoking agents:
Pattern 1: TDD Development Cycle
User Request →
Test Designer Agent (design comprehensive tests) →
Implementation Agent (write code to pass tests) →
Security Analyst (if security-related) →
Code Review →
Ship
Pattern 2: Architecture Decision
User Request →
Architect Agent (design decision with options) →
Security Analyst (security implications) →
Test Designer (how to test this architecture) →
User Approval →
Implementation
Pattern 3: Feature Implementation
Planning →
Test Designer (write tests) ||
Architect Agent (design structure) →
Implementation Agent (write code) →
Security Analyst (if needed) →
Code Reviewer (final check) →
Ship
Pattern 4: Debugging
Bug Report →
Code Reviewer (analyze issue) →
Test Designer (write failing test that exposes bug) →
Implementation Agent (fix bug) →
Verify Fix →
Ship
Real Example: Building an Auth Feature
Let me show you this in action. I needed to add JWT authentication to my NPM MCP project.
Step 1: Architect Agent
“Design a JWT authentication system for managing NPM instances. Need to support multiple instances with separate credentials.”
Architect Agent provided:
- Overall structure (AuthManager class)
- Token caching strategy
- Refresh logic
- Instance-specific token storage
- Trade-offs of different approaches
Step 2: Security Analyst
“Review this authentication design for security issues.”
Security Analyst identified:
- Need for token encryption at rest
- Refresh timing to prevent token expiration mid-request
- Secure credential storage requirements
- Input validation for credentials
- Recommendations for using
keyringlibrary
Step 3: Test Designer
“Design comprehensive tests for this auth system.”
Test Designer provided:
- 12 unit tests covering:
- Token caching
- Token refresh
- Multi-instance support
- Credential encryption
- Error cases
- Edge cases (expired tokens, invalid credentials)
- 3 integration tests with real NPM API
Step 4: Implementation Agent
“Implement AuthManager to pass these tests.”
Implementation Agent wrote:
- AuthManager class
- Token caching logic
- Automatic refresh
- Credential encryption
- All necessary helper methods
Step 5: Code Reviewer
“Review this implementation for improvements.”
Code Reviewer suggested:
- Better error messages
- Additional logging
- Type hint improvements
- Docstring enhancements
Result:
- Coverage: 95%
- Security issues: 0 (Security Analyst caught them in design)
- Time to implement: ~4 hours (vs. ~12 hours solo)
- Code quality: Production-ready
When NOT to Use Agents
Don’t invoke agents for:
- Simple bug fixes (tell Claude to fix it)
- Documentation updates (tell Claude to write it)
- Trivial refactoring (tell Claude to do it)
- Questions that CLAUDE.md answers (remind Claude to read the docs)
Agent orchestration is for complex tasks where specialization adds value.
The Critical Rule: Security Analyst
Here’s a non-negotiable:
A Security Analyst MUST review EVERY authentication, authorization, or credential-handling feature before it ships.
Not “usually.” Every time.
This is how you go from “45% of code has vulnerabilities” to “zero security issues in code review.”
Pattern 5: Pre-Approved Operations (Eliminating Friction)
Remember the verification overhead problem? Part of that is constant interruptions:
“Should I run pytest? Let me ask for approval.” “Should I check coverage? Let me ask for approval.” “Should I run mypy? Let me ask for approval.”
Each interruption breaks your flow. Each approval takes 5–10 seconds. Over a session, that’s minutes of wasted time.
The Permission Philosophy
Create .claude/settings.local.json:
{
"permissions": {
"allow": [
"Bash(pytest:*)",
"Bash(mypy:*)",
"Bash(ruff check:*)",
"Bash(ruff format:*)",
"Bash(git status)",
"Bash(git diff)",
"Bash(git log:*)",
"Bash(git branch)",
"Bash(find:*)",
"Bash(python3:*)",
"Bash(python:*)",
"WebSearch",
"Read(/**/*.py)",
"Read(/**/*.md)",
"Read(/**/*.yaml)",
"Read(/**/*.toml)"
],
"deny": [
"Bash(rm -rf *)",
"Bash(rm -rf /)",
"Bash(dd if=*)",
"Bash(mkfs.*)",
"Bash(> /dev/*)"
],
"ask": [
"Bash(git commit*)",
"Bash(git push*)",
"Bash(git pull*)",
"Bash(git merge*)",
"Bash(pip install*)",
"Bash(uv pip install*)",
"Write(**)"
]
},
"enableAllProjectMcpServers": false
}
Permission Categories
Always Allow (Safe, Common Operations)
- Running tests
- Checking coverage
- Linting
- Type checking
- Reading files
- Git status/diff/log
- Web search
Always Deny (Dangerous Operations)
- Deleting everything
- Overwriting system files
- Destructive disk operations
- Force pushing to main
Ask First (Important Operations)
- Committing code
- Pushing to remote
- Installing dependencies
- Writing files
Project-Specific Permissions
Each project may need different permissions:
For a Python project:
"allow": [
"Bash(pytest:*)",
"Bash(mypy:*)",
"Bash(black:*)",
"Bash(python:*)"
]
For a Node.js project:
"allow": [
"Bash(npm test*)",
"Bash(npm run lint*)",
"Bash(node:*)"
]
For a Docker project:
"allow": [
"Bash(docker ps)",
"Bash(docker images)",
"Bash(docker logs:*)"
],
"ask": [
"Bash(docker build*)",
"Bash(docker push*)"
]
The Flow Difference
Without pre-approved permissions:
AI: "I need to run pytest"
You: [Approve]
AI: "Tests pass. I need to check coverage."
You: [Approve]
AI: "Coverage is 82%. I need to run mypy."
You: [Approve]
AI: "Types check. I need to run ruff."
You: [Approve]
4 interruptions. 30–40 seconds lost. Broken flow.
With pre-approved permissions:
AI: "Running tests, checking coverage, running mypy, running ruff..."
AI: "All checks pass. Coverage 82%, no type errors, no lint issues."
0 interruptions. Continuous flow. Results in seconds.
Security Considerations
Pre-approving operations is safe IF:
- You understand what you’re approving
- Dangerous operations are in the deny list
- Important operations require confirmation
- You review the settings.local.json periodically
The deny list is your safety net. Make it comprehensive.
Pattern 6: Reusable Skills (Workflow Automation)
Some operations are complex enough that explaining them every time wastes time.
Create skills — documented workflows that Claude Code can invoke by name.
The Skill Structure
Create .claude/skills/create-mcp-tool/skill.md:
# Skill: Create New MCP Tool
**Purpose:** End-to-end workflow for creating a new MCP tool with tests
**Invocation:** When user says "create MCP tool" or similar
**Prerequisites:**
- Phase plan defines tool requirements
- Tool specification exists in PRD or Tool Catalog
## Workflow
### Step 1: Design (Architect Agent)
**Invoke:** Architect Agent
**Context:**
- Tool name and purpose
- Expected inputs and outputs
- NPM API endpoints involved
- Integration points
**Expected Output:**
- Tool function signature
- Input validation approach
- Error handling strategy
- Return value structure
### Step 2: Security Review (If applicable)
**Invoke:** Security Analyst (if tool handles credentials or sensitive data)
**Context:**
- Tool design from Step 1
- Security requirements
**Expected Output:**
- Security recommendations
- Input validation requirements
- Credential handling approach
### Step 3: Design Tests (Test Designer Agent)
**Invoke:** Test Designer Agent
**Context:**
- Tool design from Step 1
- Security recommendations from Step 2
- Tool specification
**Expected Output:**
- Complete test suite plan with:
- Unit tests (success cases)
- Unit tests (error cases)
- Unit tests (edge cases)
- Integration test with mocked NPM API
- Test data fixtures
### Step 4: Write Failing Tests
**Action:** Implement tests from Step 3
**Location:** `tests/unit/test_tools/test_[tool_name].py`
**Verify:** Run tests
```bash
pytest tests/unit/test_tools/test_[tool_name].py -v
Expected: All tests FAIL (no implementation yet)
### Step 5: Implement (Implementation Agent)
**Invoke:** Implementation Agent
**Context:**
- Failing tests from Step 4
- Tool specification
- Type hints required
**Expected Output:**
- Minimal code to pass tests
- Proper error handling
- Logging at appropriate levels
- Complete docstrings
### Step 6: Verify and Refactor
**Actions:**
1. Run tests:
``` bash
pytest tests/unit/test_tools/test_[tool_name].py -v
Expected: All tests PASS
2. Check coverage:
``` bash
pytest tests/unit/test_tools/test_[tool_name].py --cov=src/npm_mcp/tools/[tool_name] --cov-report=term-missing
Expected: ≥80% coverage
3. Run full test suite:
``` bash
pytest tests/ -v
Expected: All tests still passing
4. Refactor for clarity (if needed)
### Step 7: Integration
**Actions:**
- Register the tool in src/npm_mcp/server.py
- Update Tool Catalog documentation
- Add usage example
- Run full test suite
- Update the session log with the decision rationale
### Step 8: Documentation
**Update:**
- Tool docstring with examples
- TOOL_CATALOG.md with tool details
- README.md if user-facing
- Session log with completion notes
## Success Criteria
- All tests passing
- ≥80% coverage for new tool
- Full test suite still passing
- Tool registered in server
- Documentation complete
- Session log updated
## Common Issues
### Tests fail after implementation:
- Check test expectations match requirements
- Verify mock setup is correct
- Ensure error cases are handled
### Coverage below 80%:
- Add tests for error cases
- Add tests for edge cases
- Add tests for validation logic
### Integration fails:
- Check tool registration syntax
- Verify imports are correct
- Run linters (ruff, mypy)
Why Skills Scale Your Development
Without skills, every complex workflow requires re-explanation:
- “First do X, then Y, then Z…”
- “Don’t forget to check A”
- “Make sure B is done before C”
With skills, you say: “Follow the create-mcp-tool skill”
And the workflow is executed consistently every time.
Pattern 7: Quality Gates at Every Level
We talked about phase gates in Article 2. Let’s expand that to every level of development.
The Three-Tier Gate System
## Quality Gate System
### Tier 1: Commit Gates (Before EVERY commit)
**Automated checks:**
- [ ] All tests passing: `pytest tests/ -v`
- [ ] Coverage ≥ 80%: `pytest --cov=src --cov-report=term-missing`
- [ ] No linting errors: `ruff check .`
- [ ] No type errors: `mypy src/`
- [ ] No security issues: Basic vulnerability scan
**Manual checks:**
- [ ] Commit message follows conventional commits format
- [ ] Related tests included with implementation
- [ ] Documentation updated if needed
**If any check fails:** Fix before committing. No exceptions.
### Tier 2: Phase Gates (Before moving to next phase)
**Comprehensive review:**
- [ ] All phase objectives met (checklist complete)
- [ ] All tests passing (100% pass rate)
- [ ] Coverage ≥ 80% for all phase code
- [ ] Security Analyst review complete (if applicable)
- [ ] Performance benchmarks met (if defined)
- [ ] Phase documentation complete
- [ ] Phase retrospective written
- [ ] Session logs up to date
- [ ] next_session_plan.md updated
**If any check fails:** Cannot proceed to next phase.
### Tier 3: Release Gates (Before production deployment)
**Production readiness:**
- [ ] All phases complete
- [ ] Overall coverage ≥ 80%
- [ ] Security audit passed (no critical/high vulnerabilities)
- [ ] Performance requirements met
- [ ] Documentation complete and published
- [ ] User examples tested and working
- [ ] Docker image built and tested
- [ ] CI/CD pipeline functional
- [ ] Deployment plan documented
- [ ] Rollback plan documented
- [ ] Monitoring and alerting configured
**If any check fails:** Not production ready.
Automating Gates
Create scripts/check-commit-gate.sh:
#!/bin/bash
set -e
echo "Running Commit Gate Checks..."
echo "1. Running tests..."
pytest tests/ -v
echo "2. Checking coverage..."
pytest --cov=src --cov-report=term-missing --cov-fail-under=80
echo "3. Running linters..."
ruff check .
echo "4. Running type checks..."
mypy src/
echo "✅ All commit gate checks passed!"
Add to your CLAUDE.md:
## Before Every Commit
Run: `./scripts/check-commit-gate.sh`
Do not commit if any check fails.
Gate Philosophy
Gates aren’t obstacles. They’re quality insurance.
A test failure caught at commit takes 5 minutes to fix. The same inability, caught at the phase gate, takes 30 minutes (a context switch). The same failure seen in production takes hours or days (investigation, fix, deploy).
Gates shift cost left. Catch issues when they’re cheap to fix.
The Metrics That Matter
Track these metrics over time:
Lead Metrics (Predict future quality):
- Test pass rate (should always be 100%)
- Code coverage (should always be ≥80%)
- Commit gate pass rate (high = good practices)
- Security issues found in review (0 is the goal)
Lag Metrics (Reflect past quality):
- Bugs found in production (lower is better)
- Code churn (lower is better)
- Time to resolve production issues (lower is better)
- Technical debt items (should decrease over time)
Example Metrics Dashboard
Create .claude/metrics.md:
# Project Metrics
## Current Sprint (Week 7)
### Quality Metrics
- Test Pass Rate: 100% (762/762 passing)
- Code Coverage: 85.72% (target: 80%)
- Commit Gate Pass Rate: 98% (1 failure this week)
- Security Issues: 0
### Velocity Metrics
- Features Completed: 5 tools
- Tests Written: 87 new tests
- Lines of Code: +2,341
- Documentation: 12 pages updated
### Debt Metrics
- Known Issues: 2 (both low priority)
- Refactoring TODOs: 3
- Documentation TODOs: 1
## Historical Trend
### Phase 1
- Coverage: 88.32%
- Tests: 156 passing
### Phase 2
- Coverage: 85.41%
- Tests: 289 passing
### Phase 3
- Coverage: 86.44%
- Tests: 649 passing
### Phase 4 (Current)
- Coverage: 85.72%
- Tests: 762 passing
## Goals for Next Week
- Complete remaining Phase 4 tools
- Maintain 100% test pass rate
- Reach 86% coverage
- Complete Phase 4 retrospective
Pattern 8: Continuous Improvement (Retrospectives)
After each phase, create a retrospective. This creates a feedback loop that improves your process over time.
The Retrospective Template
Create .claude/retrospectives/phase_[n]_retrospective.md:
# Phase [N] Retrospective
**Date:** [Date]
**Phase:** Phase [N] - [Name]
**Duration:** [X] weeks
**Status:** ✅ Complete
## Overview
**Phase Goals:**
[What was this phase supposed to accomplish?]
**Actual Outcomes:**
[What actually got done?]
## Metrics
### Test Quality
- Tests Written: [X]
- Tests Passing: [X] ([Y]% pass rate)
- Coverage: [X]%
- Critical Path Coverage: [X]%
### Code Quality
- Lines of Code: +[X]
- Files Created/Modified: [X]
- Refactoring Sessions: [X]
- Code Churn: [X]%
### Velocity
- Planned Items: [X]
- Completed Items: [X]
- Blocked Items: [X]
- Estimated vs. Actual: [comparison]
## What Went Well
### Technical Wins
- [Specific thing that worked well]
- [Another win]
- [Another win]
### Process Wins
- [Process that worked]
- [Workflow that was efficient]
### Agent Usage
- [Agent pattern that worked well]
- [Example of good orchestration]
## What Could Be Improved
### Technical Challenges
- [Specific challenge encountered]
- **Impact:** [How it affected work]
- **Root Cause:** [Why it happened]
- **Learning:** [What we learned]
### Process Challenges
- [Process that didn't work well]
- **Impact:** [How it affected work]
- **Root Cause:** [Why it happened]
- **Learning:** [What we learned]
### Agent Usage Issues
- [Agent pattern that didn't work]
- **What happened:** [Description]
- **Why:** [Reason]
- **Better approach:** [What would work better]
## Specific Examples
### Example 1: [Title]
**Context:** [What was happening]
**Issue:** [What went wrong or right]
**Outcome:** [Result]
**Learning:** [What to do differently]
### Example 2: [Title]
[Same structure]
## Action Items for Next Phase
### Process Improvements
- [ ] [Specific change to make]
- **Why:** [Reason for change]
- **How:** [Implementation plan]
- **Success metric:** [How to measure]
### Technical Improvements
- [ ] [Specific change]
- **Why:** [Reason]
- **How:** [Implementation]
- **Success metric:** [Measurement]
### Documentation Improvements
- [ ] [Specific change]
## Decision to Keep/Change
### Keep (Working Well)
- [Thing to keep doing]
- [Thing to keep doing]
### Change (Needs Improvement)
- [Thing to change]
- **From:** [Old way]
- **To:** [New way]
- **Because:** [Reason]
### Experiment (Worth Trying)
- [Thing to try next phase]
- **Hypothesis:** [What we expect]
- **Test:** [How to verify]
## Phase Completion Checklist
- [x] All phase objectives met
- [x] 100% tests passing
- [x] ≥80% coverage
- [x] Documentation complete
- [x] Security review done
- [x] Retrospective complete
- [x] Next phase planned
## Next Phase Preview
**Phase [N+1]:** [Name]
**Focus:** [What next phase is about]
**Duration:** [X] weeks
**Key Changes:** [What we're doing differently based on this retro]
The Improvement Loop
Retrospectives aren’t just documentation. They’re a feedback mechanism:
- Do the work (implement phase)
- Reflect (write a retrospective)
- Identify patterns (what worked, what didn’t)
- Make changes (update process, CLAUDE.md, skills)
- Try a new approach (next phase)
- Measure results (did it help?)
- Reflect again (next retrospective)
Over time, your process gets better. Your CLAUDE.md gets more comprehensive. Your skills library grows. Your agent orchestration gets more sophisticated.
You’re not just building software. You’re building a system for building software.
Final Thoughts
The research is clear: most developers are slower, produce lower-quality code, and introduce more bugs with AI assistants.
But it doesn’t have to be that way.
The difference isn’t the tool. It’s the system around the tool.
The question isn’t whether AI-assisted development can work. It can.
The question is whether you’re willing to build the system that makes it work.
Most developers won’t. They’ll keep treating AI like a magic box. They’ll keep getting slower. Keep shipping bugs. Keep wondering why it’s not working.
But you don’t have to be most developers.
You have the complete framework:
- Clear direction (CLAUDE.md)
- Built-in verification (TDD)
- Manageable scope (phases)
- Preserved context (sessions)
- Specialized expertise (agents)
- Efficient flow (permissions)
- Reusable workflows (skills)
- Quality insurance (gates)
- Continuous improvement (retrospectives)
Start small. Build your CLAUDE.md. Enforce TDD—document sessions. Then add the advanced patterns as needed.
Within weeks, you’ll see the difference. Within months, you’ll wonder how you ever worked any other way.
The framework is here. The patterns are proven. The results are real.
The only question left is: Are you ready to put in the work?
Check out my collection of Claude Code Agents and Skills
