For architects: three decisions the labs leave to you¶
For architects and tech leads who own or review AI designs across teams (skills ladder level 4). The labs teach each pattern on its own. This page is about three choices that cut across all of them: what goes into each call, whether to use a framework, and when (rarely) to fine-tune. Every claim points to a lab you can rerun.
Time: about an hour of reading. Needs: the Core path, or at least System design and the guides of the topics your teams build with.
1. Context engineering: what goes into each call¶
The model knows only what one call contains (AI basics). Context engineering is deciding, for every call, what goes in, in what order, and what stays out. Most "the model got it wrong" bugs, and most of the bill, are context decisions.
What competes for the window
| Part | Grows with | Who controls it | Lab |
|---|---|---|---|
| System rules and examples | Every rule anyone adds | Prompt owner, versioned | prompting 02, 04 |
| Tool schemas | Every tool you expose | Router | llm-api 07 |
| Retrieved passages | k, chunk size | Retriever | rag 04, 08 |
| Conversation history | Every turn | Trimming and summaries | agents 04 |
| Working memory (facts) | The task, not the turns | Code | agents 04 |
| Tool results | What the tools return | Tool authors | llm-api 03 |
| The answer, and thinking | The task; thinking about 10x | Output cap | rnr 10, 03 |
Six moves that worked in the labs
- Calculate in code; send the result, not the raw data. rnr 12 summarised reviews three ways. "Stuff" (every review in one prompt) and map-reduce both broke on the 67-review product: the answer was cut off mid-JSON. "Grounded" (code counts the aspects, the model only writes) read about 700 tokens however many reviews a product had, and named the planted defect.
- Send fewer, better passages. 3 to 5 chunks, reranked, beat 20: long contexts bury the answer in the middle (rag 08, learn RAG section 4).
- Show only the tools for this request. Small models get confused past about ten tools; a cheap routing call first, then only that intent's tools (llm-api 07).
- Keep facts in typed state, and trim history. The latest quote and order live in working memory, filled by code from tool results and put in the system prompt every call, so trimming the history can't lose them (agents 04).
- One job per call. whatsapp-agent 08: one structured extraction call, then code, passed 25 of 25 golden cases
in our latest run; the agent that had to remember every step passed 16 (whatsapp-agent 08,
LABS-VERIFIED.md). - Put the stable part first. Rules and tool schemas that never change go at the start, so provider prompt caching and the gateway's response cache can reuse them (rnr 11).
Order inside a call: rules first; then facts and retrieved text; untrusted user text last, fenced in tags and called data; a one-line reminder of the rules after it (rnr 03, learn guardrails).
Long context, RAG or CAG?
| Option | Fits when | Breaks when |
|---|---|---|
| Put everything in (long context) | One document, read once (a contract, a call transcript) | It's sent on every call: cost and latency grow, the middle gets ignored |
| CAG (whole knowledge base in a cached prompt) | Small, stable reference data that fits easily | It changes often, or grows past the window |
| RAG (search, then send a few passages) | Large or changing documents, answers need citations | Questions need counting or joining across everything: use code or SQL (rag 12, rnr 14) |
In a review, ask for: the token budget per call at p50 and p95, broken down by the parts above; what is dropped first when it overflows; and which part grows with usage (history, reviews, tools). If nobody knows, the bill and the quality will both drift.
2. Frameworks: hand-rolled or LangGraph (and friends)¶
The course hand-rolls every pattern first, then rebuilds two in LangGraph: one agent (agents 07) and a multi-agent workflow (multi-agent 07). What that showed:
| A framework gave us | It did not give us |
|---|---|
| A checkpoint after every step, so a pause survives a restart | The model call, the tools or the prompts |
Pause and resume (interrupt()), history and replay |
Approval rules, budgets, retries |
| A graph you can draw and reason about | The checks: agents 07 needed the same goal check as the hand-rolled agent, added as a node |
| One shared way of building for the team | Correctness: "a framework organises the loop; it doesn't make it correct" |
In multi-agent 07, the stage functions, checks and policy didn't change at all when the plumbing moved to LangGraph. That is the split to aim for.
The landscape, by job. Names change fast; the jobs don't.
| Job | Examples | Course equivalent |
|---|---|---|
| Orchestration: steps, state, pauses | LangGraph, agent SDKs from model providers, PydanticAI, CrewAI | agent/, workflow/ (agents, multi-agent) |
| Data and retrieval plumbing | LlamaIndex, LangChain | rag.py |
| Gateway: providers, keys, budgets, fallbacks | LiteLLM | door/, ai/gateway.py (rnr 11) |
| Evals | promptfoo, DeepEval, Inspect AI, ragas | evals/ (rnr 05, 13; rag 09) |
| Guardrails | NeMo Guardrails, Guardrails AI | ai/guardrails.py (rnr 03) |
| Tracing | OpenTelemetry with Langfuse, Phoenix or LangSmith | obs/tracing.py (rnr 06) |
When to hand-roll, when to adopt
| Hand-roll | Adopt a framework |
|---|---|
| A single call, a chain, or one simple loop | Pauses that must survive restarts and deploys |
| You need to see and test every line (regulated flows, money) | Many branches, stages or agents |
| The team is still learning the pattern | Streaming per step, replay, forking a run |
| A few hundred lines would do | Several teams need one way of building |
Rules when you adopt one
- Keep business logic as plain functions you can test without the framework (multi-agent
test_workflow.pydoes). The framework owns order, state and pauses; nothing else. - Know its resume semantics. In LangGraph a node with
interrupt()runs again from the top on resume: a side effect above it (an email, an order) happens twice (agents 07, multi-agent 07). - Check that every model call still goes through your one door, or your traces and cost reports go blind.
- Pin exact versions and review upgrades. A gateway sees every prompt and every key; treat it as critical infrastructure (rnr FAQ, "Should we use LiteLLM").
- Price the exit: how much code would change if you dropped it next year?
3. When to fine-tune, and when not¶
Fine-tuning is further training on your own examples. It changes how a model behaves (format, style, a narrow task). It does not reliably add facts. Most teams that ask for it need one of the cheaper steps first.
Try these in order; move down only when the golden set says the step above isn't enough:
- A clearer prompt: definitions and rules (prompting 02).
- A schema for the shape, and checks in code for the meaning (prompting 03, rnr 02).
- One or two examples for a miss a rule can't fix (prompting 02).
- Give it the facts at question time: tools or RAG (llm-api, rag).
- Split the job: extract with the model, decide in code (whatsapp-agent 08).
- Thinking or a bigger model, only where it changes the answer: a cascade (rnr 10).
- Fine-tune.
Problem by problem
| The problem | Do this first | Fine-tune only if |
|---|---|---|
| It doesn't know our products, prices or policies | Tools or RAG. Facts change; a tuned model goes stale, can't cite, and can't "forget" a withdrawn policy | Never for facts |
| Wrong output format | A schema (structured output) | Never for format alone |
| Inconsistent labels on a narrow task | Better definitions and a golden set; a check in code | Volume is high, the task is stable, and the golden set still shows a gap after steps 1 to 6 |
| Too slow or costly at volume | A smaller model plus a cascade; caching | A small tuned model matches the big one on your golden set (distillation) |
| Search misses domain terms (steel grades, standard numbers) | Hybrid search with keywords (rag 05) | Fine-tune the embedding model, not the chat model |
| Tone or house style | Examples in the prompt | Hundreds of approved examples exist, and style matters at scale |
Before you approve a fine-tune, ask:
- Which slice of the golden set fails today, by how much, and what did steps 1 to 6 achieve?
- Do we have hundreds to thousands of labelled examples, and the right to use them? Customer data needs consent.
- Who retrains it when the base model is upgraded, and who re-runs every eval when they do?
- Where does it run? A custom model is a model you now host, monitor and pay for, and it misses the provider's upgrades.
LoRA and other PEFT methods make fine-tuning cheaper (a small add-on, not a full copy), but they don't change any of the questions above.
Check yourself¶
Answer each in a sentence or two, without looking. If one is hard, reread the section in brackets.
- A team's buyer assistant gets worse as conversations get longer, and the bill grows each month. What would you ask to see first? (section 1)
- Why did the grounded summary stay the same size as products got more reviews, while "stuff" broke? (section 1)
- A team proposes LangGraph for a two-step classify-then-reply flow. Would you approve it? What would change your answer? (section 2)
- In a framework with resumable pauses, where must an "send the quote email" step never go, and why? (section 2)
- A product team wants to fine-tune a model "so it knows our catalogue". What do you tell them, and what do you offer instead? (section 3)
Next¶
- System design section 2 is the review template; this page fills in three of its decisions.
- Each learn guide's "Decisions your team will face" table covers the rest, topic by topic.
- OWASP LLM Top 10 map for the security review.