Efe Anidi
Simulations

AI-driven NPCs: LLM agents and the future of living simulations

For AI game designers: from dialogue trees to LLM agents with memory, goals and routines, why text-first NPC conversation is the practical win today, how generative voice comes next, and the architectures that hold up.

15 October 2026 · 13 min read

simulations

For most of the history of games, a non-player character has been a very good liar. The blacksmith who greets you by name has no idea who you are; a flag in a save file told a dialogue tree which branch to show. The guard who “hears a noise” is running a state machine with three states and a timer. It works because designers are careful about where the player looks.

Large language models change what an NPC can be underneath the performance. A character can now hold a memory of what happened, form opinions about it, make plans that weren’t written in advance, and talk about all of it in open language. That is a real shift, but it is not a free one, and it arrives in layers. Today the practical win is text: conversation typed and read, grounded in a simulation that tracks what is true. Voice, through generative audio, is the next layer and is already shipping in places. Generated video and world models sit further out, and may eventually change how a simulation is shown rather than how it thinks. For anyone designing games with AI, the NPC is where that shift is most visible. This piece sets out where LLM agents sit in the lineage of game AI, what an agent NPC looks like as a loop of code, where it breaks, and the patterns that make it workable.

A short lineage of NPC minds

Every generation of NPC AI has been an answer to the same question: how much of the character’s behaviour do we write by hand, and how much do we let a system work out?

Dialogue trees and scripts sit at one end. Every line and branch is authored: perfectly controllable, often beautifully written, but the space of possible conversations is exactly the space someone typed.

Finite state machines gave characters behaviour rather than lines: patrol, investigate, attack, flee. Easy to reason about until the transition graph turns into spaghetti.

Behaviour trees, popularised in the mid-2000s and associated in particular with Halo 2’s AI, organised decisions into a hierarchy of selectors and sequences. They scale far better than raw FSMs and remain the default in most engines, but the tree decides and the character executes.

Goal-Oriented Action Planning (GOAP), best known from Jeff Orkin’s work on F.E.A.R., moved some authorship to runtime. You give the agent goals and a set of actions with preconditions and effects, and a planner searches for a sequence that achieves the goal.

Utility AI scores every available action against the agent’s current needs and context, then picks the best (or a weighted random choice among the best). The Sims is the canonical example: hunger, energy, social need and fun all pull on behaviour, and interesting routines fall out of the arithmetic. LLM agents are the newest layer. Instead of searching over a hand-built action graph or scoring a fixed list, the model reasons in language over a description of the situation, the character’s memories and its goals, and proposes what to do or say next. The expressive range is far wider than anything before. So is the room for error.

Approach Runtime cost Controllability Expressiveness Best use
Dialogue trees / scripts Negligible Total Limited to authored content Key story beats, quest givers
Finite state machines Negligible Very high Low Simple enemies, ambient creatures
Behaviour trees Low High Moderate Combat, companions, most AAA NPCs
GOAP Low to moderate (planning search) Moderate Moderate to high within the action set Tactical agents, multi-step tasks
Utility AI Low Moderate, tuned via curves High for needs-driven routines Life sims, colonists, crowds
LLM agents High (inference per decision) Low unless constrained Very high, open language Conversation, social reasoning, high-level decisions

The table makes the trade-off plain. Each step towards expressiveness has historically been paid for in controllability, and LLMs take the biggest step yet. The AI game designer’s job is to choose where on that table each character sits, not to put every character in the bottom row.

Anatomy of an LLM agent NPC

The clearest public blueprint is still Park et al.’s 2023 paper, Generative Agents: Interactive Simulacra of Human Behavior, from Stanford and Google. Its sandbox, Smallville, held 25 agents who woke up, went to work, chatted and formed relationships. Seeded with a single agent’s intent to throw a Valentine’s Day party, the population spread invitations among themselves, and several agents turned up at the right place and time. Nobody scripted the guest list.

The architecture behind that has three ideas worth stealing.

  1. A memory stream. Every observation the agent makes is appended to a long list of natural-language records with timestamps.
  2. Retrieval. When the agent needs to act, it does not read the whole stream. It scores memories on recency, importance (rated by the model when the memory is stored) and relevance to the current situation, and pulls in the top few.
  3. Reflection and planning. Periodically the agent asks itself higher-level questions about its recent memories and writes the answers back into the stream as new, more abstract memories (“Klaus is passionate about his research”). Separately, it drafts a plan for the day, decomposes it into smaller chunks, and revises it when something unexpected happens.

As a loop, it looks roughly like this:

interface Memory {
  text: string;
  createdAt: number;
  lastAccessed: number;
  importance: number;      // 1-10, scored once at write time
  embedding: number[];
  kind: "observation" | "reflection" | "plan";
}

async function agentTick(agent: Agent, world: WorldState, now: number) {
  // 1. Perception: what can this agent see and hear right now?
  const observations = world.perceive(agent.id);
  for (const obs of observations) {
    await agent.memory.add(obs, { kind: "observation", now });
  }

  // 2. Retrieval: pull the memories that matter for this moment
  const query = describeSituation(agent, observations);
  const context = agent.memory.retrieve(query, {
    k: 12,
    weights: { recency: 1, importance: 1, relevance: 1 },
    now,
  });

  // 3. Reflection: only when enough important things have piled up
  if (agent.memory.importanceSinceLastReflection() > agent.reflectThreshold) {
    const insights = await llm.reflect(agent.persona, context);
    for (const i of insights) {
      await agent.memory.add(i, { kind: "reflection", now });
    }
  }

  // 4. Planning: keep the plan unless the situation demands a change
  if (agent.plan.isStale(now) || shouldReplan(observations, agent.plan)) {
    agent.plan = await llm.plan(agent.persona, context, agent.plan);
  }

  // 5. Action: choose from legal actions only, validated against the world
  const legal = world.legalActionsFor(agent.id);
  const choice = await llm.chooseAction(agent.persona, context, agent.plan, legal);
  const result = world.apply(agent.id, validate(choice, legal));

  await agent.memory.add(result.description, { kind: "observation", now });
}

Two details in that sketch matter more than they look. The action step selects from a list the world supplies, and the outcome is written back as an observation produced by the world, not by the model. Both come up again below.

The hard parts

Moving from a research demo to a game exposes five problems.

Cost and latency

A game tick is measured in milliseconds; a call to a large hosted model is typically measured in hundreds of milliseconds to seconds. Multiply by every NPC, every decision, every frame, and the arithmetic fails immediately. A shopkeeper who pauses for two seconds before every gesture does not feel alive; she feels buffered. Text hides some of this, because players accept a typing indicator. Voice hides almost none of it.

Consistency and character drift

Language models are good at sounding like a character for a paragraph and less good at being the same character for forty hours. Personalities flatten towards a generic helpful tone, grudges are forgotten, and retrieval is lossy: the one memory that mattered might not make the top twelve.

Hallucinated world facts

An NPC will happily tell the player there’s a sword hidden in the well. In a novel that is invention; in a simulation it is a bug, because the player will walk to the well.

Controllability versus emergence

The thing that makes agent NPCs interesting, that they do things you didn’t write, is the same thing that breaks quests, kills characters the story needs, or leaves the town’s only blacksmith wandering the woods in existential reflection. You want surprise within bounds, and the bounds are the hard part.

Safety and moderation

Open-ended conversation means open-ended input. Players will try to make characters say things they shouldn’t, break character or leak system prompts. When Epic added a conversational, AI-voiced Darth Vader to Fortnite in May 2025, players were reported tricking him into swearing almost immediately. Any LLM that talks to players needs input and output filtering, and a clear policy for what happens when a filter trips.

Architecture patterns that hold up

None of these problems is solved, but each has patterns that reduce it to something manageable.

Hybrid minds

The single most useful idea is not to make the LLM do everything. Let a cheap system, usually utility AI or a behaviour tree, run moment-to-moment behaviour: walking, eating, working, reacting to danger. Call the model only at decision points: when a conversation starts, when a goal is completed or fails, when something important enough happens to warrant rethinking the plan. The LLM becomes a slow, deliberate layer setting goals and weights, while the fast layer turns those into motion.

Level of detail for simulation

Agents near the player run at full fidelity, with model-driven conversation and replanning. Agents in the next district run on utility AI with occasional summarised updates. Agents across the map are statistical: a few rolls per in-game day decide whether the farmer’s harvest was good. When the player approaches, the agent is promoted and its summary becomes its recent memory.

Never let the model’s free text drive the game directly. Ask for structured output, ideally through tool calls or a JSON schema, and generate the schema from the actions actually available:

{
  "action": "trade",
  "target": "npc_miller_04",
  "offer": { "item": "iron_ingot", "qty": 2 },
  "request": { "item": "flour", "qty": 5 },
  "say": "Two ingots for five sacks. That's fair and you know it."
}

The engine validates every field. If the target doesn’t exist or the agent doesn’t own the ingots, the action is rejected and the rejection becomes an observation. The model proposes; the simulation disposes.

World state as ground truth

This is the fix for hallucinated facts. The world, not the model, owns what is true. Anything an NPC says about the world should be either derived from queries against the world state or clearly framed as rumour, opinion or belief. A useful discipline is to give each agent a belief store separate from the world: an NPC can be wrong about the bridge, but only because it believes something stale, not because the model invented a bridge. Being wrong for a reason is characterisation. Being wrong at random is noise.

Caching and summarised memories

Routine is cacheable: a baker’s daily plan barely changes, and greetings can be batch-generated during idle time. Compact memory streams by summarising last week into a few reflections, and keep a pinned core of identity facts (name, history, relationships, values) always in context. That pinned core is the best defence against drift.

Small and local models

Not every call needs a frontier model. Small models, quantised and run locally, can handle importance scoring, short barks, routine plan updates and classification, while a larger model handles the conversations players will actually scrutinise. Local inference removes per-call billing and network latency, at the cost of memory and GPU time competing with the renderer.

Designing for emergence

An agent with memory and planning but nothing to want will produce pleasant, aimless small talk. The Smallville party worked because one agent had a goal and the others had reasons to care. Emergent stories come from pressure.

The best teachers here aren’t LLM projects. Dwarf Fortress and RimWorld produce memorable stories from fairly simple agents because their systems collide, and RimWorld makes pacing itself a system, with an AI storyteller choosing when to inject raids or windfalls. LLM-driven worlds should follow the same principles:

  • Give agents goals that conflict. Two characters who want the same land will generate story without help.
  • Make things scarce. Scarcity forces trade-offs, and trade-offs are where character shows.
  • Let systems touch. Weather affects harvests, harvests affect prices, prices affect tempers. The LLM layer is best at interpreting these collisions socially, not at causing them.
  • Keep consequences persistent. If an insult is forgotten by the next day, nothing builds. Relationships should be stored as world state, not left to the model’s recall.
  • Use a director that watches for stagnation and nudges: a stranger arrives, a debt comes due.

The LLM is the part that makes emergence legible. A colonist in a classic simulation breaks down because a number crossed a threshold; an agent NPC can tell you why, in her own words, and remember that you were the one who didn’t help.

Evaluating a world that writes itself

There is no single expected output to assert against; you cannot test that the party happens on Tuesday. Test properties instead:

  • Invariants that must always hold: quest-critical characters stay reachable, the economy never creates items from nothing, no agent acts outside its legal set.
  • Headless soak runs over hundreds of simulated days and many seeds, looking for deadlocks, runaway loops and collapsing populations.
  • Consistency and grounding probes: ask agents the same questions about themselves over time, and check factual claims in their speech against world state.
  • Human review of transcripts. Park et al. leaned on human judgements of believability, and no metric yet substitutes for a playtester saying “she wouldn’t say that”.
  • Cost budgets: tokens per in-game hour, treated like frame time.

Model output is not reliably deterministic, so record every response during a test run and allow exact replay.

Text now, voice next, pictures later

A living world built this year should start with text, and not as a compromise. Text is where the technology is mature, cheap and forgiving. A typed conversation tolerates a second of latency, can be logged and grounding-checked line by line, and costs a fraction of anything rendered. The lineage is long, too: AI Dungeon, first released in 2019, showed that people will happily play a world made of generated prose. A text-first simulation, with hard world state underneath and a model narrating and voicing characters on top, is the simplest version of everything in this article, and the easiest to test.

Voice is the next layer, and generative audio is good enough to ship. Text-to-speech can now carry emotion and character, and streaming speech models start talking before the full line is generated. The engineering changes more than you would expect, though:

  • Latency becomes visible. Speech recognition, model reasoning and synthesis stack up. Stream every stage, and let the character fill the gap naturally (“Hmm. The bridge?”) rather than standing frozen.
  • Moderation gets harder. A filtered line in a text box is a minor glitch; a voiced line that gets out cannot be unheard. Filter before synthesis, not after.
  • Consent and casting matter. The Fortnite Vader voice was built with the James Earl Jones estate’s agreement, and still drew objections from voice actors’ unions. Use licensed voices, and treat voice as a design and ethical decision, not a plug-in.
  • Text stays canonical. Keep the transcript as the record of what was said. Memory, grounding checks and replays all work on text; audio is a presentation of it.

Pictures are further out. World models such as Google DeepMind’s Genie 3, announced in August 2025, generate navigable environments from a text prompt in real time, at 720p and 24 frames per second, holding consistency for a few minutes. That is remarkable and also short. Generated video is unlikely to replace a simulation’s state any time soon; a world that forgets the bridge after five minutes cannot hold a feud for forty hours. What is likely is a split between what is true and how it is shown. The simulation keeps the ground truth, the agents reason over it in text, and a generative layer may increasingly render the result: first as voice, then as generated portraits and scenes, and eventually as interactive video conditioned on the world state. The architecture in this piece does not change when that happens. Only the last step of the pipeline does.

The near future, then, is layered rather than a world of frontier models improvising freely. Deterministic cores hold economies, needs and relationships. Utility AI and behaviour trees run the bodies. LLMs sit above as the interpretive layer, deciding what characters want and explaining what happened in their own voices. AI game designers increasingly write personalities, values and pressures, then tune the systems those things live inside, which is closer to how simulation designers already work than to traditional narrative design.

Takeaways

  • LLM agents extend a long lineage of NPC AI; each step has traded controllability for expressiveness, and LLMs make the largest trade so far. Decide which characters need a model at all.
  • Text-first conversation over hard world state is today’s practical win; voice is the next layer, and generated video may later change presentation, not ground truth.
  • The generative agents pattern of memory stream, retrieval, reflection and planning is a sound starting point for any agent NPC.
  • Cost, latency, drift, hallucinated facts, loss of control and moderation are the real obstacles, and each needs a deliberate architectural answer.
  • Run cheap utility AI or behaviour trees for moment-to-moment behaviour and call the model only at decision points.
  • Simulate with level of detail: full fidelity near the player, summaries and statistics further away.
  • Constrain model output to legal actions through structured outputs, and keep the world state as the single source of truth.
  • Emergence comes from goals, scarcity and colliding systems; the LLM’s best job is making that emergence legible.
  • Test emergent worlds with invariants, soak runs, grounding probes, recorded replays and human review.