Back to Research Papers

Generative Agents: Interactive Simulacra of Human Behavior

View on arXiv2023Memory & Context Management

Authors: Park, O'Brien, Cai, et al. (Stanford)

Abstract

Generative Agents introduces believable simulacra of human behavior by combining LLMs with a comprehensive memory and reflection architecture. The key innovation is a retrieval algorithm that balances recency, importance, and relevance to determine which memories should influence agent behavior.

Key Contributions

  • 1.Memory importance scoring (1-10 scale via LLM judgment)
  • 2.Recency decay using exponential function
  • 3.Relevance via embedding cosine similarity
  • 4.Weighted combination formula for memory retrieval
  • 5.Reflection mechanism for higher-level insights
  • 6.Demonstrated in Smallville - 25 agents living and interacting

Implementation in Awareness

Awareness uses the Generative Agents formula directly:

Retrieval Score Formula:

```

Score = α₁ × Recency + α₂ × Importance + α₃ × Relevance

```

Recency Component:

- Exponential decay: `decay_factor ^ hours_since_access`

- Default decay: 0.995 per hour

- Recent memories naturally score higher

Importance Component:

- LLM scores each memory 1-10 on creation

- "On a scale of 1-10, how important is this information?"

- Normalized to 0-1 range for scoring

Relevance Component:

- Cosine similarity of embeddings

- Current query vs. stored memory

- Semantic matching ensures topical relevance

Configurable Weights (α₁, α₂, α₃):

- Default: 1.0 for each factor (equal weighting)

- Tunable based on use case

- Can emphasize recency or importance as needed

Code Example

// Generative Agents scoring in Awareness
function calculateRetrievalScore(
  memory: Memory,
  query: string,
  currentTime: Date
): number {
  const hoursSinceAccess =
    (currentTime - memory.lastAccessedAt) / (1000 * 60 * 60);

  const recency = Math.pow(0.995, hoursSinceAccess);
  const importance = memory.importanceScore / 10; // Normalize to 0-1
  const relevance = cosineSimilarity(
    memory.embedding,
    embedQuery(query)
  );

  return (
    RECENCY_WEIGHT * recency +
    IMPORTANCE_WEIGHT * importance +
    RELEVANCE_WEIGHT * relevance
  );
}

Usage in Awareness

Foundational algorithm for scoring recency, importance, and relevance in memory retrieval

Related Papers