datarekha

Generative agents: believable simulations

Most agents do tasks. Generative agents do something stranger — they simulate believable human behavior. Park et al.'s Smallville put 25 LLM agents in a sandbox town and watched a party invitation spread on its own. The engine is a memory stream with a three-factor retrieval score, periodic reflection, and planning — and it's a recipe for social simulation, not task completion.

8 min read Advanced Agentic AI Lesson 23 of 71

What you'll learn

  • What generative agents are for — believable simulation, not task completion
  • The memory stream and its recency + importance + relevance retrieval score
  • Reflection and planning — turning raw observations into behavior
  • Emergent social behavior, and the honest limits of agent simulations

Before you start

Almost every agent in this course exists to get something done — answer, code, book, search. Generative agents have a different goal: to behave believably. Park et al.’s 2023 Generative Agents paper put 25 LLM-driven characters in a sandbox town, “Smallville,” gave each a persona and a daily routine, and let them live. The striking result was emergent social behavior — one agent decided to throw a Valentine’s party, and over a simulated day the invitation spread by word of mouth, others coordinated, and some showed up — none of it scripted. The point isn’t the task; it’s the believability.

The engine: a memory stream

A believable agent needs to act consistently with everything it has experienced. The core data structure is the memory stream — a long, append-only log of observations in natural language. The hard part is retrieval: at any moment, which handful of memories should enter the prompt? Recency alone fails (the agent fixates on trivia it just saw); the paper scores each memory on three factors and takes the top-ranked:

  • Recency — how recently it was accessed (recent memories matter more, with decay).
  • Importance — how significant the memory is (mundane “ate breakfast” scores low; “had a fight” scores high), rated once when stored.
  • Relevance — similarity to the current situation or query (embedding similarity).
# Generative-agents memory retrieval: score each memory by recency + importance + relevance,
# then surface the top ones. (Park et al. normalize and sum the three factors.)
memories = [
    # (text, recency, importance, relevance-to-query)
    ("ate breakfast",          0.9, 0.1, 0.1),
    ("Isabella plans a party", 0.6, 0.9, 0.9),
    ("saw a falling leaf",     0.8, 0.1, 0.0),
    ("invited Maria",          0.5, 0.8, 0.95),
]

def retrieval_score(rec, imp, rel):
    return rec + imp + rel

scored = [(retrieval_score(rec, imp, rel), text) for text, rec, imp, rel in memories]
print("query 'the party' -> memories ranked:")
for s, text in sorted(scored, reverse=True):
    print(f"  {s:.2f}  {text}")
query 'the party' -> memories ranked:
  2.40  Isabella plans a party
  2.25  invited Maria
  1.10  ate breakfast
  0.90  saw a falling leaf

Notice what wins. “Ate breakfast” is the most recent memory, but it’s trivial and irrelevant, so it sinks. The two party-related memories rise because importance and relevance outvote raw recency — which is exactly why the agent acts on the party and not on its breakfast. Retrieving the right memories is what makes the behavior coherent.

Observe → remember → retrieve → actobserveperceive worldmemory streamappend-only observationsretrieve (score)recency + importance+ relevancetop-k into promptplan & actdecide behaviorreflectsynthesize higher-level insightsstorewrite backaction becomes the next observation
The memory stream is the hub: observations flow in, a three-factor score retrieves the relevant ones to drive action, and reflection periodically distills the stream into higher-level insights.

Reflection and planning

Raw observations aren’t enough for depth, so generative agents periodically reflect: when accumulated importance crosses a threshold, the agent asks itself “what can I conclude from recent memories?” and writes the answers — higher-level insights like “Klaus is passionate about his research” — back into the stream as new memories. Reflections can build on reflections, forming a tree of increasingly abstract self-knowledge. (This is the multi-memory cousin of single-run reflection, which critiques one attempt; here it synthesizes many memories over time.)

The agent also plans: it drafts a broad daily plan, decomposes it into hour-by-hour and then minute-by-minute actions, and revises the plan when observations contradict it (bumping into a friend reschedules the afternoon). Plans keep behavior coherent over a long day; reactions keep it responsive.

What it’s for — and what it isn’t

Generative agents are a tool for simulation, and that’s a real, growing use: believable NPCs in games, social-science experiments run in silico, agent-based modeling of crowds or markets, and testbeds for studying coordination. The believability comes from the whole loop — memory + retrieval + reflection + planning — not any one piece.

In one breath

  • Generative agents optimize for believable behavior, not task completion — Park et al.’s Smallville (25 agents) produced emergent social behavior like a party invitation spreading unscripted.
  • The core structure is the memory stream (append-only observations); retrieval scores each memory by recency + importance + relevance and takes the top-k — so meaningful memories outrank merely recent trivia (the demo: the party beats breakfast).
  • Reflection periodically synthesizes many memories into higher-level insights written back to the stream (a tree of self-knowledge), distinct from single-run reflection.
  • Planning drafts and decomposes a daily plan and revises it as observations contradict it, keeping behavior coherent yet responsive.
  • Uses: NPCs, social simulation, agent-based modeling — but it’s costly and a simulation is not evidence about real people (it echoes training-data patterns and biases).

Quick check

Quick check

0/4
Q1What distinguishes generative agents from the task-completion agents elsewhere in this course?
Q2How does a generative agent decide which memories to bring into context?
Q3What is reflection in a generative agent?
Q4What is the most important limitation to remember about generative-agent simulations?

Next

The memory stream here is a specialized agent memory tuned for retrieval; the synthesis step generalizes single-run reflection. When believable agents are organized to accomplish something rather than just live, you’re back to multi-agent orchestration.

Sign in to track your progress

Completed lessons, your XP, level, and streak save to your account — it's free and takes a few seconds.

Related lessons

Explore further

Skip to content