|
| 1 | +# Pattern Catalog Guide |
| 2 | + |
| 3 | +The Pattern Catalog is a collection of reusable software patterns extracted from the Empathy Framework, organized for cross-domain transfer and Level 5 (Systems Thinking) capability development. |
| 4 | + |
| 5 | +## What is the Pattern Catalog? |
| 6 | + |
| 7 | +The Pattern Catalog serves three purposes: |
| 8 | + |
| 9 | +1. **Document existing patterns** - Capture what we've built so it can be reused |
| 10 | +2. **Enable cross-domain transfer** - Apply patterns from one domain to solve problems in another |
| 11 | +3. **Accelerate Level 5 thinking** - Train the ability to recognize "this problem is like that solved problem" |
| 12 | + |
| 13 | +## Catalog Location |
| 14 | + |
| 15 | +``` |
| 16 | +patterns/ |
| 17 | +├── README.md # Index and usage guide |
| 18 | +├── reliability/ # Patterns from reliability engineering |
| 19 | +│ ├── circuit-breaker.md |
| 20 | +│ ├── graceful-degradation.md |
| 21 | +│ └── retry-with-backoff.md |
| 22 | +├── observability/ # Patterns from observability/SRE |
| 23 | +│ ├── health-monitoring.md |
| 24 | +│ └── telemetry-tracking.md |
| 25 | +└── cross-domain/ # Level 5 transfer examples |
| 26 | + ├── circuit-breaker-to-trust.md |
| 27 | + ├── alerting-to-empathy-levels.md |
| 28 | + └── graceful-degradation-to-conversation.md |
| 29 | +``` |
| 30 | + |
| 31 | +## How to Use the Catalog |
| 32 | + |
| 33 | +### For Developers |
| 34 | + |
| 35 | +When facing a new problem: |
| 36 | + |
| 37 | +1. **Search for similar patterns** - Look through the catalog for patterns that solve similar problems |
| 38 | +2. **Check cross-domain transfers** - Non-obvious solutions often come from other domains |
| 39 | +3. **Consider the abstraction** - What's the core mechanism? Does it apply elsewhere? |
| 40 | + |
| 41 | +```python |
| 42 | +# Example: Need to handle user who keeps getting wrong answers |
| 43 | + |
| 44 | +# Search catalog → find circuit-breaker.md |
| 45 | +# Read cross-domain → circuit-breaker-to-trust.md |
| 46 | +# Result: Use TrustCircuitBreaker instead of inventing new solution |
| 47 | + |
| 48 | +from empathy_os.trust import TrustCircuitBreaker |
| 49 | +breaker = TrustCircuitBreaker(user_id="user_123") |
| 50 | +``` |
| 51 | + |
| 52 | +### For Architects |
| 53 | + |
| 54 | +When designing new features: |
| 55 | + |
| 56 | +1. **Check if pattern already exists** - Avoid reinventing the wheel |
| 57 | +2. **Identify pattern opportunities** - When building something new, is it generalizable? |
| 58 | +3. **Document new patterns** - Contribute to the catalog |
| 59 | + |
| 60 | +### For AI Systems |
| 61 | + |
| 62 | +The catalog can be referenced by AI systems: |
| 63 | + |
| 64 | +```python |
| 65 | +# When solving a problem, reference relevant patterns |
| 66 | +patterns = catalog.search("protect relationship from failures") |
| 67 | +# Returns: circuit-breaker-to-trust.md |
| 68 | + |
| 69 | +# Apply the pattern |
| 70 | +solution = apply_pattern(patterns[0], problem_context) |
| 71 | +``` |
| 72 | + |
| 73 | +## Pattern Template |
| 74 | + |
| 75 | +Every pattern follows this structure: |
| 76 | + |
| 77 | +```markdown |
| 78 | +# Pattern Name |
| 79 | + |
| 80 | +**Source Domain:** Where this pattern originated |
| 81 | +**Location in Codebase:** File paths |
| 82 | +**Level:** Capability level (1-5) |
| 83 | + |
| 84 | +## Overview |
| 85 | +What problem does this solve? |
| 86 | + |
| 87 | +## Implementation |
| 88 | +Code examples from actual codebase |
| 89 | + |
| 90 | +## Key Insight |
| 91 | +The one thing to remember |
| 92 | + |
| 93 | +## Cross-Domain Transfer Potential |
| 94 | +Where else could this apply? |
| 95 | +``` |
| 96 | + |
| 97 | +## Understanding Cross-Domain Transfer |
| 98 | + |
| 99 | +Cross-domain transfer is the Level 5 capability that makes the catalog powerful. It's the ability to recognize that: |
| 100 | + |
| 101 | +> "This problem in Domain A has the same structure as that solved problem in Domain B" |
| 102 | +
|
| 103 | +### Example: Circuit Breaker → Trust |
| 104 | + |
| 105 | +| Reliability Domain | Trust Domain | |
| 106 | +|-------------------|--------------| |
| 107 | +| Service keeps failing | User keeps getting wrong answers | |
| 108 | +| Stop calling failing service | Stop acting without confirmation | |
| 109 | +| Wait for recovery period | Wait for trust recovery period | |
| 110 | +| Test with limited calls | Test with supervised interactions | |
| 111 | +| Resume normal operation | Restore full autonomy | |
| 112 | + |
| 113 | +The **mechanism** is identical: |
| 114 | +1. Track failures/damage |
| 115 | +2. Trip when threshold exceeded |
| 116 | +3. Wait for recovery period |
| 117 | +4. Test recovery |
| 118 | +5. Resume normal |
| 119 | + |
| 120 | +### Finding Transfer Opportunities |
| 121 | + |
| 122 | +Ask these questions: |
| 123 | + |
| 124 | +1. **What's the abstract problem?** |
| 125 | + - Not "API keeps timing out" but "unreliable component" |
| 126 | + - Not "user frustrated with wrong answers" but "relationship degrading" |
| 127 | + |
| 128 | +2. **What's the mechanism?** |
| 129 | + - State machine? Threshold? Fallback chain? |
| 130 | + - Time-based? Count-based? Score-based? |
| 131 | + |
| 132 | +3. **Where else does this structure appear?** |
| 133 | + - Different domain, same structure = transfer opportunity |
| 134 | + |
| 135 | +## Current Patterns |
| 136 | + |
| 137 | +### Reliability Patterns |
| 138 | + |
| 139 | +| Pattern | Key Insight | Implementation | |
| 140 | +|---------|-------------|----------------| |
| 141 | +| [Circuit Breaker](../../patterns/reliability/circuit-breaker.md) | Fail fast to prevent cascade | `src/empathy_os/resilience/circuit_breaker.py` | |
| 142 | +| [Graceful Degradation](../../patterns/reliability/graceful-degradation.md) | Partial value beats failure | `src/empathy_os/resilience/fallback.py` | |
| 143 | +| [Retry with Backoff](../../patterns/reliability/retry-with-backoff.md) | Transient failures recover | `src/empathy_os/resilience/retry.py` | |
| 144 | + |
| 145 | +### Observability Patterns |
| 146 | + |
| 147 | +| Pattern | Key Insight | Implementation | |
| 148 | +|---------|-------------|----------------| |
| 149 | +| [Health Monitoring](../../patterns/observability/health-monitoring.md) | Degraded predicts failure | `src/empathy_os/resilience/health.py` | |
| 150 | +| [Telemetry Tracking](../../patterns/observability/telemetry-tracking.md) | Failures are learning data | `src/empathy_os/models/telemetry.py` | |
| 151 | + |
| 152 | +### Cross-Domain Transfers (Implemented) |
| 153 | + |
| 154 | +| Transfer | From → To | Implementation | |
| 155 | +|----------|-----------|----------------| |
| 156 | +| [Circuit Breaker → Trust](../../patterns/cross-domain/circuit-breaker-to-trust.md) | Reliability → Trust | `src/empathy_os/trust/circuit_breaker.py` | |
| 157 | + |
| 158 | +### Cross-Domain Transfers (Documented, Not Yet Implemented) |
| 159 | + |
| 160 | +| Transfer | From → To | Status | |
| 161 | +|----------|-----------|--------| |
| 162 | +| [Alerting → Empathy Levels](../../patterns/cross-domain/alerting-to-empathy-levels.md) | Observability → Empathy | Documented | |
| 163 | +| [Graceful Degradation → Conversation](../../patterns/cross-domain/graceful-degradation-to-conversation.md) | Reliability → UX | Documented | |
| 164 | + |
| 165 | +## Contributing to the Catalog |
| 166 | + |
| 167 | +### Adding a New Pattern |
| 168 | + |
| 169 | +1. **Identify the pattern** - What's the core mechanism? |
| 170 | +2. **Find the implementation** - Where is it in the codebase? |
| 171 | +3. **Document using template** - Create markdown file in appropriate directory |
| 172 | +4. **Look for transfers** - Could this apply elsewhere? |
| 173 | + |
| 174 | +### Adding a Cross-Domain Transfer |
| 175 | + |
| 176 | +1. **Identify source pattern** - What pattern are you transferring? |
| 177 | +2. **Map the concepts** - Create a table showing the mapping |
| 178 | +3. **Implement if valuable** - Create working code |
| 179 | +4. **Document the transfer** - Why does this work? |
| 180 | + |
| 181 | +### Pattern Naming |
| 182 | + |
| 183 | +- Use lowercase with hyphens: `circuit-breaker.md` |
| 184 | +- Be descriptive but concise |
| 185 | +- Cross-domain: `source-to-target.md` |
| 186 | + |
| 187 | +## Metrics |
| 188 | + |
| 189 | +Track catalog health: |
| 190 | + |
| 191 | +- **Patterns documented:** 8 |
| 192 | +- **Cross-domain transfers:** 3 (1 implemented) |
| 193 | +- **Codebase coverage:** ~40% |
| 194 | +- **Last updated:** 2025-12-28 |
| 195 | + |
| 196 | +## Level 5 Capability Development |
| 197 | + |
| 198 | +The catalog is a tool for developing Level 5 (Systems Thinking) capability: |
| 199 | + |
| 200 | +| Level | Description | Catalog Usage | |
| 201 | +|-------|-------------|---------------| |
| 202 | +| 1 - Reactive | Respond to requests | None | |
| 203 | +| 2 - Guided | Follow patterns | Reference patterns | |
| 204 | +| 3 - Proactive | Anticipate needs | Suggest patterns | |
| 205 | +| 4 - Anticipatory | Predict problems | Recognize pattern fits | |
| 206 | +| 5 - Systems | Transfer across domains | Create new transfers | |
| 207 | + |
| 208 | +### Exercises |
| 209 | + |
| 210 | +1. **Pattern Recognition** - Given a problem, find 3 potentially applicable patterns |
| 211 | +2. **Transfer Identification** - Find an existing pattern, identify 2 new domains it could apply to |
| 212 | +3. **Implementation** - Take a documented transfer and implement it |
| 213 | + |
| 214 | +## Further Reading |
| 215 | + |
| 216 | +- [Trust Circuit Breaker Guide](./trust-circuit-breaker.md) - Detailed guide on the implemented transfer |
| 217 | +- [Pattern Catalog README](../../patterns/README.md) - Catalog index and quick reference |
| 218 | +- [Empathy Framework Architecture](../architecture.md) - Overall system design |
| 219 | + |
| 220 | +--- |
| 221 | + |
| 222 | +*The Pattern Catalog is a key component of reaching Level 5 (Systems Thinking) capability.* |
0 commit comments