Memory · Free preview

A Working Scratchpad

Think on paper

Working memory is a scratchpad the agent writes intermediate results to and reads back, so a multi-step task becomes a chain of small, recoverable steps instead of one opaque leap you can neither check nor retry.

Think on paper

Ask an agent to do a multi-step task in one shot — "compute the tax, apply the discount, then split three ways" — and it will often hand you a single confident number that's quietly wrong. You can't see where it went off the rails, because there are no rails: the whole computation happened invisibly inside one model call. There's nothing to inspect, nothing to retry, nothing to trust.

In the last lesson you fit a conversation onto the finite desk. Working memory is what you do with that desk during a single task: a scratchpad the agent writes each intermediate result to, then reads back for the next step. The intuition is the same one that makes you do long division on paper instead of in your head — each step becomes small, named, and visible, so a slip shows up at the exact line it happened. The agent stops making one opaque leap and starts leaving a trace.

Take (a + b) * c with a=7, b=3, c=4. Instead of emitting 40 and hoping, the agent writes scratchpad.sum = 10, logs it, then reads that back to compute scratchpad.product = 40, logs that, and reports the last value on the pad as the answer. If the product had come out as 30, you'd instantly see sum was fine and the multiply was the bug — diagnosis without re-running anything.

This matters because real agent tasks are long chains — search, then parse, then decide — and a chain with no intermediate state can only fail as a black box. A scratchpad turns failures into located failures, and lets a step re-run from the last good value instead of from scratch.

Here the task is (a + b) * c. The starter cheats and jumps straight to the answer, so there's no trace to trust. Rewrite it to write the sum to scratchpad.sum and log it, read it back to compute scratchpad.product and log that, then report the product as the answer. Done means all three lines appear, in order, each value read from the pad rather than recomputed inline.

The scratchpad isn't extra work — it's what turns one impossible leap into a chain of steps you can check, retry, and build on.

In the full academy, you write and run this — live, graded:

// Compute (a + b) * c — but show your work on a scratchpad.
const a = 7, b = 3, c = 4;

// A blank scratchpad: the agent's working memory for this one task.
const scratchpad = {};

// 🚫 Right now the agent leaps straight to the answer in one shot —
// no intermediate steps are recorded, so the trace can't be checked.
const answer = (a + b) * c;

// TODO: instead, WRITE each intermediate result to the scratchpad and
// READ it back for the next step:
//   1. scratchpad.sum = a + b;        then log: scratchpad.sum = <value>
//   2. scratchpad.product = scratchpad.sum * c;  then log that write
//   3. log: answer: <scratchpad.product>

console.log(`answer: ${answer}`);

🔒 Live code execution, real agent runs, mastery tracking and verifiable credentials unlock with the full academy.

This is 1 of 50 lessons.

The full academy: write real code, watch real agents run, and earn verifiable credentials — across 8 tracks, in a 3D campus.

Unlock the full academy — $100 →

14-day refund · 🔒 Stripe-secured checkout · lifetime access

More free lessons: An LLM Is a Function  ·  The Agent Loop  ·  Define a Tool  ·  Give an Agent a Tool  ·  Durable State

← The Agent Marketplace