Memory

Short Term MemoryLong Term Memory
Psychologylasts for 15-30 secondslasts for more than 30 seconds
LLMcurrent sessionshared across multiple sessions

Short Term Memory

  • aka Thread scoped memory or working memory
  • tracks ongoing conversation by maintaining message history
  • LangGraph uses State and Checkpointer to achieve this

Long Term Memory

  • user specific or application data
  • shared across conversational threads
  • can be implemented with Vector Stores
  • Based on Human Psychology LTM is classified further
  • Types
    • Semantic Memory
    • Episodic Memory
    • Procedural Memory
  • LTM implementation depends on
    • what kind of memory?
    • when do you want to update the memories?
      • in the hot path
      • background async
LTM TypeWhat is StoredPsychology ExampleAgent Example
SemanticFactsThings I learned in schoolFacts about a user
EpisodicExperiencesThings I didPast agent actions
ProceduralInstructions/
Rules
Instincts or motor skillsAgent system prompt

Semantic Memory

  • can be implemented by semantic search by vector DB
  • fact based, when and how does not matter
  • examples
    • user preferences
    • domain knowledge

Episodic Memory

  • can be implemented by key-value structured DB
  • save memories as episodes indexed by time and topic
  • what happened when type questions
  • examples
    • multi-sessions to remember previous sessions
    • coaching agents to track progress over time

Procedural Memory

  • handled by fine tuning and prompts
  • capture “how-to” knowledge
  • examples
    • reusable skills
    • multi-steps tasks like data pipelines or API integrations

Cognitive Architectures

Memory Consolidation

  • Merge, deduplicate, and strengthen memories

Memory Compaction

  • Compress stored memories with summaries, entity extraction, or distillation

Memory Decay

  • Give more weight to recent memories compared to old memories
  • Versioning of memories can help
  • Forget on purpose

Tools

  • Mem0
  • Zep

Production

  • Caching frequently used memories
  • TTL policies to remove stale memories
  • Horizontal sharding
  • Backup and Recovery
  • GDPR and PII
  • Observability
  • Cost management