AI Fundamentals

What’s really happening under the hood — model weights, the prompt lifecycle, tokens, context windows, caching, attention falloff, and the layered persona-file mental model. Analogies carry the weight. Finish with a 10-question quiz.

Watch text become tokens

Press the button — a sentence tokenizes one chunk at a time…
Token chunkAlternatingThird color

The model never sees letters. It sees integers — one per chunk. Each maps to a vector of thousands of numbers in the embedding table.

1

Model Weights: What a Trained Model Actually Is

When you talk to an AI, what are you actually talking to? Not a database. Not a search engine. Something stranger: a huge pile of numbers — billions of them — called weights or parameters. That’s the whole model.

There is no separate library of training data the model retrieves from. The weights are the model. Training data shaped the weights, then was discarded. When you ask the model something, it isn’t looking anything up — it’s generating, token by token, from statistical patterns compressed into those billions of numbers. This is why models hallucinate: if patterns favor a plausible-sounding wrong answer, that’s what comes out.

Same container, radically different contents: untrained weights are noise, trained weights encode structured statistical patterns Untrained Model 1,000,000,000,000 parameters Same size. Radically different contents. Trained Model 1,000,000,000,000 parameters
A blank hard drive and one holding the Library of Congress are both one terabyte. One is noise; one is a library. Model weights work the same way — the structure inside is everything.

Training starts with billions of random numbers. The model is shown enormous text and asked to predict the next word. Every error nudges the weights toward what would have been correct. After trillions of nudges, weights encode statistical patterns about how language and ideas connect — not memorized facts, but compressed structure. The knowledge isn’t filed anywhere. It’s distributed across billions of parameters as a kind of compressed statistical shadow of everything the model saw.

Mental model to carry: AI models don’t look things up. They generate from compressed statistical patterns baked into billions of weights during training. The weights are the model — there is no separate stored knowledge underneath.

2

Ceiling vs Potential: Why Parameter Count Isn’t Everything

If two models each have a trillion parameters, do they have the same potential? True in a narrow sense. Misleading in the sense that actually matters: same parameter count means same ceiling — not same capability, not same potential, not same anything you care about in practice.

Parameter count tells you how big a brain you’re building. Training tells you what that brain learned. There is no untrained “potential” sitting underneath the weights, waiting to be unlocked. The weights are what training produced.

Same ceiling, different buildings underneath: parameter count is the ceiling, training fills it 1T parameter ceiling Claude 3 Opus (2024) Training data, compute, feedback 1T parameter ceiling Opus 5.5 (2026) +2 yrs data, compute, better recipes
Same ceiling. Different buildings underneath. The weights are what training produced — there’s no untrained potential waiting to be unlocked.
FactorWhat it controls
Parameter countMaximum ceiling — how much pattern can theoretically be encoded
Training data volumeHow much of the ceiling actually gets filled
Training data qualityWhether the filling is signal or noise
Compute + feedback recipeRLHF, constitutional AI, architectural refinements

Mental model to carry: A big brain that read nothing is useless. A small brain that read everything well is Haiku — fast, sharp, limited. A big brain that read everything well is a frontier model. Same parameter count ≠ same capability.

3

The Prompt Lifecycle: 8 Steps From Send to Reply

You send a message. Seconds later, a reply appears. It’s not one step — it’s eight. Every prompt goes through a context-assembly pipeline before it reaches the model, and the model generates one token at a time, not a whole reply at once.

The thing that most influences the outcome is not the raw intelligence of the model — it’s what’s in the scroll and in what order. The weights are fixed per model. The scroll is engineered every single turn. The scroll is where the real leverage lives.

The 8-step prompt lifecycle: from message arrives to token-by-token streaming reply, with tool-call pause and resume 1 Message arrives (Whisper if audio) 2 Scroll assembled System prompt Persona files Memory History User message 3 Tokenization text → integers 4 API call params + tool defs 5 Layer processing attention + FFN 6 Probability sample next token 7 Append + repeat this IS streaming 8 Tool call pause → execute → resume ↑ Step 2 is the structural backbone. What’s in the scroll + in what order drives the outcome. ← why you see words appear one at a time The scroll (step 2 in detail) — assembled fresh every turn: System prompt (defines AI + tool rules) ~2K tok Persona files: Soul, Identity, Agents, Memory ~10K tok Project context ~5K tok Conversation history ~15K tok Metadata: sender, channel, timestamp ~0.5K tok Your new message ~0.5K tok
The scroll is the full context assembled fresh every single turn. Steps 3–8 happen inside the model. Step 7 is why streaming works — tokens appear one at a time because they’re generated one at a time.

Six levers that influence the outcome

LeverImpact
System prompt + persona filesOutsized — frame everything below
Conversation historyRecent context biases next-token probabilities heavily
Position in scrollTop and bottom get more attention than the middle (Lesson 7)
Temperature + samplingLower = consistent; higher = creative
Tool definitionsShape what moves the AI knows it can make
Hidden parametersReasoning mode, thinking budget, model choice

Mental model to carry: A prompt doesn’t go straight to the model. It gets wrapped in a huge context scroll, tokenized, converted to vectors, pushed through layers against the weights, then sampled token by token. The scroll is where the real leverage lives.

4

The Tokenizer: Dumb-Fast Lookup

The tokenizer is the piece of the pipeline most people assume is complicated. It isn’t. A tokenizer is a dictionary plus a greedy matching algorithm. Not a neural network. Not AI. Just a lookup table with some matching logic.

A vocabulary of about 100,000 entries. Each entry maps a chunk of bytes to an integer ID. Common words = 1 token. Rare words = 2–3 tokens. Leading spaces are part of the token — "the" and " the" (with leading space) are different tokens. Emoji, punctuation, newlines each have their own ID.

Tokenization example: The Hard Thing About Hard Things split into integer token IDs, showing leading spaces as part of tokens and identical tokens reusing the same ID Sentence: "The Hard Thing About Hard Things" The ID 262 Hard ID 9937 Thing ID 12040 About ID 2769 Hard ID 9937 Things ID 11678 Same ID — identical tokens reuse the same integer BPE merge (how vocab is built): l + o → lo lo + v → lov lov + e → love Frequent pairs merge into single tokens. Frozen at training time. Note: leading space is inside the token box. " Hard" ≠ "Hard"
Each token ≈ 3–4 chars of English. Token IDs are illustrative. The tokenizer is deterministic: same text in, same tokens out, every time.

Live tokenizer — type text, see chunks and token count

Heuristic: ~4 chars per token for English. Color alternates per chunk. Leading spaces shown as ␣.

Why tokenization mattersPractical effect
Token count = cost and context budgetEvery API call charges per token in and out
Tokenization affects qualityRare words split weirdly; numbers often tokenize badly
Different languages have different densityChinese often 1 char/token; English ~4 chars/token
Tokenizer is deterministicSame text in = same tokens out, every time

Mental model to carry: The tokenizer is a dumb-fast lookup table that converts text to integers. The model only ever sees integers — it never saw a letter in its life. Change the tokenizer and you change the entire semantic world the model lives in.

5

Tokens & Context Window: The Scarce Resource

Two units measured in the same currency: a token is the atomic unit the model consumes and produces (~4 chars of English on average). The context window is the maximum number of tokens the model can hold in its scroll at once. The entire scroll — system prompt, persona files, conversation history, current message, generating reply — cannot exceed the context window.

Three things eat the window every turn: fixed overhead (system prompt + persona files + tool definitions), conversation history (grows over time), and the current exchange (your message + the generating reply + tool outputs). Tool outputs alone can be 2K+ tokens. Three tool calls in one turn can easily consume 6K of the window on results.

The 200K context window as a bucket: fixed overhead, conversation history, and tool outputs consume it, leaving working headroom 200,000 tokens Memory ~20K (could be 10K) History ~15K Working headroom ~135K Working headroom Every turn: Bucket refills from scratch. Then caching makes most of the fixed part free. (Lesson 6) System prompt ~5K Tool defs ~5K Persona files ~10K Memory ~20K (could be 10K) History ~15K Tool outputs ~10K Working headroom ~135K
Context window is a ceiling, not free space. Fill it up and either content gets truncated or quality degrades through lost-in-the-middle (Lesson 7).

Context budget visualizer — move the slider to simulate conversation length

System + tools (10K) Persona files (10K) Memory (var) Conversation Headroom

Lean files aren’t just about cost — they’re about signal-to-noise. Every token spent on bloat is a token not available for the model to attend to what matters. This is why disciplined operators cap MEMORY under ~10K and keep persona files tight.

Mental model to carry: Tokens are the atom. Context window is the maximum scroll size measured in tokens. Fixed overhead (persona + memory + tools) consumes window every single turn. Lean files preserve signal for the model to attend to.

6

Context Caching: Why Fixed Overhead Is Fine

Lesson 5 said: 15K of persona files eats budget on every single turn. Why doesn’t every long conversation cost a fortune? Answer: context caching.

Most of the scroll doesn’t change between turns. Soul, Identity, Memory, Tool definitions, System prompt — the first 15–20K tokens are literally identical turn after turn. Providers let you mark a prefix of your prompt as cacheable. They compute the expensive internal representation once, store it, and reuse it on subsequent turns. Massive cost and latency savings.

Context caching: frozen prefix computed once and reused each turn; live tail changes and grows System prompt Persona files Memory files Tool definitions History + message FROZEN PREFIX (cached) Computed once. Reused every turn. LIVE TAIL (fresh compute) Changes each turn. Paid in full. Cache economics (Anthropic): Cache write (1st turn): 1.25x normal rate Cache read (after): 0.10x normal rate ~90% cost reduction on fixed prefix Without cache (10 turns): 100% baseline cost With cache (10 turns): ~20% ~80% savings 5 consecutive turns: frozen turn 1 frozen turn 2 frozen turn 3 frozen turn 4 frozen turn 5 Frozen prefix reused unchanged. Live tail grows.
Cache invalidates at the first point of difference. Edit anything in the frozen prefix, cache busts from that point, next turn pays full rate. Batch persona file edits to avoid paying this penalty twice.

Latency benefit: Cache hits are ~3x faster to first token. For long persona setups this is the difference between 2 seconds and 7 seconds. Latency improvement is often more valuable than the cost savings.

Mental model to carry: The scroll has two parts: the frozen prefix and the live tail. Caching lets providers do the expensive work on the frozen prefix once and reuse it. "15K of persona files" sounds brutal, but after the first turn it costs almost nothing.

7

Lost in the Middle: Why Attention Fades

Models under-attend to information buried in the middle of long contexts. If a critical instruction is on page 50 of a 100-page scroll, it might get missed even when the model "sees" it. This is the lost-in-the-middle effect.

It is NOT a tokenizer bug or a context-window hard limit. It is a soft performance degradation that follows a predictable U-shape: recall is high at the start, high at the end, and dips in the middle. Two structural reasons: positional encodings (RoPE) get mathematically blurry at long distances, and training data favored examples where critical information was at the edges rather than buried in the middle.

U-shaped attention curve: model recall is high at start and end, dips in the under-attended middle zone Position of information in context (start → middle → end) Recall under-attended zone High recall Strong positional anchor at start High recall Fresh / near current moment Dip: position signals blur at long distances Soft curve, not sharp cliff. Content present — just under-weighted.
Liu et al. (Stanford, 2023) documented this U-shape. Frontier models like Claude 3+ have a flatter curve after targeted long-context training, but the effect is still real at very long contexts.

Attention curve — watch the dip widen as context grows

Interactive U-shaped attention curve: dip widens as context length increases from 2K to 200K Position (start → end)

Practical implicationAction
Critical persona/instruction contentPut near the top of the scroll
User’s current messageAlways at the bottom — fresh attention there
Mid-scroll instruction overridesRisky — often under-weighted vs top-level persona
"The model ignored my instruction"First hypothesis: was it buried mid-scroll?

Mental model to carry: Attention is biased toward the start and end of long contexts due to positional encoding degradation and training data distribution. The middle gets under-attended. Structure your scroll so critical content lives at the edges.

8

Persona Files as CSS: The Layered Override Model

If you’ve ever done CSS, you know the cascade. Global styles define the baseline. More-specific selectors override. Inline styles beat everything. Persona files for AI agents work almost exactly the same way — with one critical difference.

Behavior guidance for an AI is layered, with each layer having higher "specificity" than the one above. The analogy carries the full logical weight: more specific wins, later overrides earlier, everything cascades from a baseline. (Analogy originated by Andrew Eriksen in the source conversation.)

AI persona files as CSS cascade: five layers from platform guardrails to per-message override /* User-agent stylesheet */ OpenClaw system prompt + tool rules Never overridden by any layer below /* Global author CSS */ Persona files: Soul, Identity, Agents Sets baseline tone, voice, role — change rarely /* Theme file */ Memory files Accumulated durable preferences and learnings /* Page-specific CSS */ Conversation history This session only — ephemeral /* Inline style */ Current user message Highest specificity, lowest reusability Specificity up / Scope down Holds: layering, scope, override behavior Breaks: CSS deterministic, prompts probabilistic
The cascade model lets you decide WHERE to put any piece of guidance. One-offs go inline. Durable patterns get promoted to Memory. Foundational identity belongs in Soul/Identity.

Where the analogy holds

Soul/Identity = global stylesheet. Loads first, defines baseline tone/voice/role. Current prompt = inline style. "For this message, answer like a 5th-grade teacher" overrides the global default for this turn only. OpenClaw’s system prompt = user-agent stylesheet — can’t be overridden. "Can’t exfiltrate private data" is the browser’s own rule. Memory = theme file: accumulated patterns promoted from one-off overrides.

Where it breaks

CSS is deterministic. Prompts are probabilistic. If selector A beats selector B, A wins every time. But persona files don’t impose rules — they bias probabilities. "Be cold-eyed" shifts the probability distribution toward cold-eyed-adjacent words. Enough bias reliably produces the behavior. But there’s no cascade engine with a written spec. There’s no inspector showing you which rule won.

Guidance typeLayerChanges how often
Durable identity: role, tone, valuesSoul, IdentityRarely — change carefully
Operational rules + protocolsAgentsWhen protocols evolve
Accumulated preferencesMemoryWhen patterns emerge
Session-scoped contextConversation historyEphemeral, resets with session
One-off override for this messageCurrent promptHighest specificity, not reusable

CSS debugging lens: If you notice your agent drifting out of character, the first question is not "did the model get worse." It’s: did the scroll get polluted? Too much conversation context? Important instruction buried mid-scroll (Lesson 7)? Something in the current prompt accidentally overriding the global? Debug it like a CSS bug — the browser didn’t get stupid. Your specificity got weird.

Mental model to carry: AI behavior guidance layers like CSS: global baseline, scoped overrides, inline for one-offs, with increasing specificity. The analogy breaks on determinism but as a model for WHERE to put a given piece of guidance it’s sharp. When behavior drifts, debug it like a CSS bug.

Where to Go From Here

This module teaches concepts, not practices. You now have the mental model — the question is what to do with it. The natural follow-on is applied work: writing persona files, managing context budgets, and debugging scroll pollution when behavior drifts.

?

Quiz: Test Your Understanding

10 questions. Pass threshold: 7/10. Selecting an answer locks it and reveals the explanation. Score is saved to localStorage so you can come back later.

0 of 10 correct