Built an AI dungeon master using GPT-4o with memory

Mike Torres
Mike TorresFeb 5, 2026

I built AI Dungeon Master — a text-based RPG powered by GPT-4o with persistent world state and character memory.

Key features:

  • Persistent world state stored in a JSON "world model"
  • Character sheets with stats, inventory, and relationships
  • Combat system with dice mechanics
  • The AI maintains narrative consistency across 50+ turns
  • The trick to consistency is feeding a compressed world state as context:

    {
      "location": "Dark Forest - clearing near the river",
      "time": "dusk, day 3",
      "party": [
        {"name": "Elara", "class": "ranger", "hp": 24, "status": ["poisoned"]}
      ],
      "active_quests": ["Find the missing merchant"],
      "recent_events": ["Defeated 3 goblins", "Found mysterious map"]
    }
    

    The world model gets updated after each turn using structured outputs. Users are loving it — average session is 45 minutes!

    6.1k views37 replies124 likes

    Log in to reply to this topic.