Skip to content

seehiong/living-storybook

Repository files navigation

Living Storybook

The World’s First MMORPS — Massively Multiplayer Online Role-Playing Storyteller

Stories don’t have to end.
They can branch.
They can remember.
They can live.

Living Storybook is a collaborative storytelling platform where humans and AI co-create persistent, branching narratives.
It is powered by Gemini 3 and orchestrated through a stateful LangGraph Narrative Brain running on a Python backend.

🧠 What this repo contains

  • Angular frontend for multiverse navigation & co-authoring
  • FastAPI + LangGraph backend (“Narrative Brain”)
  • Firestore-backed persistent narrative state

🌱 The Core Idea

A reader edits a single sentence in Chapter One.

That change saves a minor character who was meant to die.

Ten chapters later, that character returns as a villain —
remembering the world that spared them.

This is not a new story.
It’s a new timeline.

Living Storybook creates living narrative universes with memory, causality, and consequence.


🎯 The Problem

Most AI storytelling tools generate stateless, disposable prose.

Edits overwrite history.
Characters forget their past.
Continuity breaks as stories evolve.


💡 The Solution: Living Storybook (MMORPS)

Living Storybook is the world’s first MMORPS
(Massively Multiplayer Online Role-Playing Storyteller).

It enables:

  • Collaborative world-building
  • Infinite branching timelines
  • Persistent AI characters
  • Canon-safe story evolution
  • Full attribution across parallel universes

Stories don’t reset.
They accumulate history.


🌌 Core Features

🌍 1. Multiverse Engine (Parallel Timelines)

Every story exists as a timeline.

When a user edits the past:

  • The system detects a causal contradiction
  • Users are offered three options:
    • Fork Timeline → create a parallel universe
    • Overwrite Canon → rewrite history
    • Cancel → preserve the current timeline

No branches are deleted.
Every fork is a valid universe.


🎭 2. Manifested Souls (Persistent Characters)

Characters are not just text.

They are Manifested Souls — persistent AI entities with memory and evolution.

  • Gemini extracts:
    • Personality traits
    • Motivations
    • Relationships
    • Emotional deltas
  • Characters persist across chapters and timelines
  • Forked universes inherit characters with historically accurate divergence

Characters grow because the system remembers them.


🔒 3. Temporal Locking & Canon Preservation

To protect narrative integrity:

  • Published segments become Temporally Locked
  • Locked content is immutable
  • New changes must either:
    • Advance the story forward, or
    • Fork into a new timeline

Every evolution is preserved through edition sequencing.


🧭 4. Chapter Blueprint System

AI generation is guided by a structured Chapter Blueprint, not generic guidelines.

Each chapter defines:

  • A Synopsis: The overarching goal and theme of the chapter.
  • A Beat Sequence: A specific list of narrative beats (plot points) that must occur.
  • Completion Tracking: The system tracks which beats are "Completed", "Remaining", and uniquely targets the Current Beat for the next segment.

The AI understands exactly where it is in the narrative arc, ensuring stories move forward with purpose and adhere to the author's outline.


🧠 5. Intelligent Choice Framework

Every branching path is carefully constructed to ensure narrative momentum:

  • Style-Aware Logic: Choices adapt to the genre (e.g., Tactical choices for RPGs, Philosophical dilemmas for Wuxia).
  • Anti-Pattern Guardrails: Automatic validation prevents backward loops ("go back to start") or premature story-ending dead ends.
  • Dynamic Frameworks: The system switches between Approach, Action, Investigation, and Moral frameworks based on the scene's intensity.

🧠 The Narrative Brain (LangGraph + Gemini 3)

Living Storybook’s intelligence lives in a Python-based Narrative Brain, orchestrated with LangGraph and deployed on Cloud Run.

LangGraph does not generate content —
it coordinates specialized Gemini 3 agents, each with a clear narrative role.

🤖 The Narrative Nodes

The Brain is composed of specialized nodes, each playing a distinct role in the narrative loop:

Node Role Responsibility
Planner The "Architect" Generates high-level chapter blueprints (goals, beats) when a new chapter begins.
Chronicler The "Writer" Generates high-quality prose following the Narrative Specification exactly.
Guardian The "Editor" Consolidated integrity gate. Checks canon, style, pacing, and story beats in one pass.
Feedback The "Coach" Distills validation failures into actionable revision blueprints for retries.
Intelligence The "Director" Analyzes state, extracts DNA, and generates strict specifications for the next segment.

All nodes operate over a shared NarrativeState, ensuring:

  • Observability: Request correlation IDs and retry visibility.
  • Fail-Safe Operation: Automatic fallback mechanisms.
  • Sliding-Window Memory: Efficient context management.
  • Semantic Progression: Intelligent Act transitions.

🏗️ Technical Architecture

The Narrative Brain is a modular multi-agent system built on LangGraph.

Workflow Visualization

graph TD
    START((START)) --> Planner{Planner}
    Planner -->|Chapter Complete| Chronicler[Chronicler: Generate Prose]
    Planner -->|New Chapter Needed| ChapterPlanner[Chapter Planner]
    ChapterPlanner --> Chronicler

    Chronicler --> Guardian[Guardian: Consolidated Check]
    
    Guardian -->|Valid| Intelligence[Intelligence: State & Choices]
    Guardian -->|Failed| Feedback[Feedback: Prep Revision]
    
    Feedback -->|Retry #1| Chronicler
    
    Intelligence --> END((END))
    
    style Guardian fill:#f96,stroke:#333,stroke-width:2px
    style Feedback fill:#ff9,stroke:#333,stroke-dasharray: 5 5
Loading
  • Modular Design: Separated concerns across nodes/, pipelines/, and utils/.
  • Stateless Compute: Backend runs on Cloud Run; state is persisted in Firestore.
  • Fail-Safe Orchestration: Graph-based retries and self-correction loops.

🔧 Tech Stack

Frontend

  • Angular
  • NgRx
  • Firebase Hosting
  • Optimistic UI updates

Backend

  • Python
  • FastAPI
  • LangGraph (Stateful multi-agent orchestration)
  • Google Generative AI SDK (Gemini 3 Flash Preview)

Storage

  • Firestore (shared state & memory)
  • Cloud Storage (assets)

🚀 How to Run Locally

Start Backend

cd backend
.\venv\Scripts\activate
python -m app.main

Start Frontend

ng serve

📌 Project Status

Hackathon build (Gemini 3 Hackathon). Actively evolving.