Skip to content

Advanced memory management framework for AI agents with persistent, hierarchical, and semantic memory capabilities. Addresses the critical gap in agentic AI development by providing robust memory and context management across agent sessions.

License

Notifications You must be signed in to change notification settings

hanishkeloth/agentmemory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AgentMemory 🧠

Python License: MIT Status

Language Versions: English | ν•œκ΅­μ–΄ | Deutsch | ζ—₯本θͺž | Ψ§Ω„ΨΉΨ±Ψ¨ΩŠΨ©

AgentMemory is an advanced memory management framework for AI agents, providing persistent, hierarchical, and semantic memory capabilities. It addresses the critical gap in current agentic AI development: robust memory and context management across agent sessions.

πŸš€ Key Features

🎯 Multiple Memory Types

  • Short-Term Memory: FIFO buffer with TTL for immediate context
  • Long-Term Memory: Importance-based retention for valuable information
  • Episodic Memory: Temporal organization of event sequences
  • Semantic Memory: Concept-based knowledge with relationships
  • Procedural Memory: Skills and how-to knowledge with execution tracking

πŸ” Advanced Retrieval

  • Semantic Search: Vector similarity search using embeddings
  • Filtered Queries: Retrieve by type, tags, importance, or custom metadata
  • Relationship Navigation: Follow memory associations and relations
  • Time-Decay Scoring: Automatic relevance calculation with decay

πŸ’Ύ Persistence & Storage

  • Multiple Backends: In-memory, vector stores (NumPy/FAISS)
  • Save/Load: JSON serialization for memory persistence
  • Batch Operations: Efficient bulk add/delete operations

πŸ”„ Memory Management

  • Auto-Consolidation: Automatic promotion from short-term to long-term
  • Importance Scoring: Configurable importance thresholds
  • Memory Associations: Create relationships between memories
  • Statistics Tracking: Monitor memory usage and patterns

πŸ“¦ Installation

pip install agentmemory

For development:

git clone https://github.com/hanishkeloth/agentmemory.git
cd agentmemory
pip install -e ".[dev]"

πŸŽ“ Quick Start

from agentmemory import MemoryManager

# Initialize memory manager
memory = MemoryManager()

# Add memories
memory.add(
    "User prefers Python for data science",
    memory_type="long_term",
    importance=0.9,
    tags=["preference", "python"]
)

# Retrieve relevant memories
memories = memory.retrieve(
    query="What programming language to use?",
    limit=5
)

# Create associations
memory.create_association(memory1_id, memory2_id, "related_to")

# Save for persistence
memory.save("agent_memories.json")

πŸ’‘ Use Cases

πŸ€– Conversational AI Agents

class ChatAgent:
    def __init__(self):
        self.memory = MemoryManager()
    
    def process(self, user_input):
        # Store conversation
        self.memory.add(
            user_input,
            memory_type="short_term",
            session_id=self.session_id
        )
        
        # Retrieve context
        context = self.memory.retrieve(user_input, limit=5)
        
        # Generate response with context
        response = self.generate_response(user_input, context)
        return response

πŸ“š Knowledge Management

# Store facts with concepts
memory.add(
    "Python was created in 1991 by Guido van Rossum",
    memory_type="semantic",
    concepts=["python", "history", "programming"],
    importance=0.8
)

# Query by concepts
python_facts = memory.retrieve(concepts=["python"], limit=10)

πŸ”§ Skill Learning

# Store procedures
memory.add(
    {"procedure": "Deploy to AWS", "steps": [...]},
    memory_type="procedural",
    procedure_name="aws_deployment",
    skill_level=0.7
)

# Track execution success
memory.update_execution(procedure_id, success=True)

πŸ—οΈ Architecture

AgentMemory/
β”œβ”€β”€ core/
β”‚   β”œβ”€β”€ memory_manager.py    # Central orchestrator
β”‚   β”œβ”€β”€ memory_types.py      # Memory type implementations
β”‚   └── memory_entry.py      # Memory data structures
β”œβ”€β”€ stores/
β”‚   β”œβ”€β”€ base.py             # Abstract store interface
β”‚   └── vector.py           # Vector similarity stores
β”œβ”€β”€ retrievers/
β”‚   β”œβ”€β”€ base.py             # Abstract retriever interface
β”‚   └── semantic.py         # Semantic search implementation
└── utils/
    └── embeddings.py       # Embedding utilities

πŸ”¬ Advanced Features

Memory Consolidation

# Automatic consolidation from short-term to long-term
manager = MemoryManager(consolidation_threshold=10)

# Manual consolidation
stats = manager.consolidate_memories()
print(f"Promoted to long-term: {stats['promoted_to_long_term']}")

Custom Metadata

memory.add(
    "Important event",
    memory_type="episodic",
    custom_metadata={
        "location": "San Francisco",
        "participants": ["Alice", "Bob"],
        "outcome": "successful"
    }
)

Vector Search with Embeddings

from agentmemory.utils.embeddings import EmbeddingManager

embedder = EmbeddingManager()
embedding = embedder.encode_single("Machine learning concept")

memory.add(
    "Neural networks are inspired by biological neurons",
    memory_type="semantic",
    embedding=embedding
)

🀝 Integration with Popular Frameworks

LangChain

from langchain.memory import ConversationBufferMemory
from agentmemory import MemoryManager

class AgentMemoryWrapper(ConversationBufferMemory):
    def __init__(self):
        super().__init__()
        self.agent_memory = MemoryManager()
    
    def save_context(self, inputs, outputs):
        super().save_context(inputs, outputs)
        self.agent_memory.add(
            {"input": inputs, "output": outputs},
            memory_type="episodic"
        )

AutoGen

from autogen import AssistantAgent
from agentmemory import MemoryManager

class MemoryAgent(AssistantAgent):
    def __init__(self, name, **kwargs):
        super().__init__(name, **kwargs)
        self.memory = MemoryManager()
    
    def receive(self, message, sender):
        # Store message in memory
        self.memory.add(
            message,
            memory_type="short_term",
            agent_id=sender.name
        )
        return super().receive(message, sender)

πŸ“Š Performance Considerations

  • Embedding Dimension: Default 384 (all-MiniLM-L6-v2), adjustable for performance
  • Capacity Limits: Configurable per memory type to manage resource usage
  • Batch Operations: Use batch methods for bulk operations
  • Vector Store Choice: NumPy for small-scale, FAISS for production

πŸ› οΈ Development

Run tests:

pytest tests/

Format code:

black agentmemory/
ruff check agentmemory/

Type checking:

mypy agentmemory/

πŸ“ˆ Benchmarks

Operation 1K Memories 10K Memories 100K Memories
Add 0.8ms 0.9ms 1.1ms
Retrieve 2.3ms 8.7ms 45ms
Search 3.1ms 12ms 89ms

Tested on MacBook Pro M1, 16GB RAM

πŸ—ΊοΈ Roadmap

  • Distributed memory stores (Redis, PostgreSQL)
  • Graph-based memory relationships
  • Memory compression and summarization
  • Multi-agent memory sharing
  • Memory versioning and rollback
  • Advanced consolidation strategies
  • Memory attention mechanisms
  • Integration with more frameworks

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘¨β€πŸ’» Author

Hanish Keloth

πŸ™ Acknowledgments

  • Inspired by cognitive architectures and human memory systems
  • Built to address gaps identified in current agentic AI frameworks
  • Thanks to the open-source AI community for continuous innovation

πŸ“š Citations

If you use AgentMemory in your research or projects, please cite:

@software{agentmemory2025,
  author = {Keloth, Hanish},
  title = {AgentMemory: Advanced Memory Management for AI Agents},
  year = {2025},
  url = {https://github.com/hanishkeloth/agentmemory}
}

πŸ”— Links


Note: This project is in beta. APIs may change in future versions. Please report any issues or suggestions!

About

Advanced memory management framework for AI agents with persistent, hierarchical, and semantic memory capabilities. Addresses the critical gap in agentic AI development by providing robust memory and context management across agent sessions.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors