Your instinct to use a multi-pass approach is exactly right. When converting linear narrative text into a structured game state, attempting to extract the map, the actors, and the logic in a single pass usually causes AI models to hallucinate or drop critical context. To build an automated pipeline that ingests an EPUB or text file and outputs a playable world, you can structure it as a sequential semantic extraction graph. Pass 1: Spatial Topology (The Map) The first goal is to create a graph of nodes (rooms/areas) and edges (connections/paths). Because a book is too long for a single prompt, the pipeline must read the book using an overlapping sliding window. * The Extraction: Ask the model to identify distinct locations and how they connect. (e.g., "The dark cavern leads north to a stone bridge"). * The Output: A JSON array of room objects with assigned IDs, descriptions, and directional exits pointing to other room IDs. * The Challenge: Authors rarely describe a perfect grid. The pipeline needs a normalization step to resolve spatial paradoxes (e.g., merging "the grand hall" and "the main hall" into a single room ID if context implies they are the same). Pass 2: Entity Placement (The Props & Actors) Once the spatial graph exists, the pipeline does a second pass over the text, this time armed with the Room IDs from Pass 1. * The Extraction: The prompt instructs the model to track the protagonist's location and extract any notable items (weapons, keys, artifacts) or characters (monsters, allies) encountered in that specific scene. * The Output: A list of entity objects with properties (name, description, base stats) bound to a specific Room ID. Pass 3: Dialogue and Quest Logic (The State Machine) Linear stories don't naturally map to branching game quests, so this pass requires the model to infer preconditions and outcomes. * The Extraction: Scan for conflicts, conversations, and resolutions. For example, if the hero gives a coin to a beggar to get a key, the model extracts a quest: Condition: Player has Coin -> Action: Give Coin -> Outcome: Receive Key. * The Output: Dialogue trees and event triggers attached to the NPCs or objects generated in Pass 2. Pass 4: Engine Serialization The final step is translating this abstracted semantic JSON graph into the actual formats your game engine consumes. * The Compilation: The pipeline takes the extracted entities and compiles them directly into executable scriptssuch as LPC objects for your virtual machine, or serializing the initial world state into an AST-MD format for your database engine. * The Handoff: Once ingested, the server can instantly mount the generated world, populate the memory arenas, and begin handling CRDT state synchronization for connected players moving through the generated rooms. To make this work reliably, the LLM in the pipeline should be restricted to outputting strict JSON schemas for each pass, ensuring the data can be programmatically parsed and passed to the next step without manual cleanup.