TAI BUI
Back to curriculum
BuildPython

Generative Agents and Emergent Simulation

Park et al. 2023 (UIST '23, arXiv:2304.03442) populated **Smallville**, a sandbox of 25 agents, with three components: a **memory stream** (a natural-language log), **reflection** (higher-level syntheses the agent writes about its own stream), and a **plan** (day-level behavior, then sub-plans). The headline result is the Valentine's Day party. One agent was seeded with "wants to throw a Valentine's Day party," nothing else was scripted, and invitations spread through the population, dates got coordinated, and the party happened, among 24 agents who started with no knowledge of it. Ablations show all three components are required for believability. The documented failures are spatial-norm errors, like entering closed stores and sharing single-person bathrooms. This is the reference architecture for agent simulations and multi-agent social evaluation in 2026.

TIME: ~75 minutesPREREQUISITES: Phase 16 · 04 (Primitive Model), Phase 16 · 13 (Shared Memory)

Learning Objectives

  • Name the three components of the Park et al. 2023 architecture (memory stream, reflection, plan) and what each contributes, using the ablation results.
  • Compute a memory's retrieval score from recency, importance, and relevance, and explain why retrieval is ranked rather than filtered.
  • Trace how one seeded goal becomes a coordinated party through observation, reflection, and plan with no central orchestrator.
  • Run the stdlib miniature, read its output, and identify which parts of the spread are hard-coded versus emergent.
  • Describe the three documented failure modes (spatial norm errors, memory overflow, reflection hallucination) and the production mitigations for them.

Problem

Most multi-agent systems are tightly scripted teams: the planner plans, the coder codes, the reviewer reviews. That works for well-defined tasks. It does not produce the unscripted behavior you get when agents have memory, priorities, and an open world. Research, society simulation, and increasingly game AI need that second kind.

Smallville is the benchmark for it. Before Park 2023, the best agent simulations were shallow script-followers. After it, the pattern became the default for generative agents in open worlds. If you build an agent simulation in 2026, you are either using Smallville's three components or you need to justify why you are not.

Warm-up0/3
1. In a shared-memory design like the blackboard from Phase 16 · 13, why is an append-only log usually safer than editing entries in place?Warm-up
Two logs: Style A overwrites entry 2 in place, Style B keeps entries 1 to 3 and adds a new entry 4.
Setup only; both styles are shown, neither is marked correct.
2. Two agents each hold private state and only exchange messages. What makes such a system decentralized?Warm-up
Agent A and Agent B each hold private state and exchange messages directly, with a dashed box asking why this counts as decentralized.
Setup only; no coordinator is drawn one way or the other.
3. Two embedding vectors point in nearly the same direction. What does their cosine similarity look like?Warm-up
Two arrows, u and v, from the same origin pointing in nearly the same direction, with a dashed box asking for their cosine similarity.
Angle between u and v is small (about 15 degrees).
Check: Problem0/1
1. Per the Problem section, what separates a tightly-scripted agent team from a Smallville-style system?Explain
A scripted team card with fixed planner, coder and reviewer roles beside an open-world system card with two unknown traits.
Typed schematic; roles taken from the Problem section.

Concept

The three components

Memory stream. An append-only log of observations, actions, reflections, and plans. Each entry has a timestamp, a type, a description in natural language, and derived metadata: recency, importance (self-rated 1-10 by the agent), and relevance (cosine similarity to the current query).

[2026-02-14 09:12:03] observation: Isabella Rodriguez asked me if I like jazz
[2026-02-14 09:14:22] reflection:   I enjoy long conversations about music
[2026-02-14 10:05:00] plan:         Attend Isabella's Valentine's Day party tonight

Retrieval combines the three scores: score = w_recency * e^(-decay * age) + w_importance * importance + w_relevance * cos_sim. The top-k entries go into the current prompt.

Reflection. Every N memories, or on an important event, the agent generates higher-order syntheses from its recent memories. Reflection entries go back into the stream and are retrievable like any other memory. This is how agents build "understandings", the architecture's version of long-term beliefs.

Plan. Top-down decomposition. First a day-level plan in broad strokes ("go to work, have dinner with Klaus"), then hour-level plans, then action-level plans. Plans are revisable: when an observation contradicts a plan, the agent replans the affected segment.

Why all three matter (ablation)

Park et al. ran ablations that dropped observation, reflection, and plan in turn. Each ablation hurts believability:

  • Without observation the agent misses context and acts on stale beliefs.
  • Without reflection the agent cannot form higher-order beliefs, so interactions stay shallow.
  • Without plan behavior becomes reactive noise and goals dissipate.

Human raters score believability highest with all three present, and dropping any one produces a measurable regression.

The Valentine's Day emergence

One agent, Isabella Rodriguez, is seeded with the goal "wants to throw a Valentine's Day party at Hobbs Cafe on Feb 14 at 5pm." The 24 other agents receive no such seed. Over simulated days:

  1. Isabella's plan includes inviting people.
  2. Each invitation becomes an observation in a neighbor's memory stream.
  3. That neighbor's reflection generates beliefs: "Isabella is throwing a party."
  4. The neighbor's plan incorporates "attend party on Feb 14."
  5. Neighbors tell other neighbors. The invitation spreads without central coordination.
  6. At 5pm on Feb 14, several agents converge at Hobbs Cafe.

This is emergence in the technical sense. System-level behavior (a party) came out of local interactions (bilateral invitations plus individual planning) with no central orchestrator.

The documented failure modes

Park et al. explicitly document three:

  • Spatial norm errors. Agents walk into closed stores, try to use the same single-person bathroom, and eat in rooms not meant for eating. The model does not infer social-physical norms from the environment alone.
  • Memory overflow. In deep simulation runs, the cost of memory retrieval grows. The practical remedy is periodic memory compaction (summarize and prune) plus decay on low-importance entries.
  • Reflection hallucination. Reflections can invent relationships that are not in the memory stream. Mitigate by including source memory ids in reflection prompts and verifying them at retrieval time.

These show up in production, so any 2026 agent simulation inherits them.

Three-component implementation rules

  1. Memory is append-only. Don't mutate a memory entry. Corrections are new entries.
  2. Importance scores are cheap. Call the LLM to rate importance 1-10 at write time and cache the score.
  3. Retrieval is ranked, not filtered. Take the top-k by combined score. Hard filters lose context.
  4. Reflection runs periodically. Trigger it when the sum of importance of unprocessed memories exceeds a threshold (e.g., 150).
  5. Plans are revisable. When a new observation contradicts a plan, regenerate the affected segment only, not the whole plan.

Generative agents beyond Smallville

The 2024-2026 follow-up literature extends the architecture:

  • Multi-agent social simulation for policy and market research. Smallville-like populations simulate user behavior in response to features. It is faster than an A/B test, though the accuracy is contested.
  • NPC AI for games. RPGs built on Smallville agents produce emergent storylines instead of scripted quests.
  • Generative-agent evaluation benchmarks. The metric stops being task accuracy and becomes believability and coherence of behavior over long runs.

The architecture is the reference. Extensions swap components (a vector store for memory, retrieval-augmented reflection, a neurosymbolic plan) but keep the three-part structure.

Why this matters for multi-agent engineering

Smallville is the proof of concept that multi-agent emergence is cheap when the components are right. The architecture has since been replicated on open-source models, and smaller LLMs lose believability gracefully rather than sharply. A production system that needs emergent social behavior takes this shape. A system that needs tight task execution should use the supervisor, roles, and primitives patterns from earlier in this phase.

Check: Concept0/21
1. What is a memory stream?Define
Three rows from one agent's stream: a timestamped observation, a reflection, and a plan, each a short natural-language line.
Excerpt is the lesson's own worked example.
2. What does a memory's recency score represent?Define
Three memory cards written 0, 2 and 5 ticks ago, each with its recency score shown as a question mark.
Ages are illustrative; no formula shown.
3. How is a memory's importance score produced?Define
A memory's importance shown as a question mark at write time and again at two later retrievals.
Typed schematic; the same unknown value appears at all three points.
4. In retrieval scoring, what does the relevance term measure?Define
A query box and a candidate memory box, with a dashed box asking for the relevance between them.
Typed schematic; text taken from the lesson's own retrieval example.
5. What is a reflection?Define
Three recent memories pointing into a dashed box, which points back down toward the stream, asking what that box is.
Typed schematic.
6. What is a plan in this architecture?Define
A day, hour and action level, each unfilled, with a warning mark below asking what happens when an observation contradicts a step.
Typed schematic of the three plan levels.
7. What is Smallville?Define
A row of small houses next to a card asking for the number of agents and the paper that describes this sandbox.
Typed schematic; the house count is not the agent count.
8. What does believability measure for a generative agent?Define
A finished simulation run pointing to a dashed box asking what metric scores it.
Typed schematic.
9. Which three components make up the Park et al. 2023 Smallville architecture?Define
An architecture box holding three unlabeled component slots.
Typed schematic.
10. What does the retrieval score in the Concept section combine?Define
A formula with three blank terms summed to a score, feeding the top-k entries into the current prompt.
Typed schematic of the retrieval formula's shape.
11. Which implementation rule from the Concept section governs how memory entries are treated?Define
A memory entry that needs a correction, pointing to a dashed box asking what happens to it.
Typed schematic.
12. Which documented failure mode has agents entering closed stores or sharing a single-person bathroom?Define
An agent entering a closed store and several agents waiting for a single-person bathroom, with a dashed box asking which failure mode this is.
Scenario from the lesson's documented failure modes.
13. According to the ablation findings in the Concept section, what is lost when reflection alone is removed?Explain
Observation and plan present, reflection removed, with a dashed box asking the effect on behavior.
Typed schematic of one ablation.
14. Why does retrieval rank memories by combined score and take the top-k instead of applying hard filters?Explain
A memory that is weak on recency but strong on importance and relevance, with two dashed boxes asking whether a recency filter or a ranked top-k keeps it.
Typed schematic.
15. Why can the Valentine's Day party form with no central orchestrator?Explain
Isabella seeded with the party goal next to four agents with no seed, with a dashed box asking how the party still happens.
Only Isabella is seeded, matching the Concept section.
16. When should reflection trigger, per the Concept section's implementation rules?Explain
A bar of unprocessed memories with growing total importance and an unlabeled threshold mark, asking when reflection fires.
Illustrative bar; importance values are placeholders.
17. A new observation contradicts part of an agent's plan. What does the Concept section say to do?Explain
Three plan segments, hour A, B and C, with a contradiction marker under hour B and a dashed box asking what gets redone.
Typed schematic.
18. Why do deep simulation runs need periodic memory compaction?Explain
A memory stream growing across many ticks next to a clock icon marking rising retrieval cost, with a dashed box asking what keeps retrieval fast.
Typed schematic.
19. In an ablation run, agents notice events and form beliefs about them, yet their behavior looks like reactive noise and their goals dissipate. Which component was removed?Analyze
Observation and reflection present, plan removed, with a dashed box asking the effect on behavior.
Typed schematic of a different ablation than check-4.
20. You run a 200-agent simulation. An agent's reflection says "Maria is my close friend," but no memory shows any contact with Maria. Which mitigation from the Concept section fits best?Analyze
A reflection claiming a close friendship with no supporting memory, and a dashed box asking for the mitigation.
Scenario matches the stem's 200-agent run.
21. A team needs agents to triage support tickets through fixed review steps with tight completion guarantees. Which design fits?Design
A ticket-triage system with fixed review steps and tight guarantees, next to two unnamed candidate patterns.
Typed schematic; pattern names withheld.

Build It

code/main.py implements the three components in stdlib Python with scripted agent policies and no real LLM. It reproduces the Valentine's-party emergence in miniature:

  • Memory and Agent.stream: an append-only list of observations, reflections, and goals, each with a timestamp and an importance score.
  • retrieve_top_k(stream, query, tick, k): ranks memories by recency, importance, and relevance. Relevance here is keyword overlap, not embedding similarity.
  • Agent.reflect(tick): scripted reflection over recent high-importance memories.
  • Agent.update_plan(tick): adds a plan to attend the party once the agent holds the matching belief.
  • Scenario: 5 agents over 6 ticks. Agent 0 starts with a goal to host a party at tick 5. Invitations spread on a fixed schedule, and the agents converge.

Run:

python3 code/main.py

Expected output: a tick-by-tick trace, then final locations, then a small retrieval demo. In the default run all 5 agents move to HobbsCafe at tick 5. One seed produced the coordinated arrival without any orchestrator.

Check: Build It0/5
1. retrieve_top_k scores a memory as exp(-0.3 * age) + importance/10 + relevance, with relevance 0.6 on a keyword hit and 0.1 otherwise. At tick 4 with query 'party cafe', the stream is: t=0 'saw Isabella at the cafe' (importance 4), t=1 'Isabella said she is planning a party' (7), t=2 'I would enjoy a party at the cafe' (6), t=3 'Klaus mentioned he is writing a paper' (3). With k=3, which memory is left out?Apply
A four-row table of the stream at tick 4 with timestamp, importance and content, plus a dashed box noting k equals 3 and asking for the scores.
Table reproduces the stem's four memories exactly.
2. In run_simulation, agent-3's tick-1 invitation is observed with importance 5 instead of 7. What is the final count at HobbsCafe?Apply
A table of five agents with their invitation tick and importance; agent-3's importance is highlighted as 5 instead of 7, with a dashed box for the final count.
Values taken directly from the stem.
3. You delete the a.reflect(tick) call from the simulation loop and rerun. How many agents end at HobbsCafe?Apply
The per-tick loop with the reflect call removed and update_plan plus act still running, with a dashed box for the final count.
Typed schematic of the stem's change.
4. You change `run_simulation` to use 10 agents and only agents 0 to 4 arrive at HobbsCafe. What explains it, per the Author's Note?Apply
Agents 0 to 4 at HobbsCafe and agents 5 to 9 at home, with a question asking why the second group is never invited.
Outcome stated in the stem; a real run of the same logic with 10 agents confirms it.
5. A teammate says the miniature shows agents deciding whom to invite. What is wrong with that claim?Analyze
A quoted claim that agents decide whom to invite, above five agent boxes, with a dashed box asking if the claim is right.
Quote from the stem.

Use It

outputs/skill-simulation-designer.md designs a generative-agent simulation. It covers the number of agents, memory schema, reflection cadence, plan horizon, and evaluation metric.

Ship It

Rules for production simulations:

  • Memory is the database. Pick a real store (vector DB, Postgres) at scale. In-memory stdlib is for prototypes.
  • Log the retrieval trace. For each action, log the top-k memories that drove it. This is how you debug.
  • Budget per-agent tokens. An agent's retrieve, reflect, and plan steps cost O(k) LLM calls per tick. N agents × T ticks × calls per tick can dwarf your budget.
  • Compact memory periodically. Summarize and prune low-importance entries. Retention policy is a design decision, not a detail.
  • Detect spatial and social norm violations explicitly. The architecture does not learn them.
Check: Ship It0/3
1. Why does the Ship It section say to log the top-k memories behind every action?Explain
An agent action pointing to a dashed box asking which memories were used, with a question about why that list gets logged.
Typed schematic.
2. In a long run, agents keep walking into closed stores and several try to use the same single-person bathroom. Which fix matches the lesson?Analyze
The same closed-store and shared-bathroom scenes as check-5, with a dashed box asking for the fix.
Same scenario as check-5; this question asks for the mitigation, not the name.
3. You plan a 100-agent, 30-day simulation where each agent retrieves, reflects, and plans every tick. Which design best controls cost?Design
A rising cost curve for 100 agents over 30 days with retrieve, reflect and plan every tick, and a dashed box asking what controls the spend.
Figures from the stem.
Author's Note

I'd run main.py before rereading the concepts. The trace is short: invitations at ticks 0 to 2, nothing at ticks 3 and 4, and then all five agents move to HobbsCafe at tick 5. Read it next to run_simulation and you can trace which line caused each move.

What you'll notice is how much of the spread is hard-coded. Agent 0 invites agents 1 and 2 at tick 0, agent 1 invites agent 3 at tick 1, and agent 2 invites agent 4 at tick 2, all as fixed if tick == branches. The code demonstrates the pipeline from observation to reflection to belief to plan, not agents deciding whom to tell. That is why exercise 1 needs real work: with 10 agents, agents 5 through 9 are never invited and stay home, so you have to extend the invitation schedule before the question means anything.

I'd also keep the miniature in proportion to the paper. Retrieval adds recency, importance, and relevance with equal weight, uses a decay of 0.3, and scores relevance as 0.6 for a keyword hit and 0.1 otherwise, where the paper's formula uses embedding similarity. Reflection is a string match on "invited" and "party at", so the reflection-hallucination failure and its source-id check never come up here. If you want to feel that failure, swap in an LLM for reflect and log which memories each belief came from.

Exercises

  1. Run code/main.py. Confirm 3+ agents converge at the party. Increase agents to 10. Does the emergence still happen?
  2. Remove the reflection step. What does behavior look like? Map to the ablation finding in Park 2023.
  3. Introduce a competing seeded goal ("Klaus wants to give a research talk at 5pm"). Do agents split, or does one goal dominate? What determines it?
  4. Add spatial constraints: Hobbs Cafe holds at most 4 agents. Does the simulation handle overflow gracefully, or does it hit the "single-person bathroom" failure pattern?
  5. Read Park et al. (arXiv:2304.03442) Section 6 (emergent behavior experiments). Identify one behavior not reproducible in your miniature. What component of the architecture would you need to enhance?

Key Terms

TermWhat people sayWhat it actually means
Memory stream"The agent's diary"Append-only log of observations, actions, reflections, plans.
Recency"How new is the memory"Exponential-decay score by age.
Importance"How much does the agent care"Self-rated 1-10 at write time. Cached.
Relevance"How related to the current query"Cosine similarity (embedding-based).
Reflection"Higher-order belief"Synthesis generated from recent memories, re-ingested as a new memory.
Plan"Day/hour/action decomposition"Top-down plan tree. Revisable when observations contradict.
Smallville"Park 2023's sandbox"25-agent simulation that produced the Valentine's Day emergence.
Believability"The quality metric"Human-rater score for whether behavior seems like a plausible agent.

Further Reading

Code

Ships With