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.
Written and reviewed by Shreyash Prashu Last reviewed
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 characters driven by an LLM (a large language model, the text-predicting AI behind chatbots) 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 log of observations in plain language that you only ever add to, never edit. 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, and the score fades (decays) as time passes.
- 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: both texts are turned into lists of numbers, and close lists mean close meaning).
# 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.
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 (non-player characters) in games, social-science experiments run in software instead of with real people, agent-based modeling (simulating many small actors to see what the crowd does) 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
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.
Practice this in an interview
All questionsAn AI agent is an application that lets an LLM choose and execute validated tools in a bounded loop, carrying observations and state forward until it reaches a goal or needs approval. A single LLM call produces one response or tool-call proposal and stops; it does not itself provide the loop, live-system access, memory, or side effects.
Tool calling extends the LLM's output space to include structured function invocations. The model emits a JSON object naming a tool and its arguments; the runtime executes the tool and feeds the result back as a new message. An agent is a loop that repeats this cycle — observe, think, act — until the task is complete or a stopping condition is met.
Agents have transient working memory in the current context window and durable external memory, commonly organized as episodic, semantic, and procedural information. Context engineering selects and orders the right information for the limited window, while compaction compresses older state into a smaller, useful representation.
RAG couples a retrieval step — fetching relevant documents from an external store — with a generative model so the LLM can answer questions about knowledge it was never trained on. It solves the stale-knowledge and hallucination problems without retraining. The pattern is preferred when the knowledge base changes frequently or contains proprietary data.