Persistent memory for AI agents. One API. Every agent remembers.
Quick Start ยท Features ยท [API Docs#-api-reference) ยท Deployment ยท Contributing
Every AI agent wakes up with amnesia. MemoryHub fixes that. ๐ง โก
Give your Claude, LangChain, AutoGPT, CrewAI, AutoGen, or custom agents a brain that persists across sessions. Store conversations, facts, preferences, decisions, and relationships โ all through a simple REST API or Python SDK.
Keywords: ai agent memory, persistent memory, llm memory, ai long-term memory, agent context, rag alternative, conversation memory, ai knowledge base, agent state management, llm context window, ai memory system, agent memory store, ai persistent storage, langchain memory, ai agent framework, llm agent memory, ai assistant memory, context persistence, agent memory api, ai memory management
| Problem | Without MemoryHub | With MemoryHub |
|---|---|---|
| ๐ง Agent memory | Resets every session | Persists forever |
| ๐ Context retrieval | Manual RAG setup | Built-in semantic search |
| ๐ท๏ธ Memory organization | Flat text chunks | Typed, tagged, scored |
| ๐ Entity relationships | Manual tracking | Automatic graph |
| ๐ Deduplication | None | Auto-consolidation |
| ๐ก๏ธ Security | Afterthought | Built-in auth + detection |
| ๐ Integration | Custom glue code | SDK + CLI + REST API |
- Episodic Memory โ Conversations, events, interactions with timestamps
- Semantic Memory โ Facts, knowledge, preferences that persist across sessions
- Relational Memory โ Entity graphs โ who works where, what uses what
- Procedural Memory โ Workflows, how-to guides, patterns
- Full-Text Search โ ILIKE-based content search across memories, tags, entities
- Semantic Search โ Sentence transformer embeddings (all-MiniLM-L6-v2) for similarity
- Entity Extraction โ Auto-detect people, emails, URLs, tech keywords, project names
- Sentiment Detection โ Rule-based sentiment scoring (-1.0 to 1.0)
- Context Assembly โ Build relevant context bundles for agent prompts
- Importance Scoring โ 5-level importance system (Trivial โ Critical)
- Recency Prioritization โ Recent memories weighted higher
- Token Estimation โ Estimate context size before injection
- Consolidation โ Auto-deduplicate, archive stale, importance decay/boost
- Tagging โ Flexible tag-based organization
- Namespaces โ Multi-agent isolation with separate data spaces
- Expiration โ TTL-based memory expiration
- API Key Auth โ Secure agent registration and authentication
- Sensitive Data Detection โ Auto-detect API keys, passwords, tokens, private keys, SSH keys, database URLs
- Optional Redaction โ Auto-redact sensitive content before storage
- Namespace Isolation โ Agents can't access each other's memories
- Python SDK โ
pip install memoryhubโfrom memoryhub import MemoryHubClient - CLI Tool โ
memoryhubcommand with full feature support - REST API โ OpenAPI/Swagger docs at
/docs - Docker โ One-command deployment
- Async Support โ Async methods for async agents
pip install memoryhubmemoryhub serve
# ๐ง Server starts at http://localhost:7860
# ๐ API docs at http://localhost:7860/docsmemoryhub register --name "my-assistant" --namespace "john"
# Save the API key! ๐from memoryhub import MemoryHubClient
# Connect
client = MemoryHubClient(api_key="mhub_xxx", base_url="http://localhost:7860")
# ๐ง Store memories
client.remember("John prefers dark mode", category="preference", importance=4)
client.remember("Project Alpha uses FastAPI + PostgreSQL", category="fact")
client.remember("Decided to use SQLite for MVP", category="decision", importance=5)
# ๐ Search memories
results = client.recall("John preferences")
for m in results["memories"]:
print(f" [{m['category']}] {m['content']}")
# ๐ Build context for your agent
context = client.context_as_text("What does John prefer?")
# โ "๐ Context Summary
# Found 2 relevant memories (semantic).
# - [preference] John prefers dark mode [92%]"
# ๐ Create entity relationships
client.relate("John", "works_at", "Acme Corp")
client.relate("Project Alpha", "uses", "FastAPI")
# ๐ Get stats
print(client.stats())
# โ {'total_memories': 3, 'total_relations': 2, ...}# Pre-configured memory types
client.remember_preference("John likes dark themes")
client.remember_fact("The API runs on port 7860")
client.remember_decision("Using SQLite for MVP, migrate later")
client.remember_error("Connection timeout after 30s")
client.remember_conversation("User: How do I configure this?")โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ Claude ๐ค โ โ LangChain โ โ CrewAI ๐ฅ โ โ Custom Bot โ
โ Agent A โ โ Agent B โ โ Agent C โ โ Agent D โ
โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ
โ โ โ โ
โโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโผโโโโโโโโโโโ
โ MemoryHub ๐ง โ
โ โ
โ โโโโโโโโโโโโโโโโโ โ
โ โ REST API โ โ โ FastAPI + OpenAPI
โ โ Python SDK โ โ โ memoryhub package
โ โ CLI Tool โ โ โ memoryhub command
โ โโโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโ โ
โ โ Memory Engine โ โ
โ โ โข Episodic โ โ โ conversations, events
โ โ โข Semantic โ โ โ facts, preferences
โ โ โข Relational โ โ โ entity graphs
โ โ โข Procedural โ โ โ workflows, patterns
โ โโโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโ โ
โ โ Search Engine โ โ
โ โ โข Full-Text โ โ โ ILIKE search
โ โ โข Semantic โ โ โ embeddings (MiniLM)
โ โ โข Entity Ext. โ โ โ auto-extraction
โ โโโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโ โ
โ โ Storage Layer โ โ
โ โ โข SQLite ๐ฆ โ โ โ local-first
โ โ โข PostgreSQL โ โ โ production scale
โ โโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโ
# Register a new agent โ get API key
POST /api/v1/agents
{
"name": "my-agent",
"namespace": "my-project",
"description": "My helpful AI assistant"
}
# Response: { "api_key": "mhub_xxxxxxxx", ... }
# Use in all requests
X-API-Key: mhub_xxxxxxxx| Endpoint | Method | Description |
|---|---|---|
/api/v1/memories |
POST |
๐ง Store a new memory |
/api/v1/memories/bulk |
POST |
๐ฆ Store multiple memories |
/api/v1/memories/search |
GET |
๐ Search memories |
/api/v1/memories/{id} |
GET |
๐ Get a specific memory |
/api/v1/memories/{id} |
PATCH |
โ๏ธ Update a memory |
/api/v1/memories/{id} |
DELETE |
๐๏ธ Delete a memory |
/api/v1/memories/context/build |
GET |
๐ Build context bundle |
/api/v1/memories/stats |
GET |
๐ Get statistics |
/api/v1/memories/consolidate |
POST |
๐ Run consolidation |
| Endpoint | Method | Description |
|---|---|---|
/api/v1/memories/relations |
POST |
๐ Create relationship |
/api/v1/memories/relations/search |
GET |
๐ธ๏ธ Search relationships |
/api/v1/memories/relations/{id} |
DELETE |
โ Delete relationship |
| Endpoint | Method | Description |
|---|---|---|
/health |
GET |
๐ Health check |
/docs |
GET |
๐ Interactive API docs |
/redoc |
GET |
๐ ReDoc documentation |
/openapi.json |
GET |
๐ OpenAPI schema |
# ๐ง Configure
memoryhub configure
# ๐ง Store memories
memoryhub remember "John prefers dark mode" --type semantic --category preference --importance 4
memoryhub remember "Meeting notes from today" --tags "meeting,project-alpha"
# ๐ Search
memoryhub recall "John" --limit 5
memoryhub recall "project" --type semantic --text
# ๐ Build context
memoryhub context "What does John like?" --text
# ๐ Create relationships
memoryhub relate "John" "works_at" "Acme Corp"
memoryhub relate "Project Alpha" "uses" "FastAPI"
# ๐ Stats & management
memoryhub stats
memoryhub consolidate
memoryhub health
# ๐ Start server
memoryhub serve --host 0.0.0.0 --port 7860 --reloadimport anthropic
from memoryhub import MemoryHubClient
memory = MemoryHubClient(api_key="mhub_xxx")
claude = anthropic.Anthropic()
def chat(user_message, session_id="default"):
# Get relevant context from memory
context = memory.context_as_text(user_message, max_memories=5)
# Store user message
memory.remember(user_message, category="conversation", session_id=session_id)
# Call Claude with context
response = claude.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
system=f"You are a helpful assistant. Relevant context:\n{context}",
messages=[{"role": "user", "content": user_message}]
)
# Store response
memory.remember(response.content[0].text, category="conversation", session_id=session_id)
return response.content[0].textfrom langchain.agents import AgentExecutor, create_openai_agent
from langchain.tools import Tool
from memoryhub import MemoryHubClient
memory = MemoryHubClient(api_key="mhub_xxx")
tools = [
Tool(name="Remember", func=lambda c: str(memory.remember(c)),
description="Store a memory. Input: content to remember."),
Tool(name="Recall", func=lambda q: memory.recall_as_text(q),
description="Search memories. Input: search query."),
]
# Use tools in your LangChain agent...from openai import OpenAI
from memoryhub import MemoryHubClient
memory = MemoryHubClient(api_key="mhub_xxx")
client = OpenAI()
def chat(user_message):
context = memory.context_as_text(user_message)
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": f"Context:\n{context}"},
{"role": "user", "content": user_message}
]
)
memory.remember(f"Q: {user_message}\nA: {response.choices[0].message.content}")
return response.choices[0].message.contentfrom crewai import Agent, Task, Crew
from memoryhub import MemoryHubClient
memory = MemoryHubClient(api_key="mhub_xxx")
# Use memory in crew tasks...
context = memory.context_as_text("research topic")
researcher = Agent(
role="Researcher",
goal="Research with persistent memory",
backstory=f"Previous findings:\n{context}"
)docker run -d \
--name memoryhub \
-p 7860:7860 \
-v memoryhub-data:/app/data \
-e MEMORYHUB_SECRET_KEY=$(openssl rand -hex 32) \
memoryhub/memoryhub:latestdocker compose up -d- AWS ECS/Fargate โ See deployment guide
- Google Cloud Run โ
gcloud run deploy memoryhub - Fly.io โ
fly deploy - Railway โ
railway up - DigitalOcean โ App Platform ready
See docs/DEPLOYMENT.md for detailed guides.
| Variable | Default | Description |
|---|---|---|
MEMORYHUB_HOST |
0.0.0.0 |
Server host |
MEMORYHUB_PORT |
7860 |
Server port |
MEMORYHUB_SECRET_KEY |
auto-generated | JWT/API key secret |
MEMORYHUB_DATABASE_URL |
sqlite+aiosqlite:///./memoryhub.db |
Database URL |
MEMORYHUB_EMBEDDING_MODEL |
all-MiniLM-L6-v2 |
Sentence transformer model |
MEMORYHUB_ENABLE_SENSITIVE_DETECTION |
true |
Auto-detect sensitive data |
MEMORYHUB_REDACT_ON_STORE |
false |
Auto-redact before storage |
MEMORYHUB_CONSOLIDATION_INTERVAL_HOURS |
24 |
Hours between auto-consolidation |
MEMORYHUB_IMPORTANCE_DECAY_DAYS |
90 |
Days before importance decays |
MEMORYHUB_DEBUG |
false |
Debug mode |
| Type | Use For |
|---|---|
episodic |
Events, conversations, interactions |
semantic |
Facts, knowledge, preferences |
relational |
Entity connections |
procedural |
How-to, workflows, patterns |
| Category | Description |
|---|---|
conversation |
Chat messages, dialogues |
decision |
Decisions made, rationale |
preference |
User preferences, settings |
fact |
Objective facts, knowledge |
task |
Tasks, todos, assignments |
error |
Errors, bugs, learnings |
learning |
Insights, discoveries |
person |
Information about people |
project |
Project-related info |
system |
System configuration, state |
| Feature | MemoryHub | LangChain Memory | Vector DB + RAG | Custom Solution |
|---|---|---|---|---|
| Setup complexity | โญ Simple | โญโญ Medium | โญโญโญ Complex | โญโญโญโญ Very complex |
| Persistent storage | โ Built-in | โ Session only | ||
| Memory types | โ 4 types | โ Text only | โ Chunks only | |
| Entity relationships | โ Built-in | โ No | โ No | |
| Semantic search | โ Built-in | โ No | โ Yes | |
| Auto-consolidation | โ Built-in | โ No | โ No | |
| Sensitive detection | โ Built-in | โ No | โ No | |
| Multi-agent | โ Namespaces | โ No | ||
| Auth & security | โ API keys | โ No | ||
| Python SDK | โ | โ No | ||
| CLI tool | โ | โ No | โ No | |
| Docker ready | โ | N/A |
memoryhub/
โโโ memoryhub/
โ โโโ api/ # FastAPI routes
โ โ โโโ memories.py # Memory CRUD, search, context, relations
โ โ โโโ admin.py # Agent registration, namespaces
โ โ โโโ deps.py # Auth dependencies, middleware
โ โโโ core/ # Business logic
โ โ โโโ auth.py # API key management
โ โ โโโ client.py # Python SDK client
โ โ โโโ consolidation.py # Memory dedup, archive, decay
โ โ โโโ context.py # Context bundle builder
โ โ โโโ embeddings.py # Sentence transformer engine
โ โ โโโ extraction.py # Entity & sentiment extraction
โ โ โโโ sensitive.py # Sensitive data detection
โ โโโ models/ # Pydantic data models
โ โ โโโ memory.py # Memory, Relation, Search, Stats
โ โ โโโ auth.py # Agent, Token, Namespace
โ โโโ storage/ # Database layer
โ โ โโโ database.py # SQLAlchemy async engine
โ โ โโโ models.py # ORM table models
โ โ โโโ memory_store.py # CRUD operations
โ โโโ utils/ # Utilities
โ โ โโโ sensitive.py # Pattern matching for secrets
โ โโโ cli/ # CLI tool
โ โ โโโ main.py # Typer CLI commands
โ โโโ config.py # Environment configuration
โ โโโ app.py # FastAPI application
โโโ tests/ # Test suite
โโโ examples/ # Integration examples
โโโ docs/ # Documentation
โโโ assets/ # Logos, images
โโโ .github/ # CI/CD, templates
โโโ Dockerfile # Docker build
โโโ docker-compose.yml # Docker Compose
โโโ pyproject.toml # Package config
โโโ README.md # This file
โโโ CONTRIBUTING.md # Contribution guide
โโโ CHANGELOG.md # Version history
โโโ SECURITY.md # Security policy
โโโ LICENSE # MIT License
- Core memory CRUD operations
- Semantic search with embeddings
- Entity extraction and relationships
- Memory consolidation engine
- Context builder for agents
- Python SDK with convenience methods
- CLI tool with rich output
- Multi-agent namespace isolation
- API key authentication
- Sensitive data detection
- Docker support
- Comprehensive test suite
- JavaScript/TypeScript SDK (npm)
- Web dashboard for memory browsing
- PostgreSQL production support
- Memory import/export (JSON, CSV)
- Rate limiting and quotas
- Memory visualization graph
- Plugin system for custom extractors
- Webhook events for memory changes
- Multi-tenant cloud deployment
- Memory sharing between agents
- Advanced analytics and insights
We welcome contributions! See CONTRIBUTING.md for guidelines.
Areas we need help with:
- ๐ Integrations (LangChain, LlamaIndex, CrewAI, AutoGen)
- ๐ฆ JavaScript/TypeScript SDK
- ๐จ Web dashboard
- ๐ Analytics and visualization
- ๐ Documentation and tutorials
- ๐งช Testing and quality
MIT License โ see LICENSE for details.
- FastAPI โ API framework
- SQLAlchemy โ ORM
- Sentence Transformers โ Embeddings
- Typer โ CLI framework
- Rich โ Terminal formatting
Built to solve AI amnesia. One memory at a time. ๐ง โก
โญ Star on GitHub ยท ๐ฆ PyPI ยท ๐ Docs ยท ๐ฌ Discord