I've been building an AI-powered interactive fiction engine called [Wagtales](https://wagtales.app) and have posted already a couple of times while we are in beta. As a content creator, Wagtales gives you the opportunity to create limitless, unique, and engaging stories from your ideas. The characters you write, the world you describe, the secrets you bury — all of it becomes the raw material for stories that play out differently every time. This is a long post, aimed at writers who are curious about the machinery behind our dynamic storytelling. I also want to go into the detail of how stories actually work when you're reading one. --- ## Overview Every story in Wagtales is a living world including characters, locations, events, your inventory, the time of day, NPC relationships, emotional state, all of it tracked and simulated as you play. When you take an action, the engine works out what changed, then hands everything to an AI model with a simple brief: *"Here's the world. Here's what just happened. Write what comes next."* **The AI doesn't control the story — the game engine does.** The AI is the narrator, not the author. The rules, pacing, and world simulation run beneath it in ways that attempt to keep the story coherent and on track. **TL;DR:** Authors build a world and its characters (no coding required). A virtual deck of cards — drawn at the start — determine the shape of the story and the literary voice it's written in. The game engine runs the world simulation: tracking time, NPC relationships, events, and consequences. The AI's only job is to narrate what's happening in that world, turn by turn. Readers can pick suggested actions, type anything they want, have free-flowing conversations with NPCs, or just sit back and read. The same world played twice is never the same story. --- Read the rest on our [discord server](https://discord.gg/GGn7ztYaTq) ## The Author When world building, authors create a **genre**. We've borrowed the word, but in Wagtales it means something more defined than "horror" or "romance" — it's your complete authored world: the characters, the locations, the starting situation, and the deck of cards that shapes how stories within it are told. Authors create genres through a built-in editor but can use any text/JSON tool. The goal is for anyone who can write good character descriptions and world-building to be able to make a Wagtales genre — no coding required. If you can write a character backstory and describe a room, you can build a playable world. To give an example: one of our beta genres is a survival adventure where two young men are shipwrecked on a remote island. The init file defines the beach where they wash up, a hidden cave system, and two NPCs with detailed personalities, motivations, and some of the secrets the reader can discover. The author's work — the characters, their secrets, their relationships, the texture of the world — is what gives the engine something worth narrating. Everything that makes a playthrough feel specific and alive starts there. --- ## The Deck System Every genre has its own **deck** containing different sets of cards (currently 2 types, with more planned). These are drawn randomly or chosen by the player when a story starts. We provide sensible default cards for testing, but each set is completely customisable. Authors can, and should, delete, edit or create their own, either from scratch or by importing. ### Deck 1: Story Arc Cards Based on Kurt Vonnegut's famous theory that stories have shapes, these cards define the **emotional trajectory** of your story. There are 8 default shapes: | Shape | What it means | |-------|-------------| | **Man in Hole** | Start okay, fall into trouble, climb back out triumphant | | **Boy Meets Girl** | Gain something wonderful, lose it, fight to get it back | | **Cinderella** | Start in the dirt, rise, get knocked back down, rise even higher | | **Icarus** | Steady rise to glory followed by a spectacular crash | | **Oedipus** | Fall, recover, then fall even harder | | **Tragedy** | A slow, relentless decline | | **Triumph** | A steady climb upward from humble beginnings | | **Metamorphosis** | Things seem fine, then transform into something unsettling | Each card contains an **arc pattern** — 11 numerical values from 0 (darkest) to 100 (brightest) plotted across the story's progression. It also contains a **tone pattern** — 11 emotional colour values that shift the atmosphere as the story progresses. And each card can have elements like **narrative hooks** — specific story directions that complement the shape ("a betrayal by someone trusted," "a sacrifice that changes everything," etc.). ### Deck 2: Narrative Style Cards These define the **voice** the AI writes in. There are currently 11 default, presets (Hard-Boiled Detective, Magical Realism, Comic Fantasy, Epic Fantasy, etc) but again, the author has full control: Each style card would usually includes a **technical guide** (specific instructions for how to write in that style), an **example paragraph**, and even a **blacklist** of overused words the AI should avoid for that style. Reading the same genre can play differently depending on which cards are drawn. That island survival story plays out very differently if the drawn arc is "Icarus" — a desperate push toward rescue that ends in catastrophe — versus "Man in Hole", where the darkest night eventually gives way to a hard-won escape. Put either of those under a Hard-Boiled Detective narration or a Magical Realism one, and you have four distinct stories from one authored world. The genre author writes the world and characters; the cards shape how the story is told. --- ## Acts and Pacing: The Multi-Act Saga Stories are structured as **multi-act sagas** — by default 4 acts. Here's how pacing works: - When a story is created, the genre sets the total number of turns for the entire saga (default: 40, configurable from 20–99). These are divided evenly across acts, so a 40-turn / 4-act saga means ~10 turns per act. - The story arc card's emotional pattern is **sliced per act** — each act gets its portion of the overall trajectory. In the island survival story on a "Man in Hole" arc, Act 1 covers the wreck and the first desperate bid to signal for help — the fall. Act 3 is the darkest point: supplies exhausted, trust between the two men fracturing. Act 4 is the climb back. - Each turn, the AI reports progression. The engine **clamps** this so the AI can't rush to the climax in turn 2 or drag the middle forever. - Eventually a turn becomes the act's finale. The AI wraps up the act and generates transition material — a prologue for the next act, potentially at a new time and location, setting up the next chapter. - Between acts, much of the world state carries forward (NPCs remember, consequences persist) but fresh events are generated aligned to the new portion of the arc. --- ## What Happens on a Turn Readers can happily click "Next" on every turn simply reading the story as it unfolds. Things get more interesting when readers choose to interact. Type an action, the engine works out what changes in the world as a result — time passes, relationships shift, items move, events get triggered — and then hands all of that context to the AI, which writes the next beat of the story. The AI is always working only from an up-to-date picture of the known world rather than some deeply buried or contradictory context. --- ## The Events Engine: A Living World The world doesn't just wait for you. There are three types of events running in the background: **Deterministic Events** check conditions every turn. "If the player's stress exceeds 80% AND they're at the office, their health decreases." These are the world's rules. **Scheduled Events** fire at specific times. "At day 2, 2:00 PM, the meeting begins." These are the world's calendar. **Probabilistic Events** have a percentage chance of firing each turn, with modifiers. "15% chance of a random encounter at night, reduced by stealth." These are the world's chaos. Six events are generated by AI at story creation, aligned to the story arc's emotional trajectory. In the island story, a scheduled event might bring a distant ship into view on day 3 — seen, then gone. A probabilistic event might fire each night: a 20% chance of your companion's old injury flaring up, long before you know it exists. The AI can also **schedule new events mid-story** — so a conversation might trigger a secret the author planted, or a choice you make quietly closes off a door you didn't know was open. Events can **propagate** to other locations (news travels, weather spreads, panic cascades) with optional decay, and they can have **cooldowns** (fire once and disappear, or re-trigger every N turns). --- ## Three Ways to Interact: Act, Speak, Think Every interaction readers make is routed through an **action classifier**. - **ACT** (story actions) — Advances the story state and time. Move somewhere, pick up something, attack, investigate. This triggers the full turn pipeline above. - **SPEAK** (dialogue) — Have a conversation with NPCs present in the scene. This does NOT advance time or state — you can talk as much as you want within a turn. In the island story, this is how you probe your companion for the secrets the author buried in his backstory — without burning a turn to do it. NPCs respond with personality-driven dialogue shaped by their tone, their history with you, and what they know. They'll often embed clickable **action suggestions** in their responses ("*You could [try picking the lock]*, he whispers"). - **THINK** (internal monologue) — Your character's inner voice. The narrator speaks as you, reflecting what your character knows, coloured by your character's emotional tone. The speak/think modes are "free" — in as much as they don't cost a turn or advance the clock. You can have a full conversation with an NPC, weigh your options, think things through, and then commit to an action when you're ready. One deliberate design decision worth flagging: **there is no undo.** Actions and dialogue are permanent. What you say to an NPC, what you do, what you set in motion — it stays in the world. Jeopardy requires consequence. --- ## The Tone System: Emotions as Colour Every emotional state in Wagtales is expressed as an **HSL colour value** using the public code library "tonelib" we created alongside development of the story engine. HSL is a standard way of describing colour used in web design and CSS — Hue is the position on the colour wheel (red, blue, yellow, etc.), Saturation is how vivid or washed-out it is, and Lightness is how bright or dark. We mapped those three axes onto emotion: Hue becomes the *type* of feeling, Saturation becomes *intensity*, and Lightness becomes *outlook* — hopeful or bleak. Every character has a tone. The player has a tone. The story arc has a tone *pattern* that shifts through the story. Scenes are coloured by blended tones. A joyful character with high saturation in a scene driven by an apprehensive arc tone creates tension through emotional contrast. It's basically emotional math — the engine knows how to blend tones, shift them toward targets, intensify or mute them, and check whether characters' tones are harmonious or clashing. This isn't just cosmetic — the tone values flow into AI prompts and influence word choice, atmosphere, and how NPCs behave in conversation. Using HSL turns out to be a surprisingly good fit: LLMs understand these colour codes well, which means in our experience they reliably understand emotional state in the stories. --- ## What Authors Control vs. What Emerges **Authors create:** - The starting world (locations, descriptions, atmosphere) - The starting characters (backstory, personality, secrets, motivations, tone, relationships) - The deck of available story arc and narrative style cards - Genre metadata (themes, influences, content warnings, pacing, target audience) - Vetted configurations that skip AI prologue/event generation entirely and give a quick start to readers. - Story length **The engine generates:** - The specific story each playthrough (driven by drawn cards + player choices) - World events that create pressure and surprise - Story pacing - Act transitions and multi-act continuity - Narrative in the drawn literary style - NPC dialogue with personality and embedded action suggestions **Players shape:** - Which character they play as (if the genre offers multiple) - Which story arc and narrative style cards to use (if the genre offers multiple) - Every action, conversation, and decision during play The result is that the same genre played twice is never the same story. Different cards, different choices, different event timings, different AI narrative — but within the authored world's boundaries, guided by proven story shapes, and written in a consistent literary voice. --- ## The Tech, Briefly For those curious: the backend is TypeScript on Azure Functions, the frontend (due to be open sourced Q2 2027) is Next.js on Vercel, story state lives in Azure Blob Storage, and AI goes through OpenRouter so we can plug in different models depending on the task and offer the latest models as soon as they are available. *(Im a developer, not an author - I had a little help from AI to write this)* You can browse https://wagtales.app without an account. To create or read content you need to create an account and join our beta.