What if a video game character could remember what happened to it yesterday, form an opinion of the neighbors, and decide for itself what to do today? A Stanford and Google team built a tiny town to find out. Twenty-five characters live in it, each run by a language model. They wake up, make breakfast, go to work and talk to each other.
The paper calls them generative agents. The headline story is a party. A user gave one agent the idea of throwing a Valentine's Day party, and then stepped back. The town did the rest.
Generative agents are language-model characters with a memory. The design has three parts: a memory stream that records everything in plain English, retrieval that picks the few memories that matter right now, and reflection that turns many memories into insights. In tests, each part made the agents more believable.
A small town of 25
The world is called Smallville, a sprite-based town like The Sims, with houses, a cafe, shops and a park. Each agent starts with a short description in plain English: a name, a job, a few traits and a few relationships. Then the simulation runs. Agents plan their days, walk to places, chat when they meet and update their plans when something happens.
Two things were planted by the researchers. One agent, Isabella, was given the intent to throw a Valentine's Day party. Another, Maria, had a crush on Klaus. Everything else, including spreading the word, decorating the cafe and asking each other out, came from the agents themselves.
Over two game days, the number of agents who knew about the party rose from one to thirteen of the twenty-five. News of one agent's run for mayor rose from one to eight. The town's friendship network went from sparse to dense. When the team checked what agents claimed to know, only about 1.3 percent of the answers about other agents were found to be made up.
The hard part: a memory that scales
A language model can only read a limited amount of text at once. A character that lives for days piles up thousands of events. If you paste them all in, the prompt overflows. If you paste a few, the character forgets who it is.
The paper's answer is a memory stream: a long list of everything the agent experiences, written in plain English, each with a time stamp. Before the agent acts, a retrieval step looks at the situation and selects the few memories most worth showing the model. Each memory gets a score from three ingredients:
- Recency. Newer memories score higher. In the paper this fades by a factor of 0.995 for every game hour since the memory was last used.
- Importance. The language model rates each memory from 1 to 10. Brushing teeth is a 1. A breakup or a college acceptance is near 10.
- Relevance. How close the memory is in meaning to what is happening now, found by comparing embeddings.
Each ingredient is scaled to between 0 and 1, then added together with equal weight. The best-scoring memories that fit in the prompt are what the agent "remembers" at that moment.
Try it: be the memory
This agent has eight memories. Pick a question and see which three get into the prompt. Then change the weights to see what happens if the agent cares only about recent events, or only about important ones.
Reflection and planning
Raw memories do not make a personality. The agents also reflect. When the importance of recent events adds up past a threshold of 150, the agent looks at its latest 100 memories, asks itself what the most important questions are, and writes down higher-level insights. In the paper's example an agent who spends hours on research notes that he is passionate about his work. The agents reflected two or three times a day. Reflections go into the memory stream, so they can be retrieved like any other memory.
They also plan. An agent writes a rough plan for the day first, then breaks it into smaller steps, and changes the plan if something surprising happens, such as meeting a neighbor with news.
Does each part matter?
The authors "interviewed" agents with questions about themselves, their plans and what they knew, and asked 100 people to rank the believability of different answers. They compared the full design against versions with parts removed, and against answers written by human crowdworkers pretending to be the character.
| Version of the agent | Believability score |
|---|---|
| Full design: memory, reflection and planning | 29.89 |
| No reflection | 26.88 |
| No reflection and no planning | 25.64 |
| Answers written by human crowdworkers | 22.95 |
| No memory at all (the earlier approach) | 21.21 |
Each missing part lowered the score. The full design was ranked most believable, ahead of even the human-written answers. The paper reports an effect size of more than eight standard deviations between the full design and the version with no memory, no planning and no reflection.
The agents are not perfect. The paper reports that they sometimes fail to find a memory they had, embellish the details of what they remember, or follow the wrong social rule, such as treating a one-person bathroom as shared. The authors also warn that people might form parasocial relationships with such agents, and recommend keeping logs of what they say.
Key takeaways: Characters built on language models need a memory system, because the model can only read so much at once. Retrieval scores memories by recency, importance and relevance. Reflection turns many memories into a few lasting insights. Believable group behavior, such as a party, can emerge without a script.
Go deeper
- Read the original: Generative Agents: Interactive Simulacra of Human Behavior (Park et al.)
- Long-term memory for agents: how agents store and recall more than fits in a prompt
- Planning and task decomposition: turning a goal into small steps
- Multi-agent systems and collaboration: what changes when many agents talk to each other
