Module 027 min

How the model thinks

Not a database. Not a search engine. A very well-read autocomplete that is extraordinarily good at continuing a pattern — including the pattern of "a careful assistant solving a problem".

After this module
  • You can explain, without jargon, why a model can be fluent and wrong at the same time.
  • You know what fits in a context window, what a token is, and why the bill is measured in them.

Everything an AI agent does — every plan, every tool call, every apology — starts the same way: the model reads a sequence of text and predicts what should come next. One token at a time. Then that token becomes part of the input for the next prediction.

That's the whole engine. Everything else — reasoning, coding, tool use — is what happens when you give that prediction engine a very large amount of text to condition on, and train it on a great deal of human writing about thinking.

2.1Tokens: the unit of everything

Models don't read letters or words. They read tokens — chunks of text, usually 3–4 characters of English. "Agentic engineering" might be five tokens. A page of text is roughly 500–800 tokens. Every price, every context limit, every latency figure you'll ever see is denominated in them.

Try it · token estimator≈ 4 chars per token
Characters0
Approx. tokens0
Approx. pages0

Rule of thumb only. Real tokenisers split differently by language and by punctuation — code and JSON are usually more expensive per character than prose.

2.2Prediction, not retrieval

Ask a person "who wrote Dune?" and they retrieve a fact. Ask a model and it produces the most probable continuation of the text "who wrote Dune?" — which, having read an enormous amount about Dune, is usually "Frank Herbert". The answer is a reconstruction, not a lookup. That distinction explains almost every strange behavior you'll meet:

Why the same engine is brilliant on Tuesday and confidently wrong on Wednesday.
BehaviorWhat's actually happeningWhat to do about it
Invents a citationProduces the shape of a citation, because that's what the pattern looks likeGive it sources to quote; require links; verify
Knows nothing after its training cutoffNo mechanism to see new data unless text reaches the contextSearch tools, retrieval, or paste the document in
Answers a slightly different questionContinuation follows the most familiar pattern, not your intentRestate the goal as a checklist; ask it to echo the task first
Sounds certain when unsureConfidence is fluency. There is no internal "I don't know" flagAsk for evidence, or make the tool result the source of truth
NEXT-TOKEN PROBABILITY · ILLUSTRATIVE "The capital of France is ___" " Paris" 0.92 " Lyon" 0.02 " a" 0.01 " located" 0.008 PROBABILITY →
Sampling is the personality knob. At low temperature the model almost always takes the tallest bar. At high temperature it takes smaller ones more often — more variety, more mistakes.

2.3What training actually installs

Three stages, in plain terms:

  1. Pretraining. Read a large fraction of the public internet, books and code; learn to predict the next token. This is where knowledge and fluency come from. Extremely expensive, done once per model.
  2. Instruction tuning. Show it thousands of examples of "instruction → good response" so it behaves like an assistant rather than a document completer. This is where helpfulness comes from.
  3. Preference alignment. Humans (or another AI) rank pairs of answers; the model is nudged toward the preferred style, refusals and tone. This is where safe and pleasant come from — and where some of its evasiveness comes from too.

None of these stages install a database, a memory, or a guarantee. They install a prior — a strong tendency toward plausible, helpful-sounding text. Agents are built on top of that prior, which is why the harness matters more than the model.

The context window

The model's entire working memory on a given call. Everything it "knows" about your task must be inside it: instructions, conversation, retrieved documents, tool results, and room for the answer. Modern models range from tens of thousands to a million tokens. Bigger windows are useful, but they are not free — they cost money, add latency, and past a certain point, attention gets diluted. That problem gets its own module (05 · Context and memory).

2.4Reasoning models: thinking as extra compute

Since 2024, many models can spend tokens before answering — writing an internal reasoning trace, backtracking, checking itself. This is usually called test-time compute. It buys real improvements on multi-step problems (maths, planning, debugging), at the cost of latency and tokens.

For agents the practical implication is simple: match thinking budget to task difficulty. A routing decision ("is this a refund or a shipping question?") does not need a reasoning model. A migration plan for a production database does. Modules 06 and 09 turn this into a routing and cost strategy.

The trap

"It said so" is not evidence. The most expensive mistakes in agent systems come from treating fluent output as verified fact. Design so that facts arrive through tools and documents the model can quote, and make the model's own prose the commentary — never the source of truth.

Check yourselfQuestion 1 of 1

Your assistant keeps inventing plausible-sounding policy numbers. What is the most reliable fix?

60-second recap

  • One mechanism: predict the next token, append it, repeat. Fluent output is a property of the pattern, not proof of understanding.
  • Tokens are the currency — of context, cost and latency. Budget them like money, because they are.
  • Training installs a prior, not a database. Facts belong in the context, delivered by retrieval or tools, and verified outside the model.
  • Thinking costs tokens. Spend reasoning where the task is hard; don't pay for it on a routing decision.