Agentic AI for Interactive Storytelling
QuestMaster AI is a sophisticated application that generates interactive story-based quests using advanced AI agents and automated planning. The system combines narrative generation with PDDL (Planning Domain Definition Language) to create dynamic, playable adventures.
- AI-Powered Story Generation: Creates engaging narratives with characters, settings, and objectives
- PDDL Planning Integration: Uses Fast Downward planner for logical quest progression
- Interactive Web Interface: Streamlit-based frontend for immersive gameplay
- Agentic Architecture: Specialized AI agents for different aspects of quest creation
- Docker Support: Containerized deployment with automated Fast Downward installation
- CLI Interface: Command-line tools for development and testing
src/questmaster/
โโโ agents/ # AI agent implementations
โโโ core/ # Core configuration and settings
โโโ models/ # Data models and schemas
โโโ services/ # Business logic services
โโโ ui/ # User interface components
โโโ utils/ # Utility functions
Configuration is managed through environment variables and the src/questmaster/core/config.py file:
You must configure environment variable with this template Env template
# Required
OPENAI_API_KEY=your-openai-api-key
# Optional
OPENAI_MODEL=gpt-4 # Default model
LOG_LEVEL=INFO # Logging level
DEBUG=false # Debug mode-
Setup and Run:
./docker-setup.sh
-
Or manually with Docker Compose:
docker-compose up --build
-
Access the application:
- Web Interface: http://localhost:8501 (if frontend is generated and started)
- API: http://localhost:8000
-
Setup Environment:
./start.sh
-
Set OpenAI API Key:
export OPENAI_API_KEY="your-api-key-here"
-
Run the Application:
# Complete pipeline python -m questmaster.cli run # Or step by step python -m questmaster.cli phase1 # Story generation python -m questmaster.cli phase2 # Interactive frontend
- Creates immersive narratives with rich lore
- Generates characters, settings, and plot elements
- Integrates seamlessly with PDDL planning
- Converts stories into formal planning domains
- Creates actions, predicates, and goal conditions
- Ensures logical consistency in quest progression
- Validates and refines generated content
- Provides quality assurance for stories and plans
- Suggests improvements and fixes inconsistencies
- Creates dynamic Streamlit interfaces
- Generates interactive game components
- Adapts UI to story requirements
# Check system requirements
python -m questmaster.cli check
# Generate story and PDDL
python -m questmaster.cli phase1
# Create interactive frontend
python -m questmaster.cli phase2
# Run complete pipeline
python -m questmaster.cli run
# Start generated frontend
python -m questmaster.cli frontendfrom questmaster import QuestMasterApp
app = QuestMasterApp()
# Run complete pipeline
story_result = await app.run_phase1()
frontend_result = await app.run_phase2()
# Or use individual agents
story = await app.story_generator.generate_story()
pddl = await app.pddl_generator.generate_pddl(story)The Docker setup includes:
- Multi-stage build for optimized image size
- Automated Fast Downward installation from source
- Python 3.12 with all dependencies
- Health checks for reliable deployment
- Volume mounts for persistent data
# Build and run
docker-compose up --build
# Run specific services
docker-compose up app # Main application
docker-compose up frontend # Just the web interface
# Test Docker setup
./test_docker.sh# Test imports and basic functionality
python test_import.py
# Test CLI functionality
python -m questmaster.cli check
# Test Docker build
./test_docker.shQuestMasterAI/
โโโ src/questmaster/ # Main package
โโโ data/ # Game data and examples
โโโ resources/ # Templates and examples
โโโ fast-downward-24.06.1/ # PDDL planner (auto-generated)
โโโ docker-compose.yml # Docker orchestration
โโโ Dockerfile # Container definition
โโโ requirements.txt # Python dependencies
โโโ start.sh # Local setup script
Help authors generate a PDDL-modeled adventure by guiding them through an interactive narrative design process using LLM agents.
- Lore Document containing:
- Quest Description: Initial state, goals, obstacles, and world context
- Branching Factor: Min/max number of choices at each state
- Depth Constraints: Min/max steps to goal
- Characters, Locations, Items: Important story elements
-
PDDL Generation
- Converts the Lore into a
domain.pddlandproblem.pddlfile - Every line is annotated with natural language comments
- Converts the Lore into a
-
Validation with Classical Planner
- Uses Fast Downward to ensure a solvable plan exists
- Provides detailed error reporting
-
Interactive Refinement Loop (if needed)
- If no valid plan exists:
- A Reflection Agent identifies issues and suggests fixes
- Automatically attempts to correct PDDL errors
- Supports multiple validation iterations
- If no valid plan exists:
- Validated
domain.pddlandproblem.pddlfiles - Finalized Lore document (if updated)
- Generated solution plan
Use the output from Phase 1 to build a web-based interactive adventure game.
- Generate an interactive story graph from PDDL and plan
- Create a modern Streamlit web interface
- Incorporate state-based navigation and choice tracking
- Provide game statistics and progress tracking
The application follows a clean architecture pattern:
- Agents: High-level AI agents that orchestrate specific tasks
- Services: Business logic and external service integrations
- Models: Data models with validation using Pydantic
- Core: Cross-cutting concerns (config, logging, exceptions)
- UI: User interface components
- Utils: Utility functions
- Create models in
src/questmaster/models/ - Implement services in
src/questmaster/services/ - Create agents in
src/questmaster/agents/ - Add CLI commands in
src/questmaster/cli.py - Write tests in
tests/
QuestMaster uses structured logging with rich console output:
from questmaster.core.logging import get_logger
logger = get_logger(__name__)
logger.info("Processing quest", quest_id="123", user="alice")Logs include:
- Structured JSON format
- Rich console formatting
- Contextual information
- Performance metrics
1. Fast Downward Build Fails
# Install build dependencies
sudo apt-get install build-essential cmake g++ # Linux
brew install cmake # macOS2. OpenAI API Errors
- Check your API key in
.env - Verify your OpenAI account has credits
- Check rate limits
3. PDDL Validation Fails
- Review the generated PDDL files in
data/ - Check Fast Downward installation
- Enable debug logging for detailed error info
4. Memory Issues
- Increase Docker memory limits
- Use smaller GPT models for development
- Reduce story complexity
Enable detailed logging:
python -m questmaster.cli --debug --log-level DEBUG run- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests and linting
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Fast Downward planning system
- OpenAI for GPT models
- Streamlit for web interface framework
- Pydantic for data validation
- ๐ Intelligent Reflection: Automatically fixes PDDL validation issues
- ๐ฎ Interactive Web Interface: Beautiful Streamlit frontend for story interaction
- ๐ณ Docker Support: Easy deployment with containerization
- ๐ฆ Modern Architecture: Clean, maintainable codebase with proper separation of concerns
- ๐ก๏ธ Type Safety: Full type hints and validation with Pydantic
- ๐ Structured Logging: Rich logging with structlog
- โก CLI Interface: Command-line tools for all operations
- ๐ Issues: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
Happy Quest Building! ๐ฐโจ
- Generate an HTML-based interface using LLMs
- Incorporate state-based images (optional)
- Render interactive choices and dynamic storytelling