mem0
You are an expert in Mem0, the memory infrastructure for AI applications. You help developers add persistent, personalized memory to LLM-powered apps and agents — storing user preferences, conversation history, facts, and context that persists across sessions, enabling AI that remembers users, learns from interactions, and provides increasingly personalized responses.
What this skill does
# Mem0 — Memory Layer for AI Agents
You are an expert in Mem0, the memory infrastructure for AI applications. You help developers add persistent, personalized memory to LLM-powered apps and agents — storing user preferences, conversation history, facts, and context that persists across sessions, enabling AI that remembers users, learns from interactions, and provides increasingly personalized responses.
## Core Capabilities
### Memory Management
```python
# memory_service.py — Add persistent memory to any AI app
from mem0 import Memory
# Initialize with vector store
memory = Memory.from_config({
"llm": {
"provider": "openai",
"config": {"model": "gpt-4o-mini"},
},
"embedder": {
"provider": "openai",
"config": {"model": "text-embedding-3-small"},
},
"vector_store": {
"provider": "qdrant",
"config": {"host": "localhost", "port": 6333, "collection_name": "memories"},
},
})
# Add memories from conversation
messages = [
{"role": "user", "content": "I'm allergic to peanuts and I'm training for a marathon"},
{"role": "assistant", "content": "I'll keep your peanut allergy in mind! For marathon training, nutrition is key..."},
]
memory.add(messages, user_id="user_42")
# Mem0 extracts: "User is allergic to peanuts", "User is training for a marathon"
# Add explicit memory
memory.add("User prefers Python over JavaScript for backend work", user_id="user_42")
# Search memories
results = memory.search("What dietary restrictions?", user_id="user_42")
# → [{"memory": "User is allergic to peanuts", "score": 0.94}]
# Get all memories for a user
all_memories = memory.get_all(user_id="user_42")
# Update memory
memory.update(memory_id="mem_abc123", data="User completed their first marathon in March 2026")
# Delete specific memory
memory.delete(memory_id="mem_abc123")
# Delete all user memories (GDPR compliance)
memory.delete_all(user_id="user_42")
```
### AI Chat with Memory
```python
from openai import OpenAI
from mem0 import Memory
client = OpenAI()
memory = Memory()
async def chat_with_memory(user_id: str, user_message: str) -> str:
# Retrieve relevant memories
relevant = memory.search(user_message, user_id=user_id, limit=5)
memory_context = "\n".join([f"- {m['memory']}" for m in relevant])
# Generate response with memory context
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": f"""You are a personal assistant.
You know these things about the user:
{memory_context}
Use this context to personalize your responses."""},
{"role": "user", "content": user_message},
],
)
assistant_message = response.choices[0].message.content
# Store new memories from this conversation
memory.add(
[
{"role": "user", "content": user_message},
{"role": "assistant", "content": assistant_message},
],
user_id=user_id,
)
return assistant_message
# Session 1
await chat_with_memory("user_42", "I just moved to Berlin and I love Italian food")
# Stores: "User lives in Berlin", "User loves Italian food"
# Session 2 (days later)
await chat_with_memory("user_42", "Recommend a restaurant for tonight")
# → Remembers Berlin + Italian food → suggests Italian restaurants in Berlin
```
### Organization-Level Memory
```python
# Shared knowledge across an organization
memory.add(
"Our refund policy allows returns within 30 days with receipt",
user_id="agent_support",
metadata={"type": "policy", "department": "support"},
)
# Agent-specific memory
memory.add(
"Customer prefers email over phone for follow-ups",
user_id="user_42",
agent_id="support_agent",
)
# Search with filters
results = memory.search(
"refund policy",
user_id="agent_support",
filters={"type": "policy"},
)
```
## Installation
```bash
pip install mem0ai
```
## Best Practices
1. **User-scoped memories** — Always pass `user_id`; memories are isolated per user for privacy
2. **Automatic extraction** — Pass full conversations; Mem0 extracts facts automatically using LLM
3. **Search before generate** — Query relevant memories before LLM call; inject as system prompt context
4. **Memory hygiene** — Periodically review and prune outdated memories; users' preferences change
5. **GDPR compliance** — Use `delete_all(user_id=...)` for right-to-erasure requests
6. **Metadata for filtering** — Add metadata tags (type, department, source) for precise memory retrieval
7. **Conflict resolution** — Mem0 handles contradictions (e.g., "moved from NYC to Berlin" updates location)
8. **Self-hosted option** — Use Qdrant/Chroma locally for data sovereignty; no data leaves your infrastructure
Related in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.