ludLLM · architecture
portfolio / LudLLM / architecture
// architecture

How a few sentences become a novel.

LudLLM expands a paragraph of premise into a full novel through a fixed chain of stages. The hard part is not the prose. It is holding two planes of knowledge apart (what the story knows versus what each character knows) so a secret survives 80,000 words and pays out on schedule.

LudLLM is an agentic pipeline that writes a full-length spy novel end to end. You give it a premise (a paragraph) and a secret spine (who hides what, and when the reader should learn it versus when the protagonist does). It expands that into a grounded world, a cast with private belief states, a narrative structure, a chapter outline, and then roughly forty chapters of prose. A human approves the plan one stage at a time. The models generate.

The whole project is a bet on one question: can a generate-plus-judge loop hold a secret across 80,000 words and stay coherent, without reading like a machine wrote it. Four finished books in, the answer is yes.

The core idea: two planes of knowledge

A spy novel lives or dies on dramatic irony. The reader knows the handler is lying; the protagonist does not. For that to work across a whole book, the system has to track two different things at once:

  • What is true in the story (the omniscient layer the author controls).
  • What each character believes (which is often wrong, and changes chapter to chapter as they learn).

LudLLM keeps these apart in a single validated state object. Every fact has an ID. Every character carries a belief set that points at those fact IDs, including deliberately false beliefs. A secret is a fact plus a binding that says which chapter reveals it to the reader and which chapter reveals it to a given character. Those two numbers are usually not the same, and that gap is the entire engine of suspense.

How a thin premise fills out

The expansion happens in a fixed chain of stages. Each one takes the state so far and adds a layer, then stops for a human to approve before the next one runs.

StageInputOutputWhat it adds
normalizeraw premise texta clean brieftidies the premise into structured intent, no invention
worldthe briefworld.md + secret ledgerthe plot mechanism, real-world grounding, an era timeline, and the tiered secrets with their reveal bindings
castworld + factscast.mdthe load-bearing roster, each character's belief state (including false beliefs), per-era beliefs, birth years
structureworld + caststructure.mdPOV strategy, time mode, the acts, the spy tropes in play, and which reveal lands in which act
outlineeverything aboveoutline.md + timeline.mdper-chapter POV, beats, hooks, the era and story-time of each chapter, and the reader-versus-POV asymmetry view
writerthe outline05_manuscript/the actual chapters, drafted, critiqued, and revised one at a time
dossierthe final bookclassified character filesper-character dossiers where the redactions are the reveals
vizthe final bookstudio.htmlthe interactive story-graph studio (see below)

Extra characters and plot points are not asked for up front. The world stage invents the plot mechanism and the secrets; the cast stage invents whoever the structure needs (an analyst, a cutout, a mole) and gives each one a belief state bound to real fact IDs. By the outline stage the thin premise has become a chapter-by-chapter plan with a tracked secret in every beat.

The spine versus the off-spine stages

normalize through outline are the spine: a linear chain where each stage produces authored intent that later stages depend on. The spine is what the critic scores and what downstream invalidation walks (regenerate the world and the outline goes stale). The writer consumes the spine.

dossier and viz are off-spine: they read the finished book and emit artifacts that nothing else reads. They have no rubric and are never invalidated. They are still mandatory, and they run last, after the manuscript is complete, because the chapter loop mutates state as it writes. Building them earlier would freeze a snapshot the writing then invalidates.

The state is one file, and it is the source of truth

Everything lives in book_state.json, a Pydantic-validated object. The markdown you read at each stage is a generated view of that JSON, never the other way around. An edit (move a reveal to chapter 8, cut a character) is reconciled into the JSON and the markdown is re-rendered. The schema splits cleanly into an authored half (world, facts, characters, structure, outline: the intent a human approves) and a running half (the chapters, belief updates, rolling summary: what the writer produces and mutates). Validation is the guardrail: an illegal hand-edit fails to load rather than corrupting a book silently.

It is deliberately not a graph database or a vector store. It is one JSON file with ID-linked relations traversed in Python. The knowledge graph is a computed view over those relations, not a thing that is stored.

The no-leak machinery

The hardest constraint is negative: the drafter must not write a fact the POV character does not yet know. LudLLM enforces this by denial by omission. When it assembles the context for a chapter, it computes the exact set of facts that chapter's POV is allowed to know at that story-time, and hands the drafter only those. The forbidden facts are never in the prompt, so they cannot be written.

After drafting, a deterministic guard scans the prose for exact mentions of any forbidden entity and raises if it finds one. Paraphrased or implied leaks (harder to catch by substring) are caught by the cross-family critic, which is told what the chapter is allowed to reveal and flags anything that runs ahead of schedule.

The hole in the logic is the honest one to name: the deterministic scan is exact-match, so a leak that never names the thing directly leans entirely on the critic. That is the known soft spot, and the reason the critic is a different model family (a second pair of eyes that did not write the prose).

The critic is always a different family

Every judging step uses a model from a different family than the one that wrote the thing being judged. Opus drafts and authors; Gemini critiques. This holds for both the per-chapter prose critic and the per-stage critique panel. A model is a poor judge of its own output; crossing the family line is the cheap structural fix.

RoleModel familyWhy
Drafter / authorClaude (Opus)strongest long-form prose
ExtractorClaude (Haiku)cheap, structured belief-update extraction
Critic (stage panel + prose)Geminicross-family, so it does not grade its own work

By default the Anthropic-family calls route through the local Claude Code subscription rather than the metered API. A full setup costs a few cents to under a dollar; a full book is roughly ten to forty dollars of generation.

The critique panel

Each setup stage is scored by a panel before a human ever sees it. The critic runs one call per rubric dimension (for the world stage: plausibility, grounding, coherence, originality, stakes and theme), each scored 1 to 5 with evidence and a concrete fix. The verdict (ship, tighten, or regenerate) is derived from the lowest dimension, not an average, so one weak axis cannot hide behind four strong ones.

The panel is advisory. It informs the human gate; it never replaces it. In the default mode, a non-ship verdict triggers an automatic regenerate-with-notes pass before the human sees the stage, but the human is still the one who approves. The showrunner's taste is the quality lever, and that is on purpose.

The temporal spine

Several of these books braid two timelines (a present-day hunt and a founding story two decades earlier). The state carries an explicit era model: each era has a year and a capability baseline (what technology and tradecraft existed then). A character's beliefs are ordered by story-time, not reading order, so a chapter set in the past renders the right state of knowledge even though the reader reaches it late. A deterministic anachronism scan backs this up, flagging period-wrong technology or place names in either direction, with the critic as the semantic backstop.

The story-graph studio

When the book is done, the viz stage builds a single self-contained studio.html: a read-only, model-free view of the final state that anyone can open in a browser. It is the asymmetry made literal. All the who-knew-what logic is precomputed in Python; the HTML only renders it.

It has two top-level tabs.

Story Graph

Knowledge as a graph over chapters. A slider moves the "current chapter," and the graph resolves every character's belief to their story-time state at that point. Three views:

ViewWhat it shows
Knowledgea swimlane per character; a dot marks the chapter each one learned a given fact; the reader's lane sits on top, so you can see the gap between what the reader knows and what each character knows
3-chapter windowa denser mesh of acquisitions, corrections, and inferred sources across a moving window
Propagationthe cascade view: how a single secret spreads from character to character over the book
Story Graph knowledge swimlane for Alpha V2
Story Graph, Knowledge swimlane (Alpha V2). The reader knows 23 facts; dots show where each character learned each one.
Story Graph propagation cascade for Alpha V2
Story Graph, Propagation cascade (Alpha V2).

A secrets panel underneath lists the reveals near the current chapter, marked hidden, delayed, or never-stated, so you can watch the ledger pay out as you drag the slider.

Dossiers

A card grid of the classified character files, each opening into an inline paginated viewer. The dossiers are written so that the redactions are themselves the reveals: what is blacked out for one reader is legible to another, depending on what they are cleared to know.

Dossiers tab for Alpha V2
Dossiers tab (Alpha V2): the classified character files.

Both studios are playable in the browser, on each novel's page: Alpha and Alpha V2.

What ships as samples

Two finished books are published with the engine as samples: Alpha (the first proof) and Alpha V2 (a re-imagining built on a single deliberate canon departure). Each ships as a bound PDF, a full plot synopsis, and its own interactive studio. The real novels driven through the pipeline stay private; only these two samples are public.

// palette