Agentic Memory ๐Ÿง 

June 27, 2025 ยท View on GitHub

A novel agentic memory system for LLM agents that can dynamically organize memories in an agentic way.

Introduction ๐ŸŒŸ

Large Language Model (LLM) agents have demonstrated remarkable capabilities in handling complex real-world tasks through external tool usage. However, to effectively leverage historical experiences, they require sophisticated memory systems. Traditional memory systems, while providing basic storage and retrieval functionality, often lack advanced memory organization capabilities.

Our project introduces an innovative Agentic Memory system that revolutionizes how LLM agents manage and utilize their memories:

Traditional Memory System Our Proposed Agentic Memory
Comparison between traditional memory system (top) and our proposed agentic memory (bottom). Our system enables dynamic memory operations and flexible agent-memory interactions.

Note: This repository provides a memory system to facilitate agent construction. If you want to reproduce the results presented in our paper, please refer to: https://github.com/WujiangXu/AgenticMemory

For more details, please refer to our paper: A-MEM: Agentic Memory for LLM Agents

Key Features โœจ

  • ๐Ÿ”„ Dynamic memory organization based on Zettelkasten principles
  • ๐Ÿ” Intelligent indexing and linking of memories via ChromaDB
  • ๐Ÿ“ Comprehensive note generation with structured attributes
  • ๐ŸŒ Interconnected knowledge networks
  • ๐Ÿงฌ Continuous memory evolution and refinement
  • ๐Ÿค– Agent-driven decision making for adaptive memory management

Framework ๐Ÿ—๏ธ

Agentic Memory Framework
The framework of our Agentic Memory system showing the dynamic interaction between LLM agents and memory components.

How It Works ๐Ÿ› ๏ธ

When a new memory is added to the system:

  1. Generates comprehensive notes with structured attributes
  2. Creates contextual descriptions and tags
  3. Analyzes historical memories for relevant connections
  4. Establishes meaningful links based on similarities
  5. Enables dynamic memory evolution and updates

Results ๐Ÿ“Š

Empirical experiments conducted on six foundation models demonstrate superior performance compared to existing SOTA baselines.

Getting Started ๐Ÿš€

  1. Clone the repository:
git clone https://github.com/agiresearch/A-mem.git
cd A-mem
  1. Install dependencies: Create and activate a virtual environment (recommended):
python -m venv .venv
source .venv/bin/activate  # On Windows, use: .venv\Scripts\activate

Install the package:

pip install .

For development, you can install it in editable mode:

pip install -e .
  1. Usage Examples ๐Ÿ’ก

Here's how to use the Agentic Memory system for basic operations:

from agentic_memory.memory_system import AgenticMemorySystem

# Initialize the memory system ๐Ÿš€
memory_system = AgenticMemorySystem(
    model_name='all-MiniLM-L6-v2',  # Embedding model for ChromaDB
    llm_backend="openai",           # LLM backend (openai/ollama)
    llm_model="gpt-4o-mini"         # LLM model name
)

# Add Memories โž•
# Simple addition
memory_id = memory_system.add_note("Deep learning neural networks")

# Addition with metadata
memory_id = memory_system.add_note(
    content="Machine learning project notes",
    tags=["ml", "project"],
    category="Research",
    timestamp="202503021500"  # YYYYMMDDHHmm format
)

# Read (Retrieve) Memories ๐Ÿ“–
# Get memory by ID
memory = memory_system.read(memory_id)
print(f"Content: {memory.content}")
print(f"Tags: {memory.tags}")
print(f"Context: {memory.context}")
print(f"Keywords: {memory.keywords}")

# Search memories
results = memory_system.search_agentic("neural networks", k=5)
for result in results:
    print(f"ID: {result['id']}")
    print(f"Content: {result['content']}")
    print(f"Tags: {result['tags']}")
    print("---")

# Update Memories ๐Ÿ”„
memory_system.update(memory_id, content="Updated content about deep learning")

# Delete Memories โŒ
memory_system.delete(memory_id)

# Memory Evolution ๐Ÿงฌ
# The system automatically evolves memories by:
# 1. Finding semantic relationships using ChromaDB
# 2. Updating metadata and context
# 3. Creating connections between related memories
# This happens automatically when adding or updating memories!

Advanced Features ๐ŸŒŸ

  1. ChromaDB Vector Storage ๐Ÿ“ฆ

    • Efficient vector embedding storage and retrieval
    • Fast semantic similarity search
    • Automatic metadata handling
    • Persistent memory storage
  2. Memory Evolution ๐Ÿงฌ

    • Automatically analyzes content relationships
    • Updates tags and context based on related memories
    • Creates semantic connections between memories
  3. Flexible Metadata ๐Ÿ“‹

    • Custom tags and categories
    • Automatic keyword extraction
    • Context generation
    • Timestamp tracking
  4. Multiple LLM Backends ๐Ÿค–

    • OpenAI (GPT-4, GPT-3.5)
    • Ollama (for local deployment)

Best Practices ๐Ÿ’ช

  1. Memory Creation โœจ:

    • Provide clear, specific content
    • Add relevant tags for better organization
    • Let the system handle context and keyword generation
  2. Memory Retrieval ๐Ÿ”:

    • Use specific search queries
    • Adjust 'k' parameter based on needed results
    • Consider both exact and semantic matches
  3. Memory Evolution ๐Ÿงฌ:

    • Allow automatic evolution to organize memories
    • Review generated connections periodically
    • Use consistent tagging conventions
  4. Error Handling โš ๏ธ:

    • Always check return values
    • Handle potential KeyError for non-existent memories
    • Use try-except blocks for LLM operations

Citation ๐Ÿ“š

If you use this code in your research, please cite our work:

@article{xu2025mem,
  title={A-mem: Agentic memory for llm agents},
  author={Xu, Wujiang and Liang, Zujie and Mei, Kai and Gao, Hang and Tan, Juntao and Zhang, Yongfeng},
  journal={arXiv preprint arXiv:2502.12110},
  year={2025}
}

License ๐Ÿ“„

This project is licensed under the MIT License. See LICENSE for details.