# Mem0 — Long-Term Memory Layer for AI Agents > Add persistent memory to AI agents and assistants. Remembers user preferences, context, and past interactions across sessions. ## Install Save in your project root: ## Quick Use ```bash pip install mem0ai ``` ```python from mem0 import Memory memory = Memory() # Add a memory memory.add("I prefer dark mode and vim keybindings", user_id="alice") # Search memories results = memory.search("What does Alice prefer?", user_id="alice") print(results) ``` **CLI alternative**: ```bash npm install -g @mem0/cli mem0 init mem0 add "Likes Python and FastAPI" --user-id alice mem0 search "What does Alice like?" --user-id alice ``` --- ## Intro Mem0 is a memory layer for AI applications. It remembers user preferences, past interactions, and context across sessions — so your AI assistant doesn't start from scratch every conversation. Multi-level memory (user, session, agent state), 26% more accurate than OpenAI's built-in memory, 91% faster, and 90% fewer tokens than full-context approaches. 51,000+ GitHub stars, Y Combinator S24. --- ## Key Features - **Multi-level memory**: User preferences, session context, agent state - **Adaptive learning**: Continuously improves from interactions - **Cross-platform SDKs**: Python (`pip install mem0ai`) and Node.js (`npm install mem0ai`) - **Self-hosted or managed**: Full control locally, or use the hosted platform - **LLM-agnostic**: Works with OpenAI, Anthropic, and other providers ## Full Example: Chat with Memory ```python from openai import OpenAI from mem0 import Memory openai_client = OpenAI() memory = Memory() def chat_with_memories(message: str, user_id: str = "default_user") -> str: # Retrieve relevant memories relevant = memory.search(query=message, user_id=user_id, limit=3) memories_str = "\ ".join(f"- {m['memory']}" for m in relevant["results"]) # Build prompt with memory context system = f"You are a helpful AI. Use these memories:\ {memories_str}" messages = [ {"role": "system", "content": system}, {"role": "user", "content": message} ] # Generate response response = openai_client.chat.completions.create( model="gpt-4.1-nano-2025-04-14", messages=messages ) reply = response.choices[0].message.content # Save new memories from conversation messages.append({"role": "assistant", "content": reply}) memory.add(messages, user_id=user_id) return reply # Usage chat_with_memories("I'm a Python developer who loves FastAPI") chat_with_memories("What framework should I use for my next API?") # → Mem0 remembers you prefer FastAPI ``` ## Use Cases - **AI Assistants**: Consistent, personalized conversations across sessions - **Customer Support**: Remember past tickets, preferences, account history - **Healthcare**: Track patient preferences and interaction history - **Productivity**: Personal AI that knows your workflows and tools - **Gaming**: NPCs that remember player choices and adapt ## Integrations - ChatGPT browser extension (adds memory to ChatGPT, Perplexity, Claude) - LangGraph for building memory-enhanced agents - CrewAI for multi-agent systems with shared memory --- ### FAQ **Q: What is Mem0?** A: Add persistent memory to AI agents and assistants. Remembers user preferences, context, and past interactions across sessions. **Q: How do I install Mem0?** A: Check the Quick Use section above for step-by-step installation instructions. Most assets can be set up in under 2 minutes. ## Source & Thanks > Created by [Taranjeet Singh](https://github.com/taranjeetsingh) / [mem0ai](https://github.com/mem0ai). Licensed under Apache 2.0. > [mem0](https://github.com/mem0ai/mem0) — ⭐ 51,300+ > Docs: [docs.mem0.ai](https://docs.mem0.ai) Thanks to the Mem0 team (YC S24) for building the most popular open-source memory layer for AI. --- Source: https://tokrepo.com/en/workflows/952ce6d3-b141-4db3-83d4-923a7268aef8 Author: Agent Toolkit