Living system · production patterns · trade-offs before recipes

Architecture Pattern Library

A reference library for the AI architecture decisions senior engineers actually face. Every pattern names its trade-offs and the case where it's the wrong choice — no recipe without the cost. Where we run one ourselves, the page carries the as-built evidence: what shipped, what is only wired, and what it cost.

The patterns

As-built evidence
Agents

Cost · Complexity · When not to use

How do I stop an agent from running away?

The Bounded Agentic Loop: hard turn and tool-call ceilings, least-privilege tools, and graceful escalation instead of a runaway agentic loop burning budget or taking unsafe actions.

As-built evidence
Retrieval

Cost · Complexity · When not to use

How do I make retrieval answers provable?

RAG with Grounded Citations: every retrieved answer carries its source passages, so a claim can be checked instead of trusted — the difference between a demo and a system you can ship.

As-built evidence
Cost

Cost · Complexity · When not to use

How do I stop paying Opus prices for Haiku work?

Role-Based Model Routing: route each call to the cheapest model that meets its quality bar — hints to Haiku, tutoring to Sonnet, evals to Opus — instead of one model for everything.

As-built evidence
Quality

Cost · Complexity · When not to use

How do I know a prompt change didn't make things worse?

Eval Harness as Release Gate: a scored eval suite runs before every prompt or model change ships, so regressions get caught by a number, not a user complaint.

As-built evidence
Safety

Which agent actions need a human sign-off?

Human-in-the-Loop Approval Boundaries: draw the line between what an agent can do autonomously and what needs a human approve step — and where to enforce it so the boundary can't be bypassed.

As-built evidence
State

What should an agent remember, where, and for how long?

Agent Memory and State: separate working context, session history, and durable per-user memory, each with its own storage and lifetime, instead of one growing context window.

As-built evidence
State

When a conversation gets long, what do you let it forget?

Conversation Compaction: choose between a sliding window, your own summary, server-side compaction and a window plus pinned memory, keyed on what must survive exactly and what counts as user data.

As-built evidence
Safety

One safety filter isn't enough — what are the layers?

Guardrails Defense-in-Depth: stack input filtering, bounded tool scope, output checks, and monitoring, because any single guardrail layer will eventually be bypassed.

As-built evidence
Safety

Cost · Complexity · When not to use

How do I stop a poisoned doc from triggering a write?

The Capability Latch: once a turn ingests untrusted external content, its write-capable tools are switched off for the rest of that turn — set by a pre-scan of the whole turn, so tool ordering can't bypass it.

As-built evidence
Quality

Cost · Complexity · When not to use

A rule keeps getting skipped — how do I make it stick?

The Deterministic Gate: when a rule is mechanically checkable, stop rewording the instruction and put the invariant in a check that runs as code and fails closed on the one path to production.

As-built evidence
Quality

Cost · Complexity · When not to use

Why did an empty state show somebody else's data?

Fail Empty: a consumer that overwrites but never clears renders absence as a result — ship the empty state, delete the placeholder, and negate floor predicates so a malformed number falls on the side you chose.

Safety

Cost · Complexity · When not to use

How do I block a call that's only unsafe given what preceded it?

Sequence-Aware Authorization: make the allow/deny decision a predicate over the session's action history — ordering, argument provenance, exhaustion — and know the retry collision it creates before you ship it.

As-built evidence
Cost

Cost · Complexity · When not to use

Why is my prompt cache never hitting?

Cache-Aware Prompt Layout: caching is an ordering commitment, not a flag — what must stay byte-stable, why a cheap tier pinned to an older model can be the hardest to cache, and the parallel fan-out that costs 3.8× a serialised call.

As-built evidence
Cost

Cost · Complexity · When not to use

How do I cap agent spend somewhere my code can see it?

Enforceable Spend Ceilings: a dashboard limit is a control your bill has, not one your system has — where the ceiling belongs, why every cause returns the same 429, and what the user sees when it bites.

As-built evidence
Quality

Cost · Complexity · When not to use

Does pinning a model id actually protect me from it changing?

Pinning a Model Is Not Pinning Its Behaviour: a pinned id protects you against retirement, with notice — it does not protect you against a deprecated parameter, a different serving backend, or a heavier tokenizer on the same id. What needs pinning is an eval, not an id.

As-built evidence
Quality

Cost · Complexity · When not to use

Why did our duplicate check silently drop real changes?

Dedup Is Not Acknowledgement: a duplicate-suppression check protects the sink, not the source's watermark. Advance a cursor, snapshot, or watermark only once the item is durably consumed downstream, and count what you suppress.

Cost

Cost · Complexity · When not to use

Can I put a similarity cache in front of my model without serving the wrong answer?

Semantic Caching: prompt caching never changes the answer, a gateway cache needs an identical request, a semantic cache answers a similar one. A four-question admission test for which routes can afford that, run against our own five model routes.

As-built evidence
Quality

Cost · Complexity · When not to use

When my code acts on a model's answer, what exactly do I validate?

Parse the Verdict, Not the Text: structured-output mode guarantees shape, not truth and not delivery. Extract the last verdict, check the contract a schema cannot state, and give "no valid verdict" its own state with a policy chosen per consumer.

As-built evidence
Quality

Cost · Complexity · When not to use

Which model-call failures should I retry, and which should I stop on?

An LLM Error Means What Your Path Says It Means: behind a gateway the same status code means different things. Classify by call path and body, give each class one disposition, and make unknown mean surface — plus what our own client retries (one class) and what it does not.

Cost

Cost · Complexity · When not to use

How do I know my cost meter matches the bill?

Your Cost Meter Is a Copy of the Price List: a locally computed cost drifts from the vendor's, and the drift has a direction. Write down which way each gap errs, keep the provider's own figure beside yours, and enforce on one number while auditing on the other.

Quality

Cost · Complexity · When not to use

Does a dependency bump change what my model requests mean?

Pin the API Version, Not Just the Model: the model id, the API version and the SDK major are three pins that move independently, and a major SDK release can change the version your requests use. Review that bump as a migration, set the version yourself where you build the request, and say which pin a proxy owns.

Privacy

Cost · Complexity · When not to use

Where do my prompts persist once they leave my database?

Every Hop Keeps a Copy: walk the real request path, from gateway log to router to model provider to provider features, and ask four questions per hop. Is there a copy, who set the default, does your erasure reach it, is the feature eligible for your retention arrangement.

Kept current, visibly

A stale pattern page is worse than none. Every page carries a dated last reviewed kicker, and the drifty facts — model names and pricing, guardrail feature sets, exam/framework numbering, provider API shapes — get re-checked on a schedule, not left to rot. That maintenance discipline is what the membership funds.

Learn the patterns, then build the system underneath them.

The patterns are free and public. The aiArch curriculum teaches the engineering underneath them — agents, retrieval, evals, and production architecture — on a platform that runs many of these same patterns in its own build.

Free with an account: Track 0 (The Mindset Shift) and the Track 0 coach allowance, no card · every claim cited · full curriculum with membership