AI Engineering Patterns
Reusable architectural patterns for production AI systems. Each pattern includes a problem statement, solution blueprint, trade-offs, and when-to-use guidance.
17 patterns documented
Pattern 01
Circuit Breaker for LLMs
Solves
Prevent cascading failures by temporarily stopping requests to a failing LLM provider and automatically recovering when it stabilises.
Pattern 02
Context Compression
Solves
Compress conversation history or retrieved documents to fit within context window limits while preserving critical information.
Pattern 03
Evaluation-Driven Development (EDD)
Solves
Build eval suites before building AI features, then measure quality continuously — the test-driven development of AI systems.
Pattern 04
Fallback Chain
Solves
Route LLM requests through a prioritised list of models/providers, falling back to alternatives on rate limits, errors, or latency SLO violations.
Pattern 05
GraphRAG
Solves
Augment vector search RAG with a knowledge graph layer to enable multi-hop reasoning over entity relationships.
Pattern 06
Guardrail Sandwich
Solves
Wrap every LLM call with input validation and output validation layers to enforce safety, quality, and schema compliance.
Pattern 07
Human-in-the-Loop (HITL)
Solves
Insert human approval checkpoints in agent workflows for high-stakes, irreversible, or high-uncertainty actions.
Pattern 08
Intent Router
Solves
Classify user intent first, then route to specialised handlers — cheaper models for simple tasks, expensive models for complex ones.
Pattern 09
Plan and Execute
Solves
Separate planning (powerful model) from execution (cheaper models) for complex multi-step tasks, reducing cost while maintaining quality.
Pattern 10
Prompt Versioning
Solves
Manage prompts as code artifacts with version control, review, and rollback — treating prompt changes with the same rigour as code changes.
Pattern 11
ReAct Agent
Solves
Interleave Thought → Action → Observation cycles so the LLM reasons before invoking tools and adapts based on results.
Pattern 12
Reflection Pattern
Solves
Have the agent critique its own output and iteratively refine it before returning the final result.
Pattern 13
Semantic Cache
Solves
Cache LLM responses by semantic similarity of the prompt rather than exact string match, reducing cost and latency for similar queries.
Pattern 14
Streaming Pipeline
Solves
Stream LLM tokens through a processing pipeline to the client, showing output progressively and enabling real-time safety checks.
Pattern 15
Tenant Isolator
Solves
Ensure strict data isolation between tenants in multi-tenant LLM applications through namespace partitioning and context boundaries.
Pattern 16
Tiered Retrieval
Solves
Combine keyword search (BM25), semantic search (vectors), and re-ranking in a multi-stage pipeline for optimal RAG quality.
Pattern 17
Token Budget Gate
Solves
Enforce per-user, per-tenant, or per-request token limits to prevent runaway costs in multi-tenant LLM systems.

