The AI engineering stack map
When people say "AI engineering" they usually mean building reliable products on top of models someone else trained. The model is one box in the diagram, and most of the engineering happens around it: what you put into the context, which tools the model can call, how you check its output, and how the user experiences the wait. This doc is the map I draw on the whiteboard before anything else, and every other doc in this track zooms into one region of it.
Why it matters
Teams that skip the map tend to over-invest in the wrong layer. They spend weeks tuning a prompt when the real problem is that retrieval returns the wrong documents, or they switch providers when the actual issue is a missing timeout and retry policy. A shared picture of the layers gives you a vocabulary for debugging ("is this a context problem or a model problem?") and a checklist for production readiness.
It also helps with change. Models in 2026 turn over every few months. Frontier providers ship new versions with longer context windows, new reasoning controls and new pricing, and open-weight releases keep closing the gap. If your architecture isolates the model behind a thin interface, a model swap is a config change plus an eval run. If it does not, a model swap is a rewrite.
How it works
Think of a request flowing through six layers. The user interface collects input and renders a streaming response. An application layer decides what the request needs. A context layer assembles the tokens the model will see: instructions, retrieved documents, conversation history and tool definitions. The model layer is the API call itself, often behind a gateway that handles routing, retries and logging. A tools layer executes actions the model asks for. Around all of it sits an evaluation and observability layer that records what happened and scores whether it was good.
Rendering diagram…
The interesting property of this stack is that the model is stateless. Every call is a pure function from a list of tokens to a distribution over the next token, repeated until it stops. Everything that feels like memory, personality or skill is either baked into the weights or rebuilt into the context on every request. That is why so much of the work lives in the context layer.
Here is how the rest of the track maps onto the layers:
- Model layer: how LLMs generate text, tokenization and cost, reasoning models, choosing a model.
- Context layer: context windows and caching, embeddings, prompt patterns, multimodal inputs.
- Interface between model and code: structured outputs, tool calling.
- UX layer: streaming and UX patterns.
Reference architecture
A typical production request looks like this sequence. Notice that the model may be called more than once per user message, because tool use is a loop.
Rendering diagram…
Code
The single most useful abstraction early on is a thin wrapper that every model call goes through. It gives you one place for logging, cost tracking, timeouts and model swaps. Here is a minimal Python version using the Anthropic SDK.
import time
import anthropic
client = anthropic.Anthropic(timeout=60.0, max_retries=2)
def call_llm(messages, system="", model="claude-sonnet-4-6", max_tokens=1024, **kwargs):
started = time.perf_counter()
response = client.messages.create(
model=model,
system=system,
max_tokens=max_tokens,
messages=messages,
**kwargs,
)
elapsed_ms = (time.perf_counter() - started) * 1000
usage = response.usage
print({
"model": model,
"latency_ms": round(elapsed_ms),
"input_tokens": usage.input_tokens,
"output_tokens": usage.output_tokens,
"stop_reason": response.stop_reason,
})
return response
reply = call_llm([{"role": "user", "content": "Explain RAG in two sentences."}])
print(reply.content[0].text)
In a real system the print becomes a structured log or an OpenTelemetry span, and the model name comes from config so you can route per task.
Trade-offs and pitfalls
- Frameworks versus thin wrappers. Agent frameworks speed up prototypes but can hide the actual tokens sent to the model. I prefer starting with direct SDK calls and adopting a framework only when I can still see the raw request.
- Gateway versus direct calls. A gateway (self-built or a hosted one) centralizes keys, routing and fallbacks, but it is one more network hop and one more thing to keep available.
- Evaluation is a layer, not a phase. If you only evaluate before launch, you will not notice when a provider's model update shifts behavior. Log inputs and outputs from day one so you can build eval sets from real traffic.
- Statelessness cuts both ways. Rebuilding context on each call is expensive, but it also makes requests reproducible. Lean into it: store the exact context you sent.
- Over-indexing on the model. Most quality problems I have debugged were context problems: wrong documents, stale history, ambiguous instructions.
Checklist
- Every model call goes through one wrapper that logs model, tokens, latency and stop reason.
- Model names and parameters live in config, not scattered across the codebase.
- You can reconstruct the exact context sent for any logged request.
- Timeouts, retries and a fallback model are defined.
- There is a small eval set built from real or realistic inputs.
- The UI streams responses and handles errors mid-stream.