projects / ai & ml / living npcs
Experiment 2024

Living NPCs —
generative AI in retro games

What happens when you try to give persistent memory and coherent personality to NPCs in a Pokémon-style game using an LLM? This is the technical record of what worked, what didn't, and why the problem is more interesting than it seems.

Python LLMs GPT-4o Episodic Memory Game AI Prompt Engineering
View full experiment →

Classic NPCs are cognitively flat — they say the same things, forget every interaction, and have no sense of the world around them. The question was simple: can you fix this with an LLM? And if yes, at what cost in latency, tokens and coherence?

Built a three-module system — episodic memory, personality consistency and world awareness — all running within a constrained token budget. Tested across 220 evaluated conversations, iterating from v0.1 to v0.4 with measurable improvements at each step.

01
The temperature tradeoff is real

Higher temperature produces more creative, "in-character" responses — but also more repetitiveness. The sweet spot was identified experimentally across 30 samples per temperature value.

02
Lost in the middle is a core challenge

LLMs struggle with information buried in the middle of long contexts. Memory architecture had to be designed around this — not just appending history but structuring it for retrieval.

03
Latency breaks immersion before cost does

The immersion-breaking threshold was identified at a specific response time. Beyond that, players notice the delay — making latency a harder constraint than token cost in practice.

04
Local models are the real endgame

GPT-4o-mini makes the experiment viable for prototyping. But for production, a local model of sufficient quality would cut cost per session dramatically — and eliminate latency from API calls.

GPT-4o-mini
Core LLM for NPC responses and personality
Python
Memory module, prompt engineering and evaluation
Prompt Engineering
System prompt architecture for personality and constraints
Plotly
Latency, memory accuracy and cost visualizations