AI Agentic Handbook
Volume I

LLM Foundations

What a language model is, how it is trained, and what actually happens when it answers.

Sections

Interview questions answered at staff level

01

How LLMs work

Tokens, transformers, prompting and why models make things up.

10 questions
02

Training, tuning & inference

Pretraining, fine-tuning, RLHF, and the economics of serving a model.

10 questions

Read first

Blog posts for this volume, easiest first

What happens when you ask an AI a question

From pressing enter to the last word: tokens, the desk the model reads from, one-token-at-a-time writing, thinking, web search, and where your words go.

The three dials: tokens, temperature and context

Two bugs show up in nearly every first LLM integration. Both trace back to the same three settings, and both are fixable in a few lines of code.

Prompt, retrieve or fine-tune? A decision guide

Diagnose the failure first, then pick the technique. A worked claims-triage case shows where fine-tuning pays in 2026: cost, not knowledge.

The real cost of an LLM feature: latency, tokens and the bill

Five terms make up the bill and two make up the wait. Reasoning tokens, cache writes, batch discounts and the self-host break-even, worked with stated assumptions.

Thinking models, explained without the hype

What a reasoning model does with its extra time, why the same question can cost ten times more and take forty seconds longer, and a simple rule for when that is worth it.

Structured outputs that don't break

Getting JSON out of a model is easy; getting JSON your code can trust on every call is a system. Schemas, provider structured-output modes versus prompting, validation with targeted retries, and rendering partial JSON while it streams.

Self-host or API? A break-even memo with the maths shown

A decision memo for serving Open-weights vs closed models models yourself versus paying per token, with every price, throughput and headcount stated as an assumption, a cost-versus-volume curve, and a calculator you can rerun with your own numbers.

Key terms

44 pages with diagrams and quizzes

Large Language Model (LLM)Budding

A program that has read a staggering amount of text and learned one trick very well: guess what comes next. Chat, agents and search all run on that trick.

TokenBudding

The bite-sized chunk of text a model reads and writes — usually a word or part of one. Length limits, speed and price are all counted in tokens.

Context windowBudding

How much text a model can hold in one go — instructions, chat, documents and the answer, all together. Outside the window, it does not exist for the model.

Prompt & system promptBudding

Everything you send the model in one request: the instructions, the examples, the documents and the user's question. Your main steering wheel.

Parametric knowledgeMid

The facts a model soaked up during training and stores inside its own numbers. Broad, instant, and frozen on the day training stopped.

HallucinationBudding

When a model says something fluent, confident and simply not true — in the same tone it uses when it is right, which is what makes it tricky.

Fine-tuningMid

Training an existing model a little further on your own examples, so it picks up your format, tone or task. Lovely for style, poor for facts.

Retrieval-Augmented Generation (RAG)Budding

Search first, then answer: find the documents that matter, paste them into the prompt, and ask the model to answer from them — with citations.

CorpusBudding

The whole pile of documents your search can see. If something is not in there, no answer will ever mention it.

AttentionMid

How a model works out which earlier words matter for the word it is writing right now.

Prompt cachingMid

Reusing the work already done on a prompt's repeated opening, so the next request that starts the same way is cheaper and faster.

Structured output / decodingSenior

Forcing the model to produce output that fits your format — valid JSON every time — by blocking any next token that would break it.

Model distillationSenior

Training a small, cheap model to copy a big model's answers on your task. Most of the quality, a fraction of the bill.

Multimodal & vision modelsMid

Models that take in more than words — photos, scanned PDFs, charts, audio, video — and reason about them alongside your text.

Text-to-SQLSenior

Someone asks in plain words, the model writes the database query, the system runs it safely and turns the result into an answer.

Agentic RAGSenior

Retrieval where the model decides what to look up, where, and whether to search again — a short loop instead of one fixed search.

LLM-as-judgeSenior

Using a model with a clear marking scheme to grade your AI's answers, so a test run can cover hundreds of cases instead of five.

Neural networkBudding

A program that learns a pattern from examples instead of being given rules. The machinery under every model on this site.

Parameters & weightsBudding

The learned numbers inside a model. '70B' means 70 billion of them — which sets memory and cost, and on its own says little about quality.

TransformerBudding

The design inside nearly every modern model: stacked layers where each word gathers context from the others, then refines itself.

PretrainingBudding

The first and most expensive training stage, where a model learns language and world knowledge by guessing the next word, trillions of times.

Next-token predictionBudding

The one task a model is trained on and runs every time it answers: given the text so far, score every possible next token.

Training dataBudding

The text, code and examples a model learned from. Its mix, quality, recency and licensing decide what the model knows and how it behaves.

Scaling lawsMid

The measured pattern that error falls predictably as parameters, data and compute grow — with each step costing many times more than the last.

Instruction tuningMid

Training a base model on pairs of 'instruction' and 'good response', which turns a text continuer into something that answers you.

RLHF (reinforcement learning from human feedback)Mid

Training on human preferences: people pick the better of two answers, those picks train a scoring model, and the model learns to score well.

Preference optimization (DPO)Senior

Methods like DPO that train straight from 'chosen vs rejected' answer pairs — RLHF-like results without the reward model or the RL loop.

LoRA & parameter-efficient fine-tuningMid

Fine-tune by training a small add-on while the original weights stay frozen. Cheap, fast, and swappable per task or customer.

In-context learningBudding

A model picking up a task purely from the instructions and examples in your prompt, with nothing about it changed.

Few-shot promptingBudding

Showing the model a handful of worked examples in the prompt so it copies the format, labels and tone you want.

Chain-of-thoughtMid

Having the model write its working before the answer. Better on multi-step problems, paid for in tokens.

Reasoning models & extended thinkingMid

Models trained to think at length before answering: much better at hard maths, code and planning, slower and pricier per answer.

Temperature & samplingBudding

The dial between predictable and adventurous when the model picks its next word. It changes variety, not knowledge.

Top-p (nucleus) samplingMid

Sample only from the smallest group of likely words that together cover p of the probability — 90%, say — and ignore the weird tail.

Logits & probabilitiesMid

The raw scores a model gives every possible next word, before they are turned into probabilities.

InferenceBudding

Running a trained model to get output. Training happens occasionally; this happens on every single request.

KV cacheMid

The saved intermediate results for earlier words, so each new word doesn't re-read the whole conversation. It eats GPU memory.

Model quantizationMid

Storing a model's weights in 8 or 4 bits instead of 16, to cut memory and speed things up — at a quality cost you have to measure.

Time to first token (TTFT)Mid

How long the user waits before any words appear. With streaming, this is what 'fast' actually means to them.

Batching & throughputSenior

Running many requests through the GPU together, so one read of the weights serves lots of tokens. More throughput, slightly slower per stream.

Speculative decodingSenior

A small model guesses the next few words and the big model checks them all in one pass. Same output, fewer slow steps.

Mixture of experts (MoE)Senior

A model made of many sub-networks where each word only uses a few, so a huge model computes like a much smaller one.

Open-weights vs closed modelsMid

Models whose trained numbers you can download and run yourself. Closed models live behind an API. You are trading control for convenience.

Knowledge cutoffBudding

The date a model's training data stops. Anything after it is unknown — and the model usually doesn't realise that.