Search

Search papers and lessons

Generative Agents: Interactive Simulacra of Human Behavior

Joon Sung Park, Joseph C. O'Brien, Carrie J. Cai et al. · 2023

Park et al. (2023) give a language model a memory stream, reflections and daily plans, so 25 simulated townspeople act consistently over two game days.

On this page

  • Colour = topic mix
  • Neural network basics
  • Calculus
  • Discrete math
  • Linear algebra
  • Probability
  • Language & LLMs
  • ReadReady to readNot yet

TL;DR

A language model answers one prompt at a time and has no memory of its own past. Park and colleagues built an architecture that lets a model act as a believable character over days. Every experience is written down in a memory stream. Relevant memories are retrieved when the character must act. Periodically the character writes reflections, higher-level conclusions drawn from its memories, and it makes plans for the day. They placed 25 such agents in a small simulated town and let them run for two game days. Without any user intervention, one agent's idea for a Valentine's Day party spread to 12 other agents, and 5 of the 12 invited agents came to the party.

Builds on: Language Model, In-Context Learning, Sentence Embedding, LLM Agent · Leads to: Retrieval-Augmented Generation, Reflexion: Language Agents with Verbal Reinforcement Learning

Why it mattered

The paper turned "a chatbot that role-plays a character" into an engineering pattern: store everything, retrieve what matters, reflect to compress, plan to stay consistent. Later work on LLM agents uses memory streams, retrieval scoring and self-reflection in similar ways. The paper's sandbox also made the idea concrete. Users could walk into the town, talk to any agent, and watch news travel. The paper has about 6,600 citations on Semantic Scholar.

The problem

A language model with a prompt such as "You are Klaus, a graduate student who likes research" can produce a plausible line of dialogue. It cannot, by itself, stay consistent for a whole day. Three gaps appear quickly.

  1. Memory. A character accumulates thousands of observations. They do not fit in a prompt, and dumping all of them makes the answer vague.
  2. Generalisation. Asked whom he would most like to spend an hour with, an agent that only has raw observations picks the person he meets most often, not the one he is actually close to.
  3. Long-horizon coherence. Asked what to do at noon, a model with no plan can say "lunch" at 12:00, 12:30 and 13:00.

The paper's answer is an architecture in which each gap gets its own mechanism, all of it written in natural language so the language model can read and write it.

How it works

The architecture runs in a loop. Here is one agent in one moment, in the order the pieces run.

  1. Observe. The agent perceives things nearby, for example "refrigerator is idle" or "Maria Lopez is studying". Each observation is stored as a memory object with a text description, a creation time and a last-access time.
  2. Score the new memory for importance. The model is asked to rate, from 1 to 10, how poignant the memory is. The paper's examples: cleaning up the room gets 2, asking a crush out on a date gets 8. The score is stored with the memory.
  3. Retrieve for the current question. Given a query, each memory gets three scores: recency (an exponential decay with factor 0.995 per game hour since last retrieval), importance (from step 2) and relevance (cosine similarity between the memory's embedding and the query's embedding). Each score is rescaled to the range 0 to 1, then added with equal weights. The top memories that fit in the model's input length (its context window) go into the prompt.
  4. Reflect. When the importance of recent events adds up past a threshold of 150, the agent asks itself three salient questions about its last 100 memories, retrieves evidence, and writes insights such as "Klaus is dedicated to his research on gentrification (because of 1, 2, 8, 15)". The insights are stored as new memories that point to their sources, so reflections can be reflected on in turn.
  5. Plan. Each morning the agent drafts a broad daily plan, then expands each block into finer steps. A plan entry names a location, a start time and a duration, for example 180 minutes from 9 am at the desk in his dorm room.
  6. React. At each step the agent compares what it perceives with its plan. If something important happens, such as a friend asking for help, it can change the plan. Then it acts, and the action becomes a new observation.

Tiny trace. Suppose the query is "what are you looking forward to?" and the memory stream holds three items, with each score already rescaled to 0 to 1. "Planning a party": recency 0.5, importance 0.8, relevance 0.9. "Cleaning the room": recency 0.9, importance 0.2, relevance 0.1. "Ordering decorations for the party": recency 0.7, importance 0.6, relevance 0.8. With equal weights the totals are 0.5 + 0.8 + 0.9 = 2.2, 0.9 + 0.2 + 0.1 = 1.2, and 0.7 + 0.6 + 0.8 = 2.1. The two party memories rank first, so they go into the prompt and the agent answers about the party. Check: the room-cleaning memory has the highest recency but only 1.2 in total, because its relevance is 0.1.

The diagram shows the loop.

flowchart LR
  O["Observation"] --> M["Memory stream"]
  M --> R["Retrieve: recency, importance, relevance"]
  R --> P["Prompt the language model"]
  M --> F["Reflection when importance sum exceeds 150"]
  F --> M
  P --> PL["Plan and react"]
  PL --> O

The math

The paper's retrieval score is a weighted sum of three rescaled quantities. Each memory mm is scored for a query qq as

score(m,q)=αrec rec(m)+αimp imp(m)+αrel rel(m,q)\mathrm{score}(m, q) = \alpha_{\mathrm{rec}}\,\mathrm{rec}(m) + \alpha_{\mathrm{imp}}\,\mathrm{imp}(m) + \alpha_{\mathrm{rel}}\,\mathrm{rel}(m, q)

where each α\alpha is a weight, set to 1 in the paper.

Step 3 in symbols: recency, importance and relevance

Recency decays with the number of game hours hh since the memory was last accessed:

rec(m)=0.995 h\mathrm{rec}(m) = 0.995^{\,h}

Importance is the integer rating imp(m)\mathrm{imp}(m) from 1 to 10 that the model gives when the memory is created. Relevance is the cosine similarity between the embedding vectors em\mathbf{e}_m and eq\mathbf{e}_q of the memory and the query:

rel(m,q)=em⋅eq∥em∥ ∥eq∥\mathrm{rel}(m, q) = \frac{\mathbf{e}_m \cdot \mathbf{e}_q}{\lVert \mathbf{e}_m \rVert\,\lVert \mathbf{e}_q \rVert}

Before summing, each of the three lists of scores over all memories is min-max rescaled: x′=(x−min⁡x)/(max⁡x−min⁡x)x' = (x - \min x)/(\max x - \min x), so every term lies between 0 and 1.

Step 4 in symbols: when to reflect

Let i1,i2,…i_1, i_2, \dots be the importance scores of the events an agent has perceived since its last reflection. A reflection runs when

∑kimp(ik)>150\sum_k \mathrm{imp}(i_k) > 150

The threshold is a design choice in the paper, and it produced about two or three reflections a day in their runs.

Results

The main evaluation has two stages. The first is a controlled interview. The second is a two-day run with all 25 agents. TrueSkill, used to rank the interview answers, is a rating system that turns pairwise comparisons into a skill score, so a higher number means the answer was preferred more often.

  • Interviews. Each agent answered 25 questions in five groups: self-knowledge, memory, plans, reactions and reflections. One hundred crowdworkers ranked the answers from several architectures for the same agent. The full architecture ranked first, with a TrueSkill score of 29.89. Removing reflection gave 26.88, removing reflection and planning gave 25.64, and removing all memory gave 21.21. Human crowdworker answers scored 22.95. Every pairwise difference was significant except between the crowdworker condition and the fully ablated baseline, the two lowest.
  • Information diffusion. Knowledge of the candidate Sam's mayoral run grew from 1 agent (4%) to 8 (32%), and knowledge of Isabella's party grew from 1 (4%) to 13 (52%). Among the agents who said they knew about the party, none had made it up.
  • Coordination. Twelve agents heard about the party, and five of the twelve invited agents showed up at the cafe.
  • Relationships. Network density rose from 0.167 to 0.74. Of 453 answers about whether an agent knew another agent, 1.3 percent (6) were hallucinated.

What these numbers mean. The ablations support the claim that each mechanism matters, and the reflection example shows a case where raw memory gives a worse answer. The emergent results show information spreading through a group without scripting it.

The limits. The agents ran on one commercial model, and the authors say erratic behaviour remained. Retrieval sometimes missed a memory the agent did have. Agents sometimes embellished memories. The bathroom in the dorm was treated as shared even though it could hold only one person, a physical rule that is hard to put in language. The authors also note that instruction tuning may make the agents more polite and cooperative than real people. The study is a single small town.

Reading guide

  • Section 1, Introduction, and Section 2, Related Work. Why believable simulation is hard and what came before. Needs Language Model.
  • Section 3, Behavior and interaction. Agent avatars, the sandbox and the example day. Needs In-Context Learning for how prompts shape behaviour.
  • Section 4.1, Memory and retrieval. The memory stream and the three scores. Needs Sentence Embedding, Cosine Similarity, Exponential Function and Min-Max Normalization.
  • Section 4.2, Reflection. How insights are generated and stored. Needs LLM Agent for the agent loop.
  • Section 4.3, Planning and reacting. Top-down daily plans. Needs Chain-of-Thought Prompting as background for step-by-step prompting.
  • Section 5, Sandbox implementation. How game world states become text. Needs LLM Agent.
  • Sections 6 and 7, Evaluation. The interview study, the TrueSkill ranking and the two-day run. The statistics use rank tests the reader does not need in detail. Focus on the claims and the ablation pattern.

Check yourself

QuestionRecall: what are the three scores the retrieval function combines, and what does recency decay with?Show answer

Recency, importance and relevance. Recency decays exponentially with the number of game hours since the memory was last accessed, with factor 0.995 in the paper.

QuestionCompute: a memory has recency 0.8, importance 6 rescaled to 0.5, and relevance 0.2, all already between 0 and 1 with weights 1. What is its retrieval score?Show answer

0.8+0.5+0.2=1.50.8 + 0.5 + 0.2 = 1.5.

QuestionWhy does the architecture store reflections as memories with pointers to the observations they came from, rather than as a separate summary?Show answer

Storing them as memories lets retrieval treat them like any other memory, so they can surface when relevant. The pointers let an insight be traced back to its evidence, and reflections can cite other reflections, which builds trees of increasing abstraction.

QuestionA simulated town agent has a plan for 9 am to noon at the library, but a friend asks for help at 10 am. Using the architecture, what should happen, and what would go wrong without the plan?Show answer

The agent reacts. It perceives the friend's request as an observation, weighs it against the plan, and may change its activity. Without a plan, the agent would choose each action from the moment alone, which is how a model ends up eating lunch three times in a row. The plan keeps the day coherent, and reacting keeps it responsive.

Sources

Read the full paper

Joon Sung Park, Joseph C. O'Brien, Carrie J. Cai et al., 2023. arXiv:2304.03442