---
title: "The AI engineering stack"
description: "The layers of an AI application, the order teams add them in, and which module of this course teaches each one."
canonical_url: "https://fanout.sh/ai-engineering/lessons/the-ai-engineering-stack"
md_url: "https://fanout.sh/ai-engineering/lessons/the-ai-engineering-stack.md"
last_updated: "2026-11-11"
access: "public"
---

# The AI engineering stack

The layers of an AI application, the order teams add them in, and which module of this course teaches each one.

An AI application is more than a call to a model. Around that call sit the parts that decide what the model sees, what it is allowed to do, and whether its answer was any good. This lesson names those parts, shows the order teams usually add them in, and points to the module of this course that teaches each one.

We will follow one example the whole way: a support bot for a printer company that answers customer questions from the product manuals. By the end you will be able to:

- name the six layers most AI applications grow into, and say what each one is for
- trace one question through them, from the customer's message to the logged answer
- tell which layers this course goes deep on, and which it only names

## The smallest version

Every AI application starts in the same place. Your code sends some text to a model, and the model sends text back.

This version runs, but it answers badly. The model has never read the A300 manual, so it either guesses or says it does not know. It will also answer questions about anything at all, and nobody can tell afterwards what it said or what it cost.

Each problem in that list is fixed by adding one layer. That is where the stack comes from: not from a diagram someone drew in advance, but from the fixes teams kept needing.

## Six layers, in the order a request meets them

Here is the whole support bot once it has grown up. The customer's question enters on the left and passes through each layer before the answer comes back.

1. Model access. The call itself. It starts as one provider's SDK and usually grows into a gateway: one place that holds the API keys, falls back to a second provider when the first is down, and tracks spend.
2. Context construction. Everything the model knows about your app has to arrive in the prompt. That means the instructions ("answer only from the manuals"), the conversation so far, and any facts you fetched for this question.
3. Retrieval. The step that fetches those facts. Before any customer arrives, a job splits the manuals into short passages and stores them so they can be searched. At question time, the app pulls the handful of passages closest to the question. This is what people mean by RAG, retrieval-augmented generation.
4. Tools and agents. Sometimes the answer is not in any document. "Has my order shipped?" needs a lookup in the order system. The model replies with a request to call get_order_status, your code runs it, and the result goes back to the model. When the model keeps choosing its next tool in a loop until the job is done, that loop is an agent.
5. Guardrails and caching. Checks and shortcuts wrapped around the call. Input checks catch personal data and off-topic requests before they reach the model. Output checks catch an answer that is badly formed or not backed by the manuals. A cache returns a stored answer when the same question comes in again, which saves time and money.
6. Evals and observability. A record of every step: what was retrieved, what the model said, how long it took, and how many tokens it used. Evals are the tests you run over those records to see whether a change made answers better or worse.

## One question, all the way through

A customer types: "Can the A300 do 100 pages per minute?" Here is what the grown-up bot does with it.

The input check finds no personal data and a small classifier labels it a product question, so it continues. The cache has never seen this exact question. Retrieval searches the manuals and returns five passages, one of them the A300 spec sheet listing 60 pages per minute.

The app builds the prompt from the fixed instructions, those five passages, and the question. It sends the prompt through the gateway to the model, which streams back: "No. The A300 is rated at 60 pages per minute." The output check confirms that 60 appears in a retrieved passage. The trace records every step with its timing and token count, and the customer sees the answer.

Nothing in that path was the model being clever. The right passage reached it, and the checks made sure it stuck to that passage.

Common misconception. Tools do not make the model do anything by itself. The model only writes out a request, such as a function name and its arguments. Your code decides whether to run it. That is why a tool that changes something, like issuing a refund, should wait for a person to approve it.

## The order teams add layers in

Teams rarely build all six on day one. A common path is: the bare call, then retrieval so answers use your data, then guardrails, then a gateway and routing to cheaper models, then a cache, and last, loops and tools that write. Anthropic's advice to agent builders is the same idea from another angle: find the simplest thing that works and add complexity only when it earns its place.

Evals are the exception. They start on day one, because without a record of what the bot said, you cannot tell whether the next layer helped.

One more thing sits under all six layers. Somewhere, GPUs turn your prompt into tokens, one at a time. With a hosted API you rent that work, but its speed and price still set the limits for everything above it: how long a prompt you can afford, how fast the first word appears, how many customers you can serve at once.

## Where this course goes

This course spends most of its time on retrieval and on that layer underneath, because that is where the numbers that shape your application come from.

| Stack layer | Where you learn it |
| --- | --- |
| Retrieval | Embeddings and retrieval, then the RAG lesson in LLM foundations |
| Model access, what one call does | LLM foundations |
| Speed and cost underneath | LLM internals, Transformer walkthrough, LLM optimizations, and Model tradeoffs |
| Tools and agents | Reasoning and verification, then MCP and agents |
| Context construction | Context engineering, in MCP and agents |
| Guardrails, evals, gateways | Named here; not yet a module |

The last row is a real gap, and a big one for anyone shipping a product. The books shelf lists two books that cover evals well, and the people on who to follow write about them every week.

Before any of that, the next lesson opens the model box and follows one call through it: what happens to your text between sending it and reading the answer.

## Lesson notes

---
This representation contains public Fanout content only. Protected Pro lessons, account data, billing, checkout, and pricing are not included.

Browse the public content map: https://fanout.sh/sitemap.md
