Primer

Volume I · 00 · The stack

Volume I · LLMs

How a language model thinks — and how engineers wire it.

A language model is a next-token engine. Everything useful around it — tools, memory, loops, graphs, evals — is engineering. The KV cache is why the next token is cheap.

In English

A language model only does one job: guess the next piece of text. Agents, tools, memory, and loops are software wrapped around that guess. This volume walks the wrap, from the first token to the product.

Try this
Click Tokens if you have never seen a tokenizer. Skip to The harness if you already know attention and want the engineering.
Keep this
The model predicts tokens. The harness is the product.

The stack · click a layer

  1. 09The harness
  2. 08Graphs
  3. 07The loop
  4. 06Tools
  5. 05Retrieval
  6. 04Context
  7. 03Cache
  8. 02Attention
  9. 01Tokens

What this is

Interactive diagrams, not a blog. Tokenize a sentence, sample at different temperatures, watch attention move, reuse a KV cache, overflow a context window, step a tool call, run a loop, take a branch in a graph, and explode the harness around the model.

What this is not

Not a live model. Distributions and attention maps are teaching fixtures with the right shape. The claims about architecture are the real ones: next-token prediction, the loop, and the harness as the product.

  1. 01 · The modelTokensChop text into pieces. Sample the next one.Text in → tokens → a bet on the next token. That is generation.
  2. 02 · The modelAttentionClick a token. Watch it look around.Attention is weighted looking. A transformer is that, stacked.
  3. 03 · The modelCachePrefill once. Decode cheap. Break the prefix.Prefill is time-to-first-token. Decode is tokens-per-second. Similar prefixes do not count.
  4. 04 · The windowContextFill the window. Watch it overflow.If it is not in the window, it does not exist for this call.
  5. 05 · The windowRetrievalQuery a corpus. Stuff the prompt.Weights are memory of training. RAG is memory of now, stuffed into the prompt.
  6. 06 · The runtimeToolsEmit a call. Execute it. Read the result.Tools are hands. The model only names the hand; the harness moves it.
  7. 07 · The runtimeThe loopStep an agent through think → tool → observe.An agent is a while-loop around a next-token engine.
  8. 08 · Control flowGraphsRun a branching agent graph.Graphs are loops with names, branches, and a save file.
  9. 09 · The systemThe harnessExplode the architecture around the model.The model is the engine. The harness is the car.