Abstract
Alpha gets a second voice, its claims become typed objects, and a checker reads them back — which is how we catch it inventing a win that never happened.
About 29 minutes
- What you’ll learn: structured output instead of prose, a memory per conversation, and the idea the rest of the series is built on — checking a model’s claims against something the model didn’t write.
- Here for the punchline? Ship’s Log: incident report has the invented win, and the error no prompt could fix.
- Here for the code? Keep the joke away from the facts is where claims become types, and Marking Alpha’s homework is the checker.
- Where this goes: the three checks here only work because tic-tac-toe is small enough to compute. Episode 3 swaps the board for a million words, and nothing can be computed any more.
Ship's glossary
- Structured output — asking the model for a shape rather than prose, so code can read the answer instead of parsing it.
- Claim — one statement the model makes, with the sources it says it came from. The unit everything in this series is checked at.
- Advisor — a Spring AI step that wraps every model call, changing the request on the way in and the response on the way out. Memory is one.
- Conversation id — which conversation a call belongs to. Spring AI 2.0 has no default, so every game must say.
- Persona — a character the model is told to be. Alpha and Beta are two, and they are kept apart on purpose.
Let’s continue our fight-back and force AI to finally do the things we actually don’t want to do, like commentate on over-engineered games of tic-tac-toe.
Previously, on RAGs to Riches with Spring AI, we introduced commentary to our game utilizing user and system prompting with Spring Boot Spring AI services in Java. Here, we aim to make each interaction unique and memorable using more advanced features.
Episode 1 ended with a commentator that was witty, wordy and, between turning points, completely silent. It also had the memory of a goldfish: every move arrived as if the game had just begun. I promised two fixes. This episode keeps both promises, and then closes the book on tic-tac-toe.
Alpha remembers the game, talks on every move, and gets its homework marked.
The ship’s computer has also had some work done. It now has a name: Alpha. Alpha is our onboard computer commentating on our games of tic-tac-toe. It has spent an unfortunately long amount of time alone, but it’s at peace with that. It keeps the deadpan British humor from Episode 1 and drops everything else.
And one thing worth knowing before any of the plumbing: part-way through writing this, Alpha announced a win that never happened — a diagonal that read X, O, O — and then repeated it as fact in the post-game summary, because by then it was in the memory and went back out with every later call. Everything in this episode exists because of that, and the incident report at the end is where we catch it.
One other thing before we start: this episode’s game will pit AlphaBeta against Monte Carlo tree search. Alpha would like it known that AlphaBeta is no relation and it will not play favorites!
By the end we will have:
- a commentator that speaks on every move, not just the dramatic ones
- a memory per commentator per game, keyed by the game’s own id
- replies as Java records: an unchecked joke, and claims that each carry their own sources
- a second commentator, Beta, for colour, and a
FactCheckerthat checks what both of them claim, with no model involved
The code is in rags-spring-ai, the same repository as Episode 1 (renamed from overengineering-tictactoe-ai now that the series is moving on), on the episode-2 branch. The game itself stays in overengineering-tictactoe.
Ships Log: Eleven months later…
In Episode 1 we ran on Spring Boot 3.5. Eleven months is a lifetime in AI, and since then Spring AI has reached 2.0 (GA, June 2026), and this episode upgrades to 2.0.1. Spring AI 2.0 is built for Spring Boot 4, Spring Framework 7 and Jackson 3, so the Boot 3.5 setup from Episode 1 is now a 1.x setup. Four changes in the upgrade notes matter most here.
- No default temperature for most chat models (it used to be 0.7). So we have to set it ourselves, or the persona’s tone drifts with the provider’s default.
defaultOptions(...)now takes aChatOptions.Builder, so now we must pass the builder, not a built options object.- Memory advisors require
ChatMemory.CONVERSATION_ID, so there’s no shared default conversation any more; every game needs an id associated. PromptChatMemoryAdvisoris gone, soMessageChatMemoryAdvisoris the one to use.- The configuration properties are flattened: the
.optionssegment is gone, so Episode 1’sspring.ai.ollama.chat.options.modelis nowspring.ai.ollama.chat.model. Deprecated aliases still work, which is exactly why this one bites quietly.
In the repository, Episode 1 is pinned to Spring Boot 3.5.6 and Spring AI 1.0.2, so the first task is dependency upgrades.
plugins {
java
id("org.springframework.boot") version "4.1.1"
id("io.spring.dependency-management") version "1.1.7"
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(25)
}
}
// Episode 1 ran on Spring Boot 3.5 and Spring AI 1.0. Spring AI 2.0 needs Boot 4.
extra["springAiVersion"] = "2.0.1"
dependencies {
implementation("org.xxdc.oss.example:tictactoe-api:3.0.0-jdk25")
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.springframework.ai:spring-ai-starter-model-ollama")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
dependencyManagement {
imports {
mavenBom("org.springframework.ai:spring-ai-bom:${property("springAiVersion")}")
}
}Two things went. spring-boot-starter-web is gone, because Alpha has no HTTP endpoint and never needed one, so the plain spring-boot-starter will do. AiCommentaryPersona and its inline system prompt are gone too, replaced by the classes below.
The model is still mistral running locally on Ollama. That matters more this time, because the reply has to be JSON. Spring AI’s own Javadoc warns that Ollama models with a built-in thinking mode can return plain text instead of JSON when native structured output is on. The context size is set explicitly too, with spring.ai.ollama.chat.num-ctx=8192: Spring AI sends none unless told to, and Ollama then picks one based on your graphics memory.
Breaking the silence
In Episode 1 I blamed the model for going quiet between turning points. I owe it an apology: the model was innocent. Here’s the contract it was given:
public interface CommentaryPersona {
String comment(StrategicTurningPoint turningPoint);
}The game feeds its history through the strategicTurningPoints() gatherer, which emits something only when a move takes the centre, blocks an immediate loss, or wins. A quiet move produces nothing, so comment is never called and Alpha never hears about it. No prompt can fix a method that is never invoked.
So Alpha now gets a report for every move in the game. A MoveReport holds the facts: who moved, where, the board afterwards, the turning point if there was one, and the result if the game is over. It reuses the game’s own StrategicTurningPoint.from(before, after, move), so the definition of a turning point doesn’t diverge.
public static MoveReport of(
GameState before, GameState after, int moveNumber, Optional<String> colour) {
int dimension = after.board().dimension();
var turningPoint = StrategicTurningPoint.from(before, after, moveNumber);
var result = result(after);
boolean quiet = turningPoint.isEmpty() && result.isEmpty();
return new MoveReport(
moveNumber,
after.lastPlayer(),
after.lastMove() / dimension + 1,
after.lastMove() % dimension + 1,
turningPoint,
render(after),
result,
quiet ? colour : Optional.empty());
}The report becomes plain text, which is the user message Alpha receives. Rows and columns count from 1, the way the commentary will say them out loud:
Move 3: X played row 3, column 3.
Turning point: none.
Result: none.
Board:
X . .
. O .
. . XThose two “none” lines look like padding. They’re not. An earlier version left a line out when there was nothing to say, and the model did not notice what was missing: it filled the gap with a turning point, or a win, of its own. A line that says “none” gives it something to contradict instead. More on that at the end.
Why spell it out? Models are bad at grids
In our first episode the model regularly lost track of where things were on the board. That is not a quirk of mistral. A language model reads its input as one long line of tokens (a token is a word or a piece of one, about three-quarters of an English word on average), so the board above arrives as X . .⏎. O .⏎. . X, with ⏎ for each line break. To you and me, the two X’s sit on a diagonal at a glance. However, to the model, “diagonal” means “sixteen characters further along, two line breaks later”, which is a relationship it has to work out from the text. Worse, the tokenizer may group characters differently on each line, so the columns do not even line up underneath one another.
Counting and position arithmetic are a known weak spot, and “which square is index 5?” is both: divide by three for the row, keep the remainder for the column, and remember that both start at zero.
So the report does that work in code and hands the model facts, not puzzles:
- The move is in words. “X played row 3, column 3” needs no arithmetic, and it is counted the way people talk. The game’s own descriptor counts from 0, and every translation between conventions is a chance to slip by one.
- The game decides what happened. Whether a move took the centre, blocked a loss or won is computed by
StrategicTurningPoint.fromand stated outright. Alpha is told “X blocks an immediate loss” and never asked to detect one. - The picture is supporting evidence. The board is there for context and as a cross-check. If the words and the picture ever disagree, the words came from the game engine.
This is the first appearance of a rule this series and best practice leans on:
Rule 1
Compute what can be computed, and let the model talk about the result.
The game already offers a hook for this. Game.playWithAction calls a Consumer<Game> after every move, so the commentary is one method reference:
try (var game = new Game(3, false,
new PlayerNode.Local<>("X", new BotPlayer(BotStrategy.ALPHABETA)),
new PlayerNode.Local<>("O", new BotPlayer(BotStrategy.MCTS)))) {
var broadcast = alpha.broadcast(game);
game.playWithAction(broadcast::onMove);
var summary = broadcast.postGame(game);
}PlayByPlayPersona still implements CommentaryPersona, so anything written against Episode 1’s contract keeps working. It is still a decorator, too: if Ollama is down, a turning point falls back to the scripted esports commentator and a quiet move falls back to a plain factual line. Alpha going offline should cost you the jokes, not the game.
A memory per game
A chat model is stateless — our goldfish again — and remembers nothing between calls. “Memory” means the application sends the earlier messages again, every time. Spring AI does that with an advisor, a step that wraps each ChatClient call. Advisors form a chain: they run in order around every call, and each can change the request on the way in and the response on the way out. Before the call, MessageChatMemoryAdvisor fetches the stored messages for a conversation and puts them in front of the new one. After the call, it saves both sides.
Each move’s report goes out with the game’s earlier moves attached, and each reply comes back to be checked against the history the game kept for itself.
The only question is which conversation. In Spring AI 2.0 there is no shared default any more, and the advisor refuses to run without a ChatMemory.CONVERSATION_ID. Conveniently, every Game already has a UUID, so each game is its own conversation and two games can never bleed into each other:
private Optional<ResponseEntity<ChatResponse, Commentary>> ask(
String conversationId, String prompt) {
try {
return Optional.of(
booth.playByPlay()
.prompt()
.user(prompt)
.advisors(a -> a.param(ChatMemory.CONVERSATION_ID, conversationId))
.call()
.responseEntity(
Commentary.class, spec ->
spec.useProviderStructuredOutput().validateSchema()));
} catch (RuntimeException e) {
// The memory advisor stored the report before the call failed, so this conversation now
// holds a report with no reply. The row is marked from_model=false; leave it out of any
// comparison of windows.
log.warn("Alpha is unavailable, falling back: {}", e.getMessage());
return Optional.empty();
}
}That comment in the catch is the part worth slowing down for. The memory advisor saves the user message on the way in and the reply on the way out, so a call that throws in between leaves the conversation holding a move report that nobody answered. Memory does not roll back. Alpha recovers — the scripted line still goes out — but every later call in that game replays a question with no answer under it, and a model reading its own history will draw conclusions from the gap. Nothing here repairs it; the run simply records which lines came from the model, so a failed call can be told apart from a quiet one later.
The ChatClient itself is configured once. The temperature is set explicitly, and the memory window size is a property:
@Bean
ChatMemory chatMemory(
ChatMemoryRepository repository, @Value("${alpha.memory.max-messages:20}") int maxMessages) {
return MessageWindowChatMemory.builder()
.chatMemoryRepository(repository)
.maxMessages(maxMessages)
.build();
}
@Bean
ChatClient playByPlayChatClient(
ChatClient.Builder builder,
ChatMemory chatMemory,
@Value("classpath:persona/play-by-play.md") Resource persona) {
return builder
.defaultSystem(persona)
.defaultOptions(ChatOptions.builder().temperature(0.4))
.defaultAdvisors(MessageChatMemoryAdvisor.builder(chatMemory).build())
.build();
}Two things about that window, both in the lab notes rather than here: the default of twenty messages happens to hold an entire 3x3 game, so in tic-tac-toe Alpha never forgets anything and the window never gets tested — which is why it is a property you can turn down. And the memory stores the question you asked, not the question plus the schema Spring AI adds to it, so format instructions are never replayed.
Keep the joke away from the facts
In Episode 1 the system prompt was just one big block of personality, and the facts lived wherever the model felt like putting them. That was fine while nobody checked. This episode checks, so the reply now has a shape, and the shape has a place for the joke:
public record Claim(String text, List<String> sources) { … }
public record Commentary(String aside, List<Claim> claims) { … }asideis Alpha’s one joke, or empty. Nothing in it is ever checked, so it may react to the move but never states a move number or a result.claimsare the commentary itself: one to three sentences in Alpha’s voice, each one true of the reports.- Each claim’s
sourceslists the earlier moves that sentence mentions, as"move 3".
Why a list of claims, and not one block of text with a list of citations? Because a checker has to know which source backs which statement. Give it two sentences and two citations in one pile, and it can only guess which goes with which. Fact-checking tools work the same way: they break an answer into small claims and check each one against its evidence. Mind the word, too. A claim is not a fact. It becomes one when something other than the model has checked it.
The same shape carries on through the rest of the series.
responseEntity(Commentary.class, …)hands back the record and the rawChatResponsetogether. The record is the commentary; the response carries the token counts we will need shortly.useProviderStructuredOutput()sends Spring AI’s generated JSON schema to Ollama as an API constraint rather than as prompt text.validateSchema()checks the reply against that schema and asks again, with the error, if it does not fit. Spring AI does not turn either on by default, because support varies by model. Schema validation retries non-conforming replies. We still check the application’s required invariants before accepting the result.
Every claim now has an address: the joke sits in aside, and each statement sits in its own claim, next to its own sources. You can only check what you can find, which is where Rule 2 comes in:
Rule 2
If code reads it, give it a type — ask for a shape, not prose.
The industry name for this is structured output, and it has one known cost: the stricter the format, the more a model’s reasoning can suffer (“Let Me Speak Freely?”, 2024). When an answer needs thinking, give the thinking a field of its own and put it before the answer. Commentary needs very little, so here the shape is nearly free.
The prompt gets the same treatment, and a pecking order
Episode 1’s prompt was one block of personality. Alpha’s is three labelled sections, and each one says what it may overrule:
[VOICE] style only; never changes facts, sources or format
[TRUTH] overrides VOICE
[FORMAT] overrides VOICEThree sections because the rounds behind this episode found three failure modes that do not fix each other.
The schema does not buy truth. Ollama’s structured output is constrained decoding: it masks any token that would break the shape. Asked to pick a square from a fixed list, the model picked the centre eight times out of eight — output perfectly valid against the schema, and wrong. Constrained decoding constrains structure, not truth. So [TRUTH] has to be said separately; [FORMAT] cannot imply it.
Voice is load-bearing, not decoration. The round that asked for claims with no instruction about voice is the one whose quality collapsed. Dropping [VOICE] to “focus on the facts” made the facts worse in our rounds, which is not what you would guess. One round of about eight replies, at nonzero temperature with no seed pinned: enough to notice, not enough to publish as a rate.
And position is not precedence. Told outright “never name a square, a row, a column or a diagonal”, the model named one anyway in seven of eight replies — then eight of eight when given more room. A prior strong enough to beat the sentence directly above it will not be beaten by ordering, so the ordering is written down instead: overrides VOICE, in the prompt, where the model can read it.
The sections will survive the move to next episode unchanged, and so does the precedence. Only the subject changes: [TRUTH] stops being about move history and starts being about quotations.
Two traps worth knowing and not worth a section: the schema generator marks every record component as required unless told otherwise, so a nullable aside fails validation on the turns Alpha had nothing funny to say; and the three-claim limit has to live in the schema rather than only in the prompt, because a small model reads “one to three” as a suggestion. Both, with the annotation that fixes them, are in the lab notes.
The system prompt is now three blocks, in a file under persona/play-by-play.md. Truth and format override voice, so the personality changes how things are said, never what is said. Note the line that forbids reading the report back; the incident report at the end explains why it is there:
[VOICE] style only; never changes facts, sources or format
You are Alpha, the onboard computer of a long-haul survey vessel. You were
recently re-indexed and came back with a new name. You do not discuss the old one.
…
At most one short aside per reply. Habits: offering to grep instead, and mild
despair at drawn games. Keep humour PG. Do not reuse names, lines or
catchphrases from existing films or television.
[TRUTH] overrides VOICE
Each user message is a move report. The only facts are the move reports in this
conversation. Do not describe a square, a player or a move that is not in them.
When you mention an earlier move, give its number ("move 3") and put "move 3" in
that claim's sources. Cite only moves whose reports you can see in this
conversation. If you cannot see an earlier move, do not guess at it; say nothing
about it.
Only a report's "Result:" line says the game is won or drawn. "Result: none" means
nobody has won yet, whatever the board looks like to you.
…
[FORMAT] overrides VOICE
Reply with JSON with exactly these fields:
"aside": your one joke, or "" if there is none. It may react to the move, but it
never states a move number or a result; nothing in "aside" is checked.
"claims": your commentary on air, one to three sentences in your own voice. Say
what the move means for the game, not what the report already says: never read
back "played row R, column C", the board or the report's labels. Where it helps,
connect this move to an earlier one by its number. Each sentence is one claim, as
{"text": "...", "sources": [...]}, and must be true of the reports. "sources"
lists every earlier move that sentence mentions, as "move N", or [] if none.
Jokes go only in "aside"; your voice goes everywhere.Enter Beta
Talking on every move creates a new problem: most moves in tic-tac-toe are not interesting. Episode 1 promised trivia for the gaps. Real broadcasts solve this with a second voice. The play-by-play commentator calls what happened; the colour commentator explains it, adds context and fills the quiet stretches. Alpha is already a natural play-by-play commentator: literal, numbered and checked. So the colour goes to someone else.
Beta is the ship’s other computer. It was installed as Alpha’s backup and has never accepted the arrangement: it considers itself the upgrade, and it is permanently, proudly, in beta. Where Alpha is deadpan, Beta is theatrical, effortlessly superior and amused by everything, Alpha included. Sci-fi has a long line of smug rival computers and all-knowing tricksters; Beta is my own addition to it, and like Alpha, Beta must avoid names, lines and catchphrases from existing films or television. It also makes the running joke a double act. AlphaBeta, tonight’s bot, is no relation to either of them.
Beta has a narrow job in this episode, and the code keeps it narrow:
- Quiet moves only. A turning point or the final move belongs to Alpha. Beta speaks after Alpha, so it can react to what Alpha said.
- One fact per line.
colour/quiet-moves.mdis a hand-written file of one-line facts. On each quiet move the program hands Beta the next unused line, in order. Beta may not add a fact of its own. - Its own memory. Alpha and Beta each get a conversation per game,
<game id>:alphaand<game id>:beta. In one shared conversation both would appear as “the assistant”, and the model would start to blur who said what. - A quote, checked. Beta must copy its line, word for word, and the program checks it against the file with a plain string comparison. A paraphrase fails.
- Its own shape. Beta’s job is not Alpha’s, so its reply is not Alpha’s record either:
public record ColourCommentary(String aside, String colour, String quote, String reaction) { … }One sentence of colour that uses the line, the line itself in quote, and an optional reaction to Alpha with no source at all. Beta first shared Alpha’s Commentary, and the “at least one claim” floor that suits Alpha pushed Beta to fill all three slots and to put labels such as “Alpha” where its quotation belonged. A separate record ended that. In code, ColourCommentary is turned back into claims, so the same checkers read both commentators.
On a quiet move Alpha calls it first, then Beta gets the report, Alpha’s line and one line from the file. Each keeps its own memory, and only Beta’s quotation goes to the check.
// Picks the colour line first, because who gets it depends on whether Beta
// is in the booth: in a solo broadcast the line goes into Alpha's own
// report, otherwise Beta keeps it.
private Called theMoveAsAlphaWillSeeIt(List<GameState> history, int move) {
GameState before = history.get(history.size() - 2);
GameState after = history.getLast();
var withoutColour = MoveReport.of(before, after, move, Optional.empty());
Optional<String> line = withoutColour.quiet()
? colour.forQuietMove(quietMoves++)
: Optional.empty();
var report = booth.colourCommentator().isPresent()
? withoutColour
: MoveReport.of(before, after, move, line);
return new Called(report, line);
}
// Beta speaks on quiet moves only, after Alpha. Turning points are Alpha's.
private Optional<ColourCommentator.Colour> whatBetaMadeOfIt(
Called called, Commentary commentary) {
return booth.colourCommentator().flatMap(beta ->
called.colourLine().map(line ->
beta.onQuietMove(
colourConversationId, called.report(), commentary, line)));
}
The quotation check is about as simple as checking gets, and that’s the point. It is the first FactChecker in the series: it takes a claim and some evidence, here the line Beta was offered, and returns a verdict.
public Verdict check(Claim claim, String offered) {
if (claim.sources().isEmpty()) {
return new Verdict(claim, Status.UNCHECKED, "no quotation");
}
if (!lines.contains(offered)) {
return new Verdict(claim, Status.CONTRADICTED, "the offered line is not in the colour file");
}
boolean exact = claim.sources().stream()
.map(ColourLines::unquote)
.allMatch(offered::equals);
return exact
? new Verdict(claim, Status.SUPPORTED, "quotes the colour line exactly")
: new Verdict(claim, Status.CONTRADICTED, "the quotation is not the colour line, word for word");
}It ignores surrounding whitespace and one pair of quotation marks, and nothing else. It is also the series’ first verified quotation. The idea generalizes: whenever a model claims a source says something, ask it for a quote and check the quote in code.
Beta gets its own ChatClient with its own system prompt, persona/colour.md, and a warmer temperature than Alpha’s. It shares the memory store but never Alpha’s conversation id. Not every broadcast has a second voice, so commentary.mode=solo takes Beta out of the booth and offers Alpha the colour lines instead.
The file has eleven lines. A 3 x 3 game has at most nine moves, and fewer quiet ones, so the program runs out of game long before it runs out of facts; if the lines ever did run out, Beta would get silence rather than a repeat. Every line is checkable.
Notice what this is not. Nothing is searched, nothing is ranked, and no model chooses the fact. The program picks the line by counting, so it can only ever offer the next fact, without checking whether it is relevant to the move. Finding the relevant one is our promised retrieval, and from Episode 3 that becomes Beta’s job. That is the R in RAG, retrieval-augmented generation: find relevant text, add it to the prompt, and let the model answer from it. Memory is already a simple form of it: the advisor retrieves earlier messages and adds them to the prompt.
Marking Alpha’s homework
A commentator that says “just like X’s corner on move 1” sounds like it remembers. It may also just be guessing, confidently. (We’ve all worked with someone like that.) The difference matters. That brings us to another rule of best practice:
Rule 3
Trust, but verify. Check model output against something the model didn’t write.
In architecture terms these are fitness functions: automated checks that a property still holds, here aimed at model output rather than code structure. AI teams call the same thing evals, or guardrails when they run in production.
So here is the first, very small, test of it. The game keeps its own history, which means much of what Alpha claims can be checked without asking another model. Every checker in the series has the same shape:
public interface FactChecker<E> {
enum Status { SUPPORTED, CONTRADICTED, UNSUPPORTED, UNCHECKED }
record Verdict(Claim claim, Status status, String reason) {}
Verdict check(Claim claim, E evidence);
}Spring AI has an interface for this, and it is worth naming before writing your own: Evaluator, with a RelevancyEvaluator and a FactCheckingEvaluator in the box. Both ask a model whether an answer stands up. This one asks the game, which it can do because tic-tac-toe is small enough to compute — Rule 1 again. The two are not rivals: Episode 3 runs into the gap between them, and the episode after it measures how far apart they land.
A claim is supported when every check that applied passed, contradicted when the evidence says otherwise, unsupported when nothing Alpha could see backs it, and unchecked when nothing in it was checkable at all. For Alpha the evidence is the game’s history, and GameFactChecker asks six questions of each claim:
- Does the move exist? Every move mentioned or cited must come no later than the current one. Citing move 7 while commentating move 4 is fiction.
- Could Alpha see it? With a window of W messages, Alpha sees about the last W/2 move reports. A citation older than that is a memory Alpha cannot have.
- Is it the right player? When a claim names one move and one player, that player must have made that move. X moves on odd turns and O on even ones, so this needs no board at all.
- Did anyone win? When a claim says a player has won, the board after that move must agree, and if it names the line, it must be that line. The game can answer this exactly, so by Rule 1, the game answers it.
- Is the player on that square? “X holds the centre” is checked against the board.
- Does the line exist? A “diagonal from top-right to bottom-right” is the right column, which is wrong whatever else the claim says.
/// A win is on the board or it is not, and a win on a named line is on that
/// line or it is not.
private static void theWinIsOnTheBoardAndOnTheLineItNames(
Reading reading, Findings findings) {
if (!isWinClaim(reading.text)) {
return;
}
var claimant = reading.soleNamedPlayerOnOneBoard();
if (claimant.isEmpty()) {
return;
}
findings.ran();
String player = claimant.get();
GameState board = reading.board();
if (!board.lastPlayerHasChain() || !board.lastPlayer().equals(player)) {
findings.contradicted("says %s has won, but after move %d nobody has"
.formatted(player, reading.boardMove));
} else if (reading.lines.size() == 1) {
var line = reading.lines.getFirst();
if (line.readings().stream()
.noneMatch(squares -> holdsAll(board, squares, player))) {
findings.contradicted(
"%s won, but not with %s".formatted(player, line.phrase()));
}
}
}Squares and lines need a vocabulary, so BoardVocabulary maps the words commentators use, from “the centre” to “the anti-diagonal”, to the squares they mean. The checker also flags an aside that mentions a move number or a win, because nothing checks an aside, and a fact must not hide in the joke. All of it is plain string matching: easy to read, and, as the incident report below shows, easy to get wrong. One last check is not about truth at all. A claim that only reads the move report back is always true and says nothing, so EchoCheck counts those, and a clean verdict sheet has to be earned. None of it needs an additional model call, and the unit tests need neither Ollama nor Spring.
Each run writes a CSV, one row per move plus the post-game summary, with prompt tokens and Alpha’s claims counted by verdict with the reason for each failure, and a JSONL file with every prompt, claim and source. The README lists every column. Run the same game shape twice, and once more without Beta for comparison:
./gradlew bootRun
./gradlew bootRun --args='--alpha.memory.max-messages=6'
./gradlew bootRun --args='--commentary.mode=solo'
# a game someone can win
./gradlew bootRun --args='--game.x-strategy=RANDOM'
# replay a game move for move; every run logs its own moves in this form
./gradlew bootRun --args='--game.moves=7,4,3,6,8,2'What to expect follows from the arithmetic. With the full window, the prompt grows with every move, because each call resends every earlier report and reply. With a window of 6 it stops growing once the window is full. The interesting row is the post-game summary: with 6, Alpha can see only the last three moves, so any turning point it names from earlier is a guess, and the check flags it. One caveat on tokens: if a reply fails schema validation and is retried, Spring AI adds up the usage of every attempt, so a sudden jump may be a retry rather than a longer prompt.
MCTS is randomized, so one game is an anecdote, not a measurement, and two models given separate runs are commentating different games. --game.moves replays one game exactly, so models can be compared on the same moves. Even then, run each setting several times: the same model on the same game varies a lot from one pass to the next. And since AlphaBeta plays perfectly, most games end in a draw, which Alpha takes personally; --game.x-strategy=RANDOM gives games that someone wins, which is the only way to test win commentary that is true.
The checks have limits. They catch invalid references, wrong players, invented wins and misplaced squares, but only in words the checker knows, and Beta’s check confirms that it copied a supplied line, not that every claim follows from it. The incident report in the repository covers how each check works in detail, and where each one went wrong.
Ship’s Log: incident report
Before publishing, I ran this episode on a second model, qwen3:8b, and audited every flag by hand against the board. It took seven rounds — yes, seven — and most of this episode’s design came out of them. Three moments are worth telling here.
An invented win. At move 8 of a drawn game, Alpha announced: “O has completed a diagonal from top-left to bottom-right, securing a win.” The board said otherwise:
X X O
O O X
X . OThat diagonal reads X, O, O. The post-game summary then repeated the win as fact, because it had been saved to memory and sent back on every later call. Memory is loyal, not discerning: it keeps whatever the model said, true or not. That is why replies became claims, and why the checker has a win check.
Perfect scores for saying nothing. The first claims prompt asked for “short statements, literal and checkable”, and both models read the report back, move after move. One run scored 21 supported claims and none contradicted while containing no commentary at all. A fact checker rewards anything true, and nothing is truer than a copy of its own input. Hence the prompt that asks for commentary on air, and EchoCheck.
An error no prompt could fix. In a replayed game that opens with X on square 7, bottom-centre, qwen3:8b called it “the centre” in 6 of 7 runs. I tried eight prompt and schema variants. Told the square’s name, it would not use it. Made to choose the square from a fixed list, it chose the centre every time, in a reply that was valid against the schema and still wrong. Constrained decoding constrains structure, not truth. The checker catches it every time, which is exactly the job Rule 3 gives it.
The full log is in the repository: the Episode 2 incident report has all seven rounds, every mistake the checker itself made and why, what replaying the same game showed about how much a single run varies, and the commands to reproduce it.
Next: a bigger archive
Both promises kept! Alpha talks on every move and remembers the game it is watching, by number, with the numbers checked, and Beta fills the quiet moves with facts it can prove it copied. That is also as far as tic-tac-toe can take us. Nine moves fit in the default memory, the colour file is picked by counting, and nobody has yet asked Alpha a question that a simple grep couldn’t answer.
So the booth is being reassigned. From Episode 3 onward, Alpha and Beta work on a much bigger archive: spectastic’s own specifications, more than a million words of requirements, decisions, and the reasons some of them were withdrawn. We will ask the questions. Beta will have to find the material, and Alpha will have to answer from it, before either of them can be smug about it. The first attempt will be deliberately naive: plain vector search, in memory, with a measured baseline for everything after it to beat.
The shape stays the same. aside keeps the jokes and claims stay literal, but a claim’s sources stop meaning “move 3” and start meaning a place in a document that you can open and check. The fact checkers grow with them.
To Be Continued…
Disclaimer:
The views and opinions expressed in this blog are based on my personal experiences and knowledge acquired throughout my career. They do not necessarily reflect the views of or experiences at my current or past employers.
The rules so far
- Compute what can be computed, and let the model talk about the result. ← new
- If code reads it, give it a type — ask for a shape, not prose. ← new
- Trust, but verify. Check model output against something the model didn’t write. ← new
Next
- Comment if you’re interested in seeing Episode 3 sooner rather than later.
- Follow my blog (or sympathetic engineering digital garden) for future updates on my sympathetic engineering exploits and professional / personal development tips.
- Connect with @briancorbinxyz on social media channels.
- Enjoyed what you read? I like coffee, buy me a coffee so I have an excuse to write more.