xavier-ramirez.com
STAGE 0 · 1.2 · 3 NODES

One format, every turn

Last lesson, a single message became a role block wrapped in special tokens. Real conversations are messier — many turns, tool calls, step-by-step reasoning. The trick: all of it folds back into that same stack of role blocks the model was trained on.

THE 3 STEPS
01Stacking turns02Tool results fold in03The reasoning scratchpad
NODE 01 / 03

A conversation is just stacked blocks

The model has no memory. Each turn, the whole conversation is re-sent as role blocks — stacked oldest to newest — and the model writes the next one.

  • Every message is one role blocksystem, user, or assistant — wrapped in the special tokens from the last lesson.
  • The history is the input. Add a turn and the entire stack is sent again; nothing is remembered between calls.
  • The model always writes the last block — the open assistant turn at the bottom .
  • A longer chat is a taller stack, until it runs into the context limit.
FROM THE LAST LESSON
Same block, wrapped in special tokens
Each block is <|im_start|>role … <|im_end|> — the exact format the model was trained on. A whole conversation is just those blocks, in order.
THE TRANSCRIPT · stacked role blocks

Drag the turns slider — watch the same stack grow, block by block.

The model is stateless. To 'remember' turn 1, the app resends turn 1 — every single time you talk to it.

TRANSCRIPT
BLOCKS5 blocks
EST TOKENS~61 tokens
The whole stack is re-sent on every turn: how many role blocks it holds, and roughly how many tokens that is.
NODE 02 / 03

A tool result comes back as its own block

When the assistant needs live data, it writes a tool call instead of an answer. Your code runs the tool, and the result re-enters the stack as a new tool block — then the model reads everything again and answers.

  • The assistant emits a tool call instead of a final answer — still just text inside its block.
  • Your code runs the tool and appends the output as a tool role block.
  • The model re-reads the whole stack — now including the result — and writes the real answer.
  • Nothing new in the format — a tool result is just one more role block.
TOOL CALL · the result folds back in

Pick a tool — the call, the tool block, and the final answer all update together.

Weather — the model can't know live weather, so it calls a weather tool; the JSON result returns as a tool block.

NODE 03 / 03

Pre-fill `<think>` to make it reason

You can start the assistant's block for it. Pre-open the turn with a <think> tag and the model fills a private scratchpad — reasoning step by step — before it writes the answer.

  • The answer block is just text you can seed. Put <think> at its start and the model keeps going from there.
  • Inside <think> it reasons out loud — a scratchpad that's stripped away before you see the reply.
  • Then it writes the real answer after the scratchpad closes.
  • This is how reasoning models work — the same block format, one pre-filled tag.
ASSISTANT BLOCK · with and without a scratchpad

Turn the scratchpad on — the model thinks first, and catches the two-step discount.

Scratchpad off — the model answers immediately. On a two-step problem it can slip and say $26 (illustrative).

EXPLAIN IT BACK
Your chat app 'remembers' everything you said earlier — but the model is stateless. So where does the memory actually live?
NEXT · THE ATTENTION MECHANISM

The model reads this whole stack in a single pass — but how does it decide which earlier tokens matter for the next word? Next, attention: the step where every token weighs every other one.

Back: special tokensContinue to attention
Language: English