The last lesson ended on a model that agreed, forgot and invented, and on the
idea that a prompt only asks. This lesson builds the thing that holds: a small
program around the model that keeps every number at the table and gives the
model one way to change it. It is the pattern every application that lets a
language model do something follows, from booking a train to running a
role-playing game, and this platform's table is built on it.
Two kinds of work
Kept by code
Done by the model
every die, rolled by the program
describing the world and the scene
each hero's bumpsBump (role-playing)A mark a hero at a children's table takes when a check fails and something could hurt them: a fall, a trap, a scuffle. After three bumps the hero is out of the scene, knocked out or captured, never killed, and back at the next scene with no bumps. or hit points
voicing every character from their card
whose turn it is, and the round
deciding when a check is needed, how hard, and which line of the sheet it uses
the scene the table is in
adapting the path to what the players do
The left column is the game stateGame state (role-playing)Everything at the table that is a number or a rule rather than words: the dice rolled, each hero's bumps or hit points, whose turn it is, the round and the scene.:
everything at the table that is a number or a rule. The right column is words.
The model reads the state in its prompt every turn, and it may change the
state in only one way: by asking.
Asking: a tool call
The program tells the model, with the prompt, which tools it has: each has
a name, a sentence saying what it does, and the inputs it takes. When the
model wants a roll, it does not write one. It writes a
tool callTool call (language model)A request a language model writes for a program to run, in a fixed form, instead of an answer: the program does the work, such as rolling a die, and sends the result back for the model to use. instead, a short
request in a fixed form, and stops:
roll_check character: "Mira" task: "climb the beam"
difficulty: "medium" modifier: "very good at"
The program reads the request, checks it against the rules, rolls the die
itself, changes the state, and sends the result back. Only then does the model
write the narration, from the result:
result: roll "d20 (14) + 3 = 17", target 15, success
model: Mira swings up onto the beam and looks out over the market...
The table sees both: the roll as code made it, and the words. A model that
writes a roll's number anyway, in so many words, is caught before the table
reads it, because code knows every face it rolled. The check is a word list, a
floor rather than a judgement: it catches what is written plainly, not every
paraphrase.
The program, in miniature
This is the core of the table's program, written small. The model's side is
only the request; everything else is code.
import random
DIFFICULTIES = {"easy": 10, "medium": 15, "hard": 20}
MODIFIERS = {"very good at": 3, "quite good at": 1, "everything else": 0}
def roll_check(table, request, rng):
"""Run the model's request in code: refuse it, or roll and change the state."""
hero = table["heroes"][request["character"]]
if request["difficulty"] not in DIFFICULTIES:
return {"error": "difficulty must be easy, medium or hard"} # nothing is rolled
face = rng.randint(1, 20) # the program's die, never the model's
total = face + MODIFIERS[request["modifier"]]
success = total >= DIFFICULTIES[request["difficulty"]]
if not success and request.get("can_hurt"):
hero["bumps"] += 1 # code changes the state
table["rolls"].append((request["character"], face, total, success))
return {"face": face, "total": total, "success": success}
def chance(modifier, difficulty):
"""The faces of a d20 that reach the difficulty, out of twenty."""
return sum(1 for face in range(1, 21) if face + modifier >= DIFFICULTIES[difficulty]) / 20
table = {"heroes": {"Mira": {"bumps": 0}, "Tom": {"bumps": 0}}, "rolls": []}
request = {"character": "Tom", "task": "lift the tree", "difficulty": "medium",
"modifier": "everything else", "can_hurt": True}
print(chance(0, "medium"), chance(3, "medium")) # 0.3 0.45
print(roll_check(table, {**request, "difficulty": "impossible"}, random.Random(1)))
# {'error': 'difficulty must be easy, medium or hard'}
The table plays one short sheetCharacter sheetThe page that holds a character: who they are and what they want, their six ability modifiers, their trained skills, their hit points and their defence. for every hero, the children's,
at both bands, not P94's abilities and skills (an adolescent table adds hit
points and damage dice to it): a hero is very good at one thing (+3), quite good
at another (+1), and everything else is +0. That is why a hero's
modifierModifier (role-playing)A number added to a die roll for one kind of attempt: positive for something a character does well, negative for something they do badly. here can differ from the one the same hero has in a P94 or
P95.npcs.01 example.
Tom, with nothing on his sheet for lifting, has a +0 against medium 15: he
needs 15 or more, 6 faces out of 20, a 30 % chance. Mira, very good at
climbing, has +3 and needs 12 or more: 9 faces, 45 %. Neither number is ever
written by the model. A request the rules do not allow, a difficulty called
"impossible", is refused and nothing is rolled: the model is told why and
asks again.
Why the split works
Each failure of the last lesson has a place to go. Inventing a roll is
caught, because the model never rolls; a number it writes anyway as a roll is
checked against the faces code rolled. Inventing a rule fails at the
tool, which refuses what the rules do not name. Agreeing loses most of
its power: the model can decide that a check is needed, but not that it
succeeds. It still names the difficulty and the sheet line, and code checks
only that both are ones the rules have, so a model that agrees too easily can
still ask for an easy check at +3. P95.npcs.02 closes that gap where it
matters most: for seeing through a character, code reads the line from the
hero's sheet itself.
Forgetting is helped too: the bumps and the turn are in the state, sent
every turn, not in the story the model has to remember.
ⓘ Concept: The same pattern, outside games
An assistant that books a train does not write "your seat is 42": it calls
the booking system's tool, and narrates the seat the system returns. A
coding assistant does not claim the tests pass: it runs them through a tool
and reads the result. The model chooses what to ask for and how to say
the answer; the program decides what is true. Whenever an answer must be
right, not merely plausible, it comes from code, and the model's words are
checked against it.
Why it matters — A learner who has seen it once at a table recognises it in any assistant that can act.
Your turn
The first rung asks who changes one number at the table. The second asks you
to write the two functions the program runs, the check and the turn, with the
program's dice passed in. The third asks you to design a new rule as a tool.
Ask the mentor about this module
Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.
Images, PDF or text. Kept on this device only.
Keeping your files on this device
Off by default. The mentor always gets your file; this only decides whether your own copy stays here. Copies live in this browser only - they do not follow you to another device, and clearing site data removes them.
Ctrl/Cmd + Enter to send
Rung 1 — code or the model?
Loading exercise…
Rung 2 — the dice and the turn, in code
Loading exercise…
Rung 3 — a new tool for the table
Loading exercise…
My notes on this module
Loading your notes...
Rules in code, words in the model: who rolls the dice — TransformerLab