Session 02 · Tuesday 15 September 2026

How LLMs, agents and harnesses actually work

A teeny-tiny language model (TTLM)(TM)

16.S893AI Agents for Engineering Research
Today

Today

  • The model: build one small enough to see the structure
  • The model as a service
  • The harness
  • What follows for how you work
  • Go over portfolio slides briefly
Part 1

The model

Conceptual idea of next token prediction
The turbine blade failed because of thermal ▮
Each step is a probability distribution — off-topic words get almost none.
The whole definition

A language model is a function.

contextthe small cat saysa string of tokens
→
modela black box, for now
→
next tokenmeow 0.91a probability for every token

That is all of it.

TTLM · The teeny tiny language model

A tiny language to play with

Vocabulary: 16 words
Grammar of every sentence
the | a → ( adjective )* → animal → says → its sound → .
Held out, never shown in training
Training corpus: 48 sentences, seed
The dumbest language model

Count what follows what

P( next word | this word ) · counted from the corpus
rows: the word we are at · columns: what comes next · click a row
After “says”, the bigram predicts
—
The bigram sees one word of context. After “says” every animal looks the same to it.
The gap a bigram cannot close

To say the right sound, the model at “says” has to look back at the animal.
That looking back is attention.

Seven matrices (1,152 random numbers right now)

Everything the TTLM knows

positive negative near zero · every square is one parameter · untrained
click a cell
Detour · what an embedding is, for real

The dictionary, at full size

16 × 16
the TTLM's WE. Sixteen words, sixteen numbers each. Random right now.
50,257 × 768
GPT-2's WE, the real one, loaded in the demo. Same object, bigger.
directions
after training, directions in that space mean things. king − man + woman lands near queen.
Open the Geometry of Meaning ↗
Opens in a new tab. Presenter mode is top right. Come back here when done.
One head of attention, in words

One head of attention

What it means

Query is the question a word asks of the words before it. At says: “any animal in front of me?”

Key is each earlier word’s answer. Fit = query · key. Softmax turns the fits into weights that sum to 1.

Value is what a chosen word hands over. The blend is added to says; WUW_U reads the next word off it.

The arithmetic

qi=xiWQ,kj=xjWK,vj=xjWVq_i = x_i W_Q, \quad k_j = x_j W_K, \quad v_j = x_j W_V

Aij=softmaxj≤i ⁣(qi⋅kjdk)A_{ij} = \mathrm{softmax}_{j \le i}\!\left( \dfrac{q_i \cdot k_j}{\sqrt{d_k}} \right)

hi=xi+(∑j≤iAij vj)WOh_i = x_i + \Big(\sum_{j \le i} A_{ij}\, v_j\Big) W_O

p(next∣…)=softmax(hiWU)p(\text{next} \mid \ldots) = \mathrm{softmax}(h_i W_U)

Nobody writes the weights

Training, live

step0
loss—
floor—
params1,152
p( meow | the small cat says ) —
loss above the floor —
What did it learn to look at?

The attention lens

Each row is one word, and its cells show how much it looks at each earlier word. A row sums to 1. Grey cells are later words, which the model cannot see.
Reading row —
—
Next word predicted at that row
Where the words went

The dictionary organises itself

the 16 rows of WE, projected onto their two widest directions · trails = recent motion · click a word
step0
Closest to “cat” in all 16 dimensions
—
The same seven matrices, after

Nobody typed a number

positive negative near zero · every square is one parameter · untrained
click a cell
Ask it something it has never seen

Same toy, real bars

the ▮
temperature 1.00 the model's own bars
Same two moves as the first slide. This time every bar is computed by the model you just watched train.
Held out · never in the training set
From 1,152 to 10¹¹ parameters

Same machine, more numbers

What is the same
  • Context in, next-token distribution out
  • Predict, be scored, nudge the weights. Nobody writes them
  • Attention: each position reads from earlier ones
What we left out
  • Sub-word tokens, not words
  • Dozens of heads per layer, dozens of layers
  • An MLP after every block: 2/3 of GPT-3’s parameters
  • Post-training: a base model only completes text. The assistant, and the tool-call format, are trained in afterwards
The first of four words to pin down

Context window

In the TTLM
  • 8 positions. WposW_{pos} has eight rows, so a ninth word has no vector
  • Every call sees at most eight words, and nothing else
  • The model has no memory between calls. What it saw, it saw in the window
In a frontier model
  • Hundreds of thousands of tokens, for the same reason: the positions it was trained on
  • Still the whole world of one call: system prompt, your messages, tool results, its own replies
  • Fills up, is resent on every call, costs money by the token
Part 02 · About 10 minutes

The model as a service

Five calls, typed live

The entire interface, by hand

curl -s https://parley.api.mit.edu/v1/chat/completions \
  -H "Authorization: Bearer $PARLEY_API_KEY" \
  -H "Content-Type: application/json" \
  -d @1-duck.json | jq .
1-duck.json               # a list of messages in, one message out
2-name-alone.json         # "What is my name?"  It has no idea
3-name-with-history.json  # same question, earlier turns resent. Now it knows
4-tool-offer.json         # a tool on offer. It replies with a request to run it
ls . → 5-tool-result.json # we run the tool, send the result back. It answers
The hinge of the session

The model asks. It cannot act.
Whoever runs the tool and sends the transcript back is the harness.

Part 03 · About 20 minutes

The harness

Four words, pinned down

Four words to distinguish between

In the TTLMIn pi
Model1,152 numbers and a forward pass: context in, distribution outSonnet behind Parley: a few hundred billion numbers, same contract
Context window8 words, one per row of WposW_{pos}System prompt + AGENTS.md + your messages + every tool result + its own replies
HarnessThe Sample and Take-top buttons, and the temperature sliderpi: builds the context, calls the model, runs the tool it asked for, calls again
AgentThere is none. Nothing actsModel + harness + tools, running toward a goal. It can act
What pi sends before your first word

pi's system prompt, nearly whole

You are an expert coding assistant operating inside pi, a coding agent
harness. You help users by reading files, executing commands, editing
code, and writing new files.

Available tools:
- read: ...   - bash: ...   - edit: ...   - write: ...

Guidelines:
- Use bash for file operations like ls, rg, find
- Be concise in your responses
- Show file paths clearly when working with files

<project_context>  ...your AGENTS.md, verbatim...  </project_context>
<skills>           ...one line per skill it found...  </skills>
Current working directory: /Users/you/project
Everything the model saw, it saw in the context

What is in the context

  • The system prompt, and every AGENTS.md pi found on the way up
  • The list of skills, and any skill it loaded
  • Your messages
  • Every tool result, in full: every ls, every file, every test log
  • Its own earlier replies and tool calls
  • It fills up. It is resent on every call. And it never changes the weights.
Compound engineering

The model does not learn from its mistakes.
The agent can, if you write them down.

What follows for how you work

Three habits, starting now

  • Read what the harness sends. Open one of your session files this week. It is just JSON.
  • Know what a call costs. Tokens are the transcript times the number of calls, not what you typed.
  • A tool call is an action on your machine. Thursday: sandboxing, the lethal trifecta, nono.
Part 04 · About 30 minutes

Your portfolio sites

Every site, ~2 min

Show us

  • The site, and the thing that moves
  • One thing you asked the agent for and did not get
  • Any thing you had to fix yourself
  • Fail of the week.
  • The Easter egg, if you are willing
Before Thursday

Read

Simon Willison, How coding agents work. Ten minutes; it is today’s Part 3 in prose.

Do

Open one of your own pi sessions (ls ~/.pi/agent/sessions). Count the messages you typed and the tool calls the agent made. Two numbers, into your dev-log.

Project one-pager

Email me, cc your advisor, ask them to reply-all. Tuesday 22 September.

Next →
Back to course home