3AI Design Patterns
70 AI design patterns for LLM apps and agents
Proven answers to recurring problems in LLM apps and AI agents: composition, RAG, memory, tools, guardrails, and operations.
- items
- 70
- Groups
- 7
Composition 10
How to arrange model calls in sequence, in parallel, or in loops.
- Pattern
Prompt Chaining
Split the task into fixed steps where each output feeds the next input.
- Pattern
Routing
Classify the input and send each kind down a specialized path.
- Pattern
Sectioning
Break the task into independent parts and run them all in parallel.
- Pattern
Voting
Run the same task several times or with several models and decide by majority or threshold.
- Pattern
Orchestrator-Workers
One model decides subtasks on the fly and hands them to workers.
- Pattern
Evaluator-Optimizer
One model generates, another grades against clear criteria, and the loop repeats until it passes.
- Pattern
Structured Output
Require the model to answer in a schema and validate the response.
- Pattern
Few-Shot Selector
Pick, at request time, the examples most similar to the current input.
- Pattern
Prompt Template Registry
Store prompts as versioned artifacts with variables and history.
- Pattern
Map-Reduce
Process chunks in parallel and then combine the results into one answer.
Context and knowledge 11
How to get the right information into the window at the right time.
- Pattern
Retrieval-Augmented Generation (RAG)
Fetch relevant passages and hand them to the model along with the question.
- Pattern
Hybrid Search
Combine keyword and vector search so you miss neither synonyms nor exact codes.
- Pattern
Reranking
Retrieve many candidates and use a sharper model to pick the best ones.
- Pattern
Query Rewriting
Turn the user's question into one or more better searches.
- Pattern
GraphRAG
Walk relationships between entities when the answer depends on connections, not one passage.
- Pattern
Agentic RAG
Let the agent decide when, where, and how many times to search.
- Pattern
Contextual Chunking
Split documents along their structure and attach to each chunk the context it came from.
- Pattern
Context Compaction
Summarize or prune the context as it grows, keeping what matters.
- Pattern
Context Isolation
Run subtasks in separate contexts and bring back only the result.
- Pattern
Progressive Disclosure
Show the model only a summary of each skill and load the details when it asks.
- Pattern
Citation Grounding
Require every claim to point at a source and check that the source says it.
Memory and state 8
How to remember, forget, and resume across turns, sessions, and failures.
- Pattern
Short-Term Memory
Keep the current conversation's state explicit, outside the raw transcript.
- Pattern
Long-Term Memory
Store facts and preferences across sessions and bring back only the relevant ones.
- Pattern
Episodic Memory
Remember past runs, what worked and what failed, to act better next time.
- Pattern
Memory Consolidation
Review memories in the background to merge, correct, and forget.
- Pattern
Scratchpad
Give the agent a place to note its plan and partial results outside the conversation.
- Pattern
Checkpoint and Resume
Save state at safe points so the run can continue where it stopped.
- Pattern
Durable Workflow
Run the agent on an engine that guarantees each step through crashes and long waits.
- Pattern
Shared Blackboard
A structured space where several agents post and read facts, each with an owner and a format.
Tools and action 10
How the model acts in the world without breaking things.
- Pattern
Tool Use
Give the model well described functions to fetch data and take action.
- Pattern
Tool Router
Pick a small subset of tools before calling the main model.
- Pattern
Code Execution Sandbox
Let the model write and run code in an isolated, disposable environment.
- Pattern
Computer Use
Drive graphical interfaces through screen, mouse, and keyboard when there is no API.
- Pattern
Browser Agent
Navigate, read, and fill web pages using the DOM structure.
- Pattern
MCP Adapter
Expose systems as MCP servers so any agent uses the same contract.
- Pattern
Tool Result Summarizer
Shrink large tool responses to what matters before they reach the model.
- Pattern
Dry Run
Produce the action plan and show its effect before actually running it.
- Pattern
Idempotent Action
Make sure repeating the same call never duplicates the effect.
- Pattern
Compensating Action
For every step with an effect, have a step that undoes it, as in a saga.
Agent behavior 13
How agents reason, plan, share work, and know when to stop.
- Pattern
ReAct Loop
Alternate reasoning, action, and observation until the task is done.
- Pattern
Plan-then-Execute
Write the full plan first and execute steps with a simpler model or with code.
- Pattern
Replanning
Revise the plan when reality does not match expectations.
- Pattern
Reflection
Have the model critique its own result against an external signal and fix it.
- Pattern
Self-Consistency
Generate several reasoning paths and keep the most frequent answer.
- Pattern
Tree of Thoughts
Explore alternatives as a tree, score each branch, and prune the bad ones.
- Pattern
Human-in-the-Loop
Pause at defined points for a human to approve, edit, or reject.
- Pattern
Multi-Agent Handoff
Transfer the conversation to another specialist agent along with the needed state.
- Pattern
Subagent Delegation
The main agent spawns subagents for focused tasks and receives only the conclusion.
- Pattern
Supervisor
One agent coordinates others, decides who works, and checks the delivery.
- Pattern
Debate
Two or more models argue positions and a judge decides.
- Pattern
Stop Conditions
Define clearly when the agent is done, has given up, or needs help.
- Pattern
Long-Running Agent
Keep an agent working for hours or days with goals, checkpoints, and reports.
Safety and reliability 10
How to contain the model and survive its failures.
- Pattern
Input Guardrails
Check input before the main model: topic, abuse, injection, and sensitive data.
- Pattern
Output Guardrails
Check the response before it reaches the user or a tool.
- Pattern
Dual LLM
A quarantined model reads untrusted content; another, with tools, only sees the structured result.
- Pattern
Least-Privilege Tools
Each tool with its own scope, credential, and limits.
- Pattern
Constitutional Check
Grade the response against a short list of written principles and revise on violation.
- Pattern
Fallback Model
Keep another model or provider ready to take over when the main one fails.
- Pattern
Circuit Breaker
Stop calling a failing service and resume once it recovers.
- Pattern
Output Validation and Repair
Validate output with code and, on failure, send the error back to the model to fix.
- Pattern
PII Redaction
Remove or mask personal data before the model and the logs, in line with privacy law.
- Pattern
Audit Log
Record who asked, what the model saw, what it decided, and what it ran.
Operations and quality 8
How to measure, cut cost, and evolve the system safely.
- Pattern
Eval Harness
Run test cases automatically on every prompt, model, or code change.
- Pattern
LLM-as-Judge
Use a model with a rubric to grade answers that have no exact expected output.
- Pattern
Golden Dataset
Keep a curated set of inputs and expected answers that grows with real bugs.
- Pattern
Shadow Deploy
Run the new version alongside real traffic, hidden from users, and compare.
- Pattern
Model Cascade
Start with the cheapest model and move up only when needed.
- Pattern
Semantic Cache
Answer equivalent questions with an already generated response.
- Pattern
Prompt Caching
Reuse the fixed prompt prefix to cut cost and latency.
- Pattern
Cost Budget
Measure and cap spending per task, user, and day, with alerts and a cut-off plan.