Skip to content

Latest commit

ย 

History

208 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿบ Thudbot - The Space Bar AI Assistant

Python 3.12+ FastAPI Next.js LangGraph

An intelligent AI assistant for The Space Bar adventure game that provides contextual hints.

Quick Start

  1. ๐ŸŽฌ Watch the video to get oriented to Thudbot

  2. ๐Ÿงช Try out Thudbot locally

    1. Follow the Quick Start steps below

    2. Try these Example Questions

๐Ÿš€ Project Overview

Thudbot is an AI-powered player companion for The Space Bar, a cult-classic adventure game from legendary game designer Steve Meretzky.

It provides contextual, spoiler-sensitive hints through an immersive, in-universe interface: the playerโ€™s Personal Digital Assistant (PDA), Zelda.

Designed as a standalone web tool, Thudbot keeps you grounded in the game worldโ€”even when you need help solving its trickiest puzzles.

Built with LangGraph, FastAPI, and Next.js, Thudbot is a stepping stone toward fully agentic NPCs for the Boffo Games universe.

๐ŸŽฌ Demo Video

Watch the 2min Demo Video

See Thudbot in action

๐Ÿงช Testing Thudbot

Not familiar with "The Space Bar" game? No problem! Here are ready-to-test examples:

Game Hint Examples (Tests RAG system)

Q: "Where is the bus token?"
Expected: Thud explains it's in a cup, with character-specific advice

Q: "How do I get the token from the cup?" 
Expected: Step-by-step hint about asking Thud for help or looking carefully

Q: "When does the shuttle to Karkas 4 leave?"
Expected: Specific time (22:50) with character commentary about checking monitors

โœจ Features

  • ๐ŸŽฎ Game Hint System: RAG-powered hints for The Space Bar adventure game puzzles
  • ๐Ÿ›ก๏ธ Robust Error Handling: Graceful error recovery
  • ๐ŸŒ Web Interface: Next.js frontend
  • โšก FastAPI Backend: High-performance Python API server
  • ๐Ÿงช Comprehensive Testing: Robust test suite

โšก Quick Start

๐Ÿณ Fastest Way: Docker Compose

# Clone the repo
git clone https://github.com/BQ31X/thudbot.git
cd thudbot

# Add your API keys to .env (copy from .env.example)
cp .env.example .env
# Edit .env with your OPENAI_API_KEY

# Start everything with Docker
cd infra
docker compose up --build

# โœจ Thudbot backend now at: http://localhost:8000

๐Ÿ“ฆ Traditional Setup

Prerequisites

  • Python 3.13+
  • Node.js 20+

1. Environment Setup

# ๐Ÿ“ฆ Clone the repo
git clone https://github.com/BQ31X/thudbot.git
cd thudbot


# Install Python dependencies (backend)
cd apps/backend
uv sync

# Install Node.js dependencies (frontend)
cd ../frontend
npm install

2. Configuration

# Return to project root and copy environment template
cd ../..
cp .env.example .env

# Edit .env and add your API keys:
# OPENAI_API_KEY=your_api_key_here
# LANGCHAIN_API_KEY=your_langchain_key_here  # Optional: for LangSmith tracing

3. Run the Application

Terminal 1 - Backend:

cd apps/backend
uv run python -m thudbot_core

Terminal 2 - Frontend:

cd apps/frontend
npm run dev

Access: Open http://localhost:3000 in your browser!

๐Ÿš€ Production Deployment (Docker Swarm)

For production deployment using Docker Swarm with secure secret management:

Prerequisites

# Initialize Docker Swarm (if not already done)
docker swarm init

# Create Docker secrets for API keys
echo "your_openai_api_key_here" | docker secret create openai_api_key -
echo "your_langchain_api_key_here" | docker secret create langchain_api_key -

Deploy to Production (Two-Node Architecture)

Prerequisites:

  • Two servers (app node + retrieval node)
  • Docker + Docker Buildx on local machine
  • Docker Swarm on app node
  • Docker + Docker Compose on retrieval node
Build Multi-Arch Images
# Build all images (backend, frontend, retrieval)
make build-all

# Or build individually
make build-backend
make build-frontend
make build-retrieval

# Verify multi-arch support
make inspect-images
Deploy Retrieval Node First
# Deploy qdrant + retrieval service
make deploy-retrieval

# Verify
make logs-retrieval
make logs-qdrant
Deploy App Node
# Create Docker secrets on app node (one-time)
ssh bq@<app-node-ip>
echo "your_openai_key" | docker secret create openai_api_key -
echo "your_langchain_key" | docker secret create langchain_api_key -
docker swarm init

# Deploy backend + frontend + redis
make deploy-prod

# Verify
make logs
make logs-frontend
Full Deployment
# Deploy both nodes with one command
make deploy-all

Production Features

  • ๐ŸŒ Two-Node Architecture: Separates compute (app) from retrieval (embeddings + vector search)
  • ๐Ÿ” Docker Secrets: Secure API key management on app node (no secrets on retrieval node)
  • ๐Ÿ“ฆ Multi-Arch Images: ARM64 (Mac dev) + AMD64 (Linode prod)
  • ๐Ÿ”„ Auto-restart: Automatic service recovery with restart policies
  • ๐ŸŽฏ Local Embeddings: BGE CPU-only embeddings

Management Commands

# App node operations
make logs              # View backend logs
make logs-frontend     # View frontend logs  
make restart-backend   # Restart backend service

# Retrieval node operations
make logs-retrieval    # View retrieval service logs
make logs-qdrant       # View qdrant logs
make restart-retrieval # Restart retrieval service
make stop-retrieval    # Stop retrieval stack

# Build operations
make build-all         # Build and push all images
make inspect-images    # Verify multi-arch builds

๐ŸŒ Production Access: Backend available at http://your-server:8000 โš ๏ธ Security Note: Restrict access via firewall, VPN, or reverse proxy in production

โš™๏ธ Configuration:

  • Edit Makefile to set your server IPs (APP_LINODE_HOST, RETRIEVAL_LINODE_HOST)
  • Retrieval API URL is set in infra/compose.prod.app.yml

๐Ÿ—๏ธ Architecture

Two-Node Production Architecture

Frontend (Next.js)
    โ†“
Backend (FastAPI + LangGraph) โ”€โ”€โ”€ App Node (<app-node-ip>)
    โ†“ HTTP
Retrieval Service (FastAPI)   โ”€โ”€โ”€ Retrieval Node (<retrieval-node-ip>)
    โ†“ local
Qdrant (server-mode)

Production Deployment:

  • App Node: Backend + Frontend + Redis (Docker Swarm)
  • Retrieval Node: Qdrant + Retrieval API (docker compose)
  • Communication: Backend โ†’ Retrieval API via RETRIEVAL_API_URL

Built with:

  • Backend: FastAPI + LangChain + OpenAI GPT-4
  • Frontend: Next.js + React + Tailwind CSS
  • Retrieval: FastAPI + Qdrant (server-mode) + BGE embeddings (local, CPU-only)
  • Data: Server-mode Qdrant collection + Multi-query retrieval
  • Build: Offline collection builder with OpenAI or local BGE embeddings

Storage Architecture:

  • Build-time: tools/build_qdrant_collection.py creates server-mode collections
  • Run-time: Backend calls retrieval API; retrieval service queries Qdrant directly

๐Ÿ“Š RAG Evaluation & Performance

Data-driven retriever selection using comprehensive evaluation:

  • ๐Ÿ““ Full evaluation in: 00_Thud_construction.ipynb
  • ๐Ÿงช Framework: RAGAS metrics (context recall, entity recall, noise sensitivity)
  • ๐Ÿ“‹ Golden dataset: 12 synthetically generated test queries
  • ๐Ÿฅ‡ Platinum dataset: Selected subset of 5 queries, produced by applying a LangChain-based rewriting prompt to the golden dataset, followed by manual selection for evaluation focus and cost control
  • โš–๏ธ Compared retrievers: Naive, BM25, Multi-query
  • ๐ŸŽฏ Result: Multi-query retrieval selected based on superior performance

Key findings:

  • Multi-query retrieval significantly improved context precision
  • Enhanced handling of ambiguous game terminology
  • Better retrieval of relevant hints for complex puzzles

See notebook for detailed metrics, comparison tables, and methodology.

๐Ÿงช Testing

Run the comprehensive test suite:

# Run all tests
uv run pytest

# Run tests with the commit script
./check_and_commit.sh "your commit message"

Test coverage includes:

  • Data validation (CSV exists & structure)
  • Module imports (all components load)
  • File organization (required files present)
  • Basic functionality verification

๐ŸŽฎ Usage Examples

Ask about game puzzles:

"How do I get the token from the cup?"
โ†’ "The bus token is in the cup; make sure Thud has it before you hop on the bus."

Get general game help

"When is the shuttle to Karkas 4?"
โ†’ "The shuttle to Karkas 4 departs at 22:50."

๐Ÿ“– Project Structure

thudbot2/
โ”œโ”€โ”€ apps/
โ”‚   โ”œโ”€โ”€ backend/            # Python FastAPI backend
โ”‚   โ”‚   โ”œโ”€โ”€ thudbot_core/   # Core application code
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ *_node.py   # LangGraph workflow nodes
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ api.py      # FastAPI backend server
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ langgraph_flow.py # Main workflow orchestration
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ state.py    # Shared state management
โ”‚   โ”‚   โ”œโ”€โ”€ data/           # CSV hint database
โ”‚   โ”‚   โ”œโ”€โ”€ tests/          # Backend test suite
โ”‚   โ”‚   โ”œโ”€โ”€ pyproject.toml  # Python dependencies & config
โ”‚   โ”‚   โ””โ”€โ”€ Dockerfile      # Backend container image
โ”‚   โ””โ”€โ”€ frontend/           # Next.js frontend
โ”‚       โ”œโ”€โ”€ app/            # Next.js app directory
โ”‚       โ”œโ”€โ”€ public/         # Static assets (PDA interface)
โ”‚       โ””โ”€โ”€ package.json    # Node.js dependencies
โ”œโ”€โ”€ infra/
โ”‚   โ”œโ”€โ”€ compose.yml         # Docker Compose (default)
โ”‚   โ””โ”€โ”€ compose.prod.yml    # Production Docker Compose
โ”œโ”€โ”€ docs/                   # Project documentation
โ”œโ”€โ”€ notebooks/              # Jupyter notebooks used for prototype development
โ”œโ”€โ”€ .env                    # Environment variables (not in git)
โ”œโ”€โ”€ README.md               # This file
โ””โ”€โ”€ check_and_commit.sh     # Test runner and commit script

๐Ÿšจ Troubleshooting Tips

  • Make sure .env is properly configured with a valid OpenAI key.
  • Restart both frontend and backend if switching API keys or files.
  • Backend logs appear in the terminal where you run uv run python -m thudbot_core.
  • For Docker Compose issues, try docker compose down then docker compose up --build.

๐Ÿ“„ License

This project is copyrighted and all rights are reserved. Leo DaCosta 2025

About

AI player companion for The Space Bar. Built with LangGraph, FastAPI, Next.js, Qdrant & Redis.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages