Persistent memory for AI agents that actually works.
AgentMind solves a critical problem with AI agents: they forget everything between sessions. This library provides long-term memory with semantic search, temporal context, and integration with popular frameworks.
- π§ Long-term memory β agents remember context between sessions
- π Semantic search β find relevant memories by meaning
- β° Temporal context β understand "when" events occurred
- π€ User preferences β personalize for each user
- π Integrations β LangChain, AutoGen, CrewAI, OpenAI
- π Simple API β 3 lines of code to add memory
- πΎ Flexible storage β SQLite, PostgreSQL, Redis, ChromaDB
pip install agentmindfrom agentmind import Memory
# Initialize memory
memory = Memory(storage="sqlite", path="agent_memory.db")
# Remember
memory.remember(
agent_id="assistant-1",
content="User prefers Python over JavaScript",
metadata={"category": "preference", "user_id": "user-123"}
)
# Recall
memories = memory.recall(
agent_id="assistant-1",
query="What programming languages does the user like?",
limit=5
)
for mem in memories:
print(f"- {mem.content} (relevance: {mem.score:.2f})")from agentmind.integrations import LangChainMemory
from langchain.agents import initialize_agent
# Create memory for LangChain
memory = LangChainMemory(agent_id="my-agent")
# Use in agent
agent = initialize_agent(
tools=tools,
llm=llm,
memory=memory, # Agent now remembers context!
verbose=True
)
# Agent automatically saves and retrieves memories
agent.run("What did we discuss yesterday?")from agentmind import Memory
memory = Memory()
# User mentions preferences
memory.remember(
agent_id="assistant",
content="User is a senior Python developer interested in AI/ML",
metadata={"type": "user_profile"}
)
memory.remember(
agent_id="assistant",
content="User prefers concise code examples without excessive comments",
metadata={"type": "preference"}
)
# Later, agent can personalize responses
context = memory.recall(
agent_id="assistant",
query="user background and preferences",
limit=3
)
# Use context in prompt
prompt = f"""
Based on user context:
{context}
Provide a response tailored to their expertise level.
"""from agentmind import Memory
# Shared memory for agent team
shared_memory = Memory(storage="postgresql", connection_string="...")
# Researcher agent saves findings
shared_memory.remember(
agent_id="researcher",
content="Found 3 relevant papers on transformer architectures",
metadata={"task": "research", "topic": "transformers"}
)
# Writer agent uses these findings
research = shared_memory.recall(
agent_id="writer",
query="transformer architecture papers",
filters={"task": "research"}
)
# Writer creates content based on researchfrom agentmind import Memory
from datetime import datetime, timedelta
memory = Memory()
# Remember with timestamp
memory.remember(
agent_id="scheduler",
content="Meeting with client about project requirements",
timestamp=datetime(2026, 1, 15, 14, 0),
metadata={"type": "event", "priority": "high"}
)
# Recall recent events
recent = memory.recall(
agent_id="scheduler",
query="meetings and events",
time_range=(datetime.now() - timedelta(days=7), datetime.now())
)memory = Memory(storage="sqlite", path="memory.db")memory = Memory(
storage="postgresql",
connection_string="postgresql://user:pass@localhost:5432/agentmind"
)memory = Memory(
storage="redis",
connection_string="redis://localhost:6379",
ttl=86400 # 24 hours
)memory = Memory(
storage="chromadb",
collection_name="agent_memories",
persist_directory="./chroma_db"
)from agentmind import Memory, MemoryConfig
config = MemoryConfig(
storage="postgresql",
connection_string="postgresql://...",
embedding_model="text-embedding-3-small", # OpenAI embeddings
embedding_dimension=1536,
max_memories=10000, # Limit per agent
ttl=2592000, # 30 days in seconds
auto_cleanup=True # Automatic cleanup of old entries
)
memory = Memory(config=config)Save a memory.
memory.remember(
agent_id: str, # Agent ID
content: str, # Memory text
metadata: dict = None, # Additional metadata
timestamp: datetime = None, # Timestamp (default: now)
importance: float = 1.0 # Importance (0.0 - 1.0)
)Retrieve relevant memories.
memories = memory.recall(
agent_id: str, # Agent ID
query: str = None, # Search query
filters: dict = None, # Metadata filters
time_range: tuple = None, # (start_time, end_time)
limit: int = 10, # Max results
min_score: float = 0.0 # Minimum relevance
)Delete memories.
memory.forget(
agent_id: str,
memory_ids: list = None, # Specific IDs
filters: dict = None, # Delete by filter
older_than: datetime = None # Delete old ones
)Get memory statistics.
stats = memory.get_stats(agent_id="my-agent")
# {
# "total_memories": 1234,
# "oldest_memory": "2026-01-01T00:00:00",
# "newest_memory": "2026-01-15T12:34:56",
# "storage_size_mb": 45.2
# }from agentmind.integrations import LangChainMemory
memory = LangChainMemory(
agent_id="my-agent",
return_messages=True,
memory_key="chat_history"
)from agentmind.integrations import AutoGenMemory
memory = AutoGenMemory(agent_id="assistant")
# Use in AutoGen agent
assistant = autogen.AssistantAgent(
name="assistant",
memory=memory
)from agentmind.integrations import OpenAIMemory
memory = OpenAIMemory(
agent_id="my-assistant",
thread_id="thread-123"
)
# Sync with OpenAI thread
memory.sync_with_thread()# Run tests
pytest tests/
# With coverage
pytest --cov=agentmind tests/
# Integration tests only
pytest tests/integration/- v0.1.0 β Basic functionality
- v0.2.0 β LangChain integration
- v0.3.0 β AutoGen and CrewAI integration
- v0.4.0 β Web UI for memory management
- v0.5.0 β Distributed memory (Redis Cluster)
- v1.0.0 β Production-ready release
Contributions welcome! See CONTRIBUTING.md for details.
MIT License. See LICENSE.
Inspired by:
- Mem0 β original persistent memory idea
- LangChain β LLM integrations
- ChromaDB β vector databases
- GitHub: @AntoGA
- Issues: GitHub Issues
β If this project is useful, please star it! It helps with development.