Decision Guide
Start from the problem you have today and find the two or three patterns worth reading first.
Nobody needs all 50 patterns. Find the problem that sounds most like yours below, read the patterns it points to, and run their examples. Each one is a single pytest command.
"Our LLM bill is too high"
Measure before you optimize. Put an LLM Gateway in front of your model calls so you know which feature is spending what. Then:
- The same questions keep coming in → Semantic Caching
- Everything goes to the flagship model → Model Router
- Every request sends maximum context → Cascading Context Assembly, then Token Budget
- Agents use 40 tool calls on simple questions → Effort Scaling
- Every request resends the same long system prompt, tools or conversation → Prompt Prefix Caching. Usually the biggest single saving, and free to try.
- Offline jobs (classification, backfills, eval runs) go through the live API → Batch Inference
- Long agent sessions get slower and pricier with every step → Context Compaction
- You live on free tiers or hard caps, and one 429 takes a feature down → Quota-Aware Model Pool
"The provider had a bad day and so did we"
- Sustained degradation: errors, slow or empty answers → Circuit Breaker for LLMs
- Most requests are fine, but p99 is awful → Request Hedging for LLMs
- Answers come back successfully but unsure or incomplete → Uncertainty-Triggered Retry
"The RAG answers are wrong"
Work through these in order. Each one fixes a different layer.
- The right document isn't retrieved (exact terms, IDs, error codes) → Hybrid Search
- Irrelevant chunks get in, or the bot answers when it should say "I don't know" → Retrieval Quality Gate
- Old versions of documents win → Retrieval Freshness Watermark
- The top-5 results all say the same thing → Semantic Deduplication
- Good context, but the answer adds details that aren't in it → Grounding Verifier. If the facts can be read by code (numbers, names, statuses), go further with the Extract–Explain Split so the model never produces them.
- Users search a structured catalogue, and an invented result is worse than none → Intent-Only Retrieval
- The question is about relationships ("who owns what depends on X") → GraphRAG, with Entity Resolution Graph to keep the graph clean
- Upstream data keeps changing shape under you → Data Contract
"We changed a prompt and something broke"
- Before trusting any score: Frozen Evaluation Set, so the number you quote wasn't tuned against.
- Before merging: Prompt Mutation Testing checks robustness, and LLM-as-Judge runs the regression suite.
- Before users see it: Shadow Model Evaluation runs it on real traffic with zero exposure.
- While rolling out: Prompt Canary Deployment uses staged rollout with automatic rollback.
"We can't see what's going on"
- Something broke and nobody knows if it's our deploy or the provider → Provider Behavior Probes
- Why was this request slow, expensive or wrong? → Span-Level Tracing
- Is retrieval quietly getting worse? → Embedding Drift Detector
- Is quality going up or down this week? → LLM-as-Judge on sampled traffic
"We're building agents"
A reasonable starting stack, in the order you'll need it:
- Loop Termination: every loop needs a stop rule before it needs anything else.
- Guardrails with a tool policy: decide what the agent may do in code.
- Human-in-the-Loop for anything irreversible.
- Tool Output Firewall as soon as the agent reads web pages, emails or user-written data.
- Span-Level Tracing, because you can't debug agents without it.
- Context Compaction once sessions get long.
When agents start doing real work unattended:
- They say "done" when they aren't → Maker–Verifier Split
- They repeat the same mistake → Reflexion Loop, plus No-Progress Detection
- They fail at step 7 of 10 and start over → Semantic Rollback
- A retry or a replay sends the email, or charges the card, twice → Idempotent Tool Calls
- Long jobs get lost when a worker dies, or run twice → Durable LLM Job Queue
- You want the model to optimize code or queries without breaking them → Execution-Verified Rewrite
- One agent's context isn't enough for the task → Multi-Agent Orchestration (read its "When NOT to use it" first)
- Partial answers from different attempts could be combined → Graph of Thoughts
"Security or compliance is asking questions"
- Prompt injection, PII in prompts → Input Sanitization. Read its honest limits, then Guardrails.
- "What is this system for, and how was it tested?" → Model Card
- "Who approved that action?" → Human-in-the-Loop
- Too many decisions for a person to review, too risky to automate blindly → Reversible Auto-Decision
- The model fills forms or records that a person owns → Suggest–Edit–Commit: an editable draft, and every correction becomes a quality metric
- Model output feeds code (filters, routing, database fields) → Closed-Vocabulary Output
"Long conversations go off the rails"
- The bot forgets what the user said earlier → Sliding Context Window with Memory Consolidation
- Agent transcripts fill the window with tool output → Context Compaction