This project is an interactive storytelling framework that uses Large Language Models (LLMs) to generate dynamic narratives along predefined story paths. Here's a comprehensive overview:
llm-gamebook is a Python application that creates interactive, branching stories where the narrative follows predefined graph-based paths while being dynamically generated by an LLM. It's essentially a sophisticated choose-your-own-adventure system with AI-powered narration.
- Dynamic Narrative Generation: The LLM creates contextually appropriate responses based on the current story state
- Predefined Story Arcs: Ensures narrative coherence while allowing branching paths
- Entity State Management: Tracks character relationships, locations, and other story elements
- Time Tracking: Variable time progression that can speed up or slow down based on narrative needs
- Modular Design: Stories can be broken into reusable components
- Streaming Responses: Real-time display of the LLM's thinking and response generation
This project represents an innovative approach to interactive storytelling, combining the idea of traditional gamebooks with the dynamic capabilities of modern LLMs to create rich, branching narratives.
- A story is defined in a YAML file with entity types, nodes, and transitions
- The StoryEngine loads the story and initializes the state
- The LLM generates narrative content based on the current state and predefined paths
- Users interact with the story through the TUI
- The system maintains state and triggers appropriate transitions and updates based on conditions and user input
- Python for the application logic
- Pydantic for data validation and schema definition
- Pydantic AI for LLM integration and tool calling
- Textual for the terminal user interface
- Jinja2 for templating prompts and narrative elements
- YAML for story definitions
Run FastAPI web server.
$ cd backend
$ uv run uvicorn llm_gamebook.web.app:create_app --reload --factory --log-level debug
Run Vite dev server.
$ cd frontend
$ pnpm dev