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.
- 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
- 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
- Multiple Backends: In-memory, vector stores (NumPy/FAISS)
- Save/Load: JSON serialization for memory persistence
- Batch Operations: Efficient bulk add/delete operations
- 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
pip install agentmemoryFor development:
git clone https://github.com/hanishkeloth/agentmemory.git
cd agentmemory
pip install -e ".[dev]"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")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# 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)# 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)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
# 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']}")memory.add(
"Important event",
memory_type="episodic",
custom_metadata={
"location": "San Francisco",
"participants": ["Alice", "Bob"],
"outcome": "successful"
}
)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
)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"
)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)- 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
Run tests:
pytest tests/Format code:
black agentmemory/
ruff check agentmemory/Type checking:
mypy agentmemory/| 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
- 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
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Hanish Keloth
- GitHub: @hanishkeloth
- Email: hanishkeloth1256@gmail.com
- 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
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}
}Note: This project is in beta. APIs may change in future versions. Please report any issues or suggestions!