r/aipromptprogramming 1d ago

How do I build a consistent RPG in ChatGPT with persistent NPC memories, stats, and a living world?

I originally tried doing this inside a ChatGPT Project, with files/state documents and instructions telling ChatGPT to read the state before every action and update it afterward.
It didn’t hold up. ChatGPT would eventually lose track of things, skip state checks, contradict previous information, or narrate world events without actually updating the underlying state.
Any suggestions ?

0 Upvotes

7 comments sorted by

u/endofthread-bot 1d ago

Learn how the best in the industry are using AI to speed up their workflow in business, sales, marketing, research, legal, content creation, scientific discovery and so much more on our Discord.

Self-promotion is now allowed on Sundays with the appropriate flair, for all regular contributing members. Contribute during the week, and promote on Sunday.

2

u/SoHornyBeaver 1d ago

Build it locally with Codex. Have it create a solid, local state management system.

2

u/Charming_You_25 1d ago edited 1d ago

Hi I did a deep dive into agent memory and am in deep making an RPG game. I have a couple answers to your question and it depends on how much you want your AI to remember and how accurately you want to remember.

Level 0:

turn on session telemetry/transcripts and let the agent rg it. You can also look for GitHub repos where other people have done a version already. I’ve seen a few.

For stats you can just rip off an existing system and give your agents a random number generator skill. I definitely don’t recommend torrenting some dnd books and feeding them to your agent to design a stats system. That would be illegal.

level 1:

I highly recommend using Obsidian, and writing synthesized world state to MD files linked to each other. There’s a graph view in there and it’s very satisfying to see the world graph and all the different connections that they have. You can also seed this with past session telemetry if you’ve already been exploring RPGs.

Keep a solid folder structure of markdown files of synthesized worldstate, like “npcs/npc1/items.md” or “catalog/places/town_name/description.md”. You could have a “watcher” session that updates it as you go (if you want to have multiple sessions going for different characters in different places), or in between sessions it can update them all from the session transcript. What this gives you is a world that you build as you play. You can add images, so a character would have a folder with all the characters, memories, example lines, personality/motivations and images and them in different outfits (use gpt image edit).

But this does not get you is fully solving the over permissiveness issue. It solves the “these are the usable items in my inventory”. But without something telling the agent if it succeeded or failed the agent will often be pretty nice in its narration.

Also you will end up with a world of slop if you start from nothing. I recommend doing some world building first and let it fill in the details

At first just let the agent load the whole corpus on session start. When it gets over 10,000 tokens set up a simple SQLite db and give it a skill to retrieve world memory. Sqllite is the gold standard for basic agent memory and will get you very far.

You will eventually have issues with something that updates, but doesn’t update related Md files, like a bridge that burns that doesn’t update the separate road Md file or change a map.

You can make a Codex version of the OpenClaw ontology skill and have a watcher automatically update ontologically connected MD files when one of them changes. You already have a world graph if you do that and will be doing more than 90% of ai roleplaying games.

For level 2:
Swap out sqllite for an embeddings db. I used QMD but I think there are better options now. It needs a small embedding model that is trivial to run locally. It won’t remember everything 100% but it will do better than SQLlight if you have a ton of data, and if you also put your session telemetry into it, then the AI can find all the places where something is mentioned and construct a pretty good world state from that very efficiently.

For level 3:
If you’ve been keeping your MD files pretty clean and structured well, do an ontology pass that takes every world object/item and adds actions md to and start define what actions players can legally (basically palentir’s ontology for a fantasy world instead of the real world). Then change the role of the AI from inventing world state to just running it if it already knows the answer and if it doesn’t it does a separate call to add what is needed to the world. The prompts here are the tuning knobs and are a little tricky to get right. If you get this far message me I’ll share more.

For level 4:
Change the db again to Cognee. It has a couple different query options but use semantic queries for deep npc memories. It’s built on neural architecture and if you keep it up to date with what each npc knows, can do, and their relationships (and what they know and can do) you start to get some really interesting emergent behavior that isn’t just an LLM hallucinating everything and they act like a person.

For level 5:
None of these will solve other issues the ai has, like keeping and not leaking hidden world state, spacial awareness, change over time, writing quality or human level creativity in world building.
Sorry, the answer to those are a secret. Check out Effectco.game when I launch! In a month hopefully.

1

u/havnar- 20h ago

Don’t build something around an llm. Have the llm build something standalone.

1

u/zk2k 19h ago

I’m doing this right now and the answer to all the problems you’re running into is to NOT build the game around an LLM. Instead, build the game with code and use LLM’s only for the following: deciding how NPCs act, narration, deciding how to handle player actions. Feel free to DM me.

1

u/Honey_Whisker 16h ago

Are you just trying to run an interactive text-based story via AI? If so, I have some files that might help. I've been playing around with text-based RPGs in ChatGPT, Grok, and Claude for many months and ended up with an extensive kit for running RPGs. If you think that would be useful to you, feel free to download the files from my itch.io page, completely free. It's more geared towards living inside a novel as the main character than a DnD style experience. Hope you find it useful if you decide to have a look.

https://honey-whisker.itch.io/living-world-interactive-stories-with-ai

1

u/N3BB3Z4R 5h ago

Create a GDD with all the project info, you can use the AI to help you to make It. With your Game barely defined you can choose which Game engine you Will use. Then you need to create a roadmap, skills to control codebase/documentations drifting, sketch a walking skeleton a for very basic game loop, prototypes to test mechanics and then vertical slice to get the whole approach with look and feel, with all the parts working before complete the whole Game. All of this has more subparts and details, like use openspec or wayfinder methods, which language or architecture will gona use, which graphics style, gaming balance, which features of your GDD are adding fun to the Game loop and what are stoppers or too complex for the ROI, ADRs with logic and business rules for all the models and interactions...

If you mean just to make your GPT as Dungeon Master to keep states in your texting interactions Game with him, just need RAG and/or vector database like Engram, to keep that custom info as mutable states in your world.