Observed since 20 Oct, 22:40 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
A Python package for managing AI agent memory systems with persistence and vector search
A Python package for managing agent memory systems with persistence and semantic search capabilities.
AgentMem provides implementations of three core memory types essential for AI agents:
Each memory type supports:
pip install agentmem
Or install from source:
git clone https://github.com/maxgoff/memory.git
cd memory/agentmem
pip install -e .
pip install "numpy<2"from agentmem import SemanticMemory, EpisodicMemory, ProceduralMemory
# Create in-memory instances
semantic_mem = SemanticMemory()
episodic_mem = EpisodicMemory()
procedural_mem = ProceduralMemory()
# Store semantic facts
fact_id = semantic_mem.create(
content="Paris is the capital of France",
category="geography",
tags=["cities", "countries", "europe"]
)
# Store episodic experiences
event_id = episodic_mem.create(
content="User asked about Python file handling",
context={"user_id": "user123", "session": "abc456"},
importance=7
)
# Store procedural knowledge
procedure_id = procedural_mem.create(
content="Creating files in Python",
task="Create a new file",
steps=[
"Use open() with 'w' mode to create a file",
"Write content using the write() method",
"Close the file using close() or with statement"
],
domains=["programming", "python", "file operations"]
)
# Query memories
paris_facts = semantic_mem.query("Paris")
file_procedures = procedural_mem.query("file", domain="python")
recent_questions = episodic_mem.query("asked", min_importance=5)
Stores factual knowledge like "Paris is the capital of France".
from agentmem import SemanticMemory
# Create with persistence and vector search
semantic_mem = SemanticMemory(
persistence="./memory_data", # Enable file persistence
vector_search=True, # Enable vector search
vector_db_path="./vector_db" # Vector database location
)
# Create facts
fact_id = semantic_mem.create(
content="The Pacific Ocean is the largest ocean on Earth",
category="geography",
tags=["oceans", "earth", "water"]
)
# Read facts
fact = semantic_mem.read(fact_id)
print(fact["content"]) # "The Pacific Ocean is the largest ocean on Earth"
# Update facts
semantic_mem.update(
fact_id,
tags=["oceans", "earth", "water", "geography"]
)
# Delete facts
semantic_mem.delete(fact_id)
# Query facts
# Standard keyword search
ocean_facts = semantic_mem.query("ocean", category="geography")
# Vector semantic search (conceptually similar items)
water_bodies = semantic_mem.query("large bodies of water")
Stores experiences and events with temporal context.
from agentmem import EpisodicMemory
from datetime import datetime, timedelta
episodic_mem = EpisodicMemory(persistence="./memory_data")
# Create event memory
yesterday = datetime.now() - timedelta(days=1)
event_id = episodic_mem.create(
content="User asked how to open files in Python",
timestamp=yesterday,
context={"user_id": "user123", "topic": "python_files"},
importance=7
)
# Time-based queries
last_week = datetime.now() - timedelta(days=7)
recent_events = episodic_mem.query(
"", # Empty query matches all content
start_time=last_week,
end_time=datetime.now()
)
# Importance-based queries
important_events = episodic_mem.query("", min_importance=7)
# Context-based queries
user_events = episodic_mem.query(
"Python",
context_keys=["user_id", "topic"]
)
Stores knowledge about how to perform tasks.
from agentmem import ProceduralMemory
procedural_mem = ProceduralMemory(persistence="./memory_data")
# Create procedural memory
proc_id = procedural_mem.create(
content="Installing a Python package",
task="Install a package with pip",
steps=[
"Open a terminal or command prompt",
"Run 'pip install package-name'",
"Verify installation with 'pip list'"
],
prerequisites=["Python installed", "Internet connection"],
domains=["python", "package management"]
)
# Query by domain
python_procedures = procedural_mem.query("", domain="python")
# Query by content across steps
install_procedures = procedural_mem.query("pip install")
# Prerequisites filtering
internet_procedures = procedural_mem.query("",
prerequisites=["Internet connection"])
Default storage that keeps all data in memory during runtime.
# Default is in-memory
memory = SemanticMemory()
Enables data to persist across application restarts.
# With file persistence
memory = SemanticMemory(persistence="./data_directory")
# Memory will load existing data when created
# and save data automatically when modified
# Save all in-memory data to disk
memory.save_all()
# Load all data from disk to memory
memory.load_all()
# Clear all data (memory and persistence)
memory.clear_all()
Enables semantic similarity search using vector embeddings.
# With vector search
memory = SemanticMemory(
vector_search=True,
vector_db_path="./vector_db"
)
# Add facts
memory.create(content="The Earth is the third planet from the Sun")
memory.create(content="Jupiter is the largest planet in our solar system")
# Vector-based semantic search
# This can find conceptually related items even when keywords don't match
results = memory.query("celestial bodies in space")
for result in results:
print(f"{result['similarity_score']:.2f}: {result['content']}")
See the examples directory for full examples:
basic_usage.py: Basic usage for all memory typespersistence_example.py: Demonstrates file persistence and vector searchlock_monitoring_demo.py: Demonstrates the lock monitoring systemAll memory operations in AgentMem are thread-safe and can be used safely in multi-threaded applications.
AgentMem includes a lock monitoring system to help diagnose performance issues and track lock contention in concurrent environments:
from agentmem.concurrency import lock_manager
# Lock statistics
stats = lock_manager.get_lock_statistics()
print(f"Global lock contention: {stats.get('global', {}).get('contention_count', 0)}")
# Currently active locks
active_locks = lock_manager.get_active_locks()
for lock_name, (thread, acquisition_time) in active_locks.items():
print(f"Lock {lock_name} held by {thread.name}")
# Reset monitoring metrics
lock_manager.reset_metrics()
# Disable monitoring for better performance
lock_manager.enable_monitoring(False)
# Re-enable monitoring
lock_manager.enable_monitoring(True)
# Get lock operation history
history = lock_manager.get_lock_history()
See the examples/lock_monitoring_demo.py for a full demonstration of the lock monitoring features.
For large-scale applications, consider the performance characteristics:
You can run performance tests with:
# From the root directory (memory/)
python -m tests.test_performance
Note: Do not use python -m agentmem.tests.test_performance as the tests module is not inside the agentmem package.
For detailed API documentation and examples, see the full documentation.
MIT
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.3.0 | 14 Apr 2025 | 9 |
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 22:40 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:bd445bf2e62ce0abc0d27da82ee2d4af1c769b3e63ef97e924b500fb22d2dce6