GitHub
Examples

Long-term Memory

Archive consolidated memories for permanent storage and retrieval.

Storage Module
Scenario: Archiving major life events

When to Use

Use long-term memory for "consolidation". Only high-value episodes or summaries should move here after a session ends. Perfect for:

  • Summaries of completed projects or conversations
  • Critical life events (e.g., "Graduated college", "Moved city")
  • Core memories that define the user's history

Key Operations

archive()

Move episode data to long-term storage

retrieve()

Search archived memories

Code Example

After a stressful week where Emma's grandmother was hospitalized, we archive the summary of this event so the agent remembers it forever.

# 1. Archive a consolidated memory
client.memory.long_term.archive(
episode_id="ep_session_week2_day5",
kg_name="KG_Companion_Demo",
data={
"summary": "Nana Rose hospitalized with heart palpitations, Emma very stressed.",
"outcome": "Stabilized",
"impact": "High"
},
user_id="emma_2024",
metadata={"importance": "critical"}
)
# 2. Retrieve years later
# "What happened with Emma's grandmother?"
results = client.memory.long_term.retrieve(
query="grandmother hospitalization history",
user_id="emma_2024"
)

Key Takeaways

  • Long-term memory is for archival. Think of it as the "File Cabinet" vs Episodic's "Diary".
  • Items here are meant to be permanent and highly searchable.
  • This module supports versioning, so you can update a long-term memory as new details emerge.