SKILL.md
SKILL.mdBrowse 14 files
2,055 tokens
7,783 bytes
Token encoding: o200k_base
Snapshot 0df3e4b
1---2name: mem03description: >4 Mem0 Platform SDK for adding persistent memory to AI applications.5 TRIGGER when: user mentions "mem0", "MemoryClient", "memory layer",6 "remember user preferences", "persistent context", "personalization",7 or needs to add long-term memory to chatbots, agents, or AI apps.8 Covers Python SDK (mem0ai), TypeScript SDK (mem0ai), and framework integrations9 (LangChain, CrewAI, OpenAI Agents SDK, Pipecat, LlamaIndex, AutoGen, LangGraph).10 Also covers the open-source self-hosted Memory class.11 This is the DEFAULT mem0 skill for ambiguous queries.12 DO NOT TRIGGER when: user asks about CLI commands, terminal usage, or shell13 scripts (use mem0-cli), or Vercel AI SDK / @mem0/vercel-ai-provider / createMem014 (use mem0-vercel-ai-sdk).15license: Apache-2.016metadata:17 author: mem0ai18 version: "3.0.0"19 category: ai-memory20 tags: "memory, personalization, ai, python, typescript, vector-search"21compatibility: Requires Python 3.10+ or Node.js 18+, pip install mem0ai or npm install mem0ai, MEM0_API_KEY env var (Platform), and internet access to api.mem0.ai. SDK v3 with v2 compatibility mode available.22---23 24# Mem0 Platform Integration25 26> **Skill Graph:** This skill is part of the Mem0 skill graph:27> - **mem0** (this skill) -- Platform Client SDK + OSS (Python + TypeScript)28> - **[mem0-cli](../mem0-cli/SKILL.md)** ([GitHub](https://github.com/mem0ai/mem0/tree/main/skills/mem0-cli)) -- Command-line interface29> - **[mem0-vercel-ai-sdk](../mem0-vercel-ai-sdk/SKILL.md)** ([GitHub](https://github.com/mem0ai/mem0/tree/main/skills/mem0-vercel-ai-sdk)) -- Vercel AI SDK provider30 31Mem0 is a managed memory layer for AI applications. It stores, retrieves, and manages user memories via API — no infrastructure to deploy. For self-hosted usage, see the OSS section in the client references below.32 33## Step 1: Install and authenticate34 35**Python:**36```bash37pip install mem0ai38export MEM0_API_KEY="m0-your-api-key"39```40 41**TypeScript/JavaScript:**42```bash43npm install mem0ai44export MEM0_API_KEY="m0-your-api-key"45```46 47Get an API key at: https://app.mem0.ai/dashboard/api-keys?utm_source=oss&utm_medium=skill-mem048 49> **Don't have a `MEM0_API_KEY`?** Run `mem0 init --agent --agent-caller <your-name> --json` (after `pip install mem0-cli` or `npm install -g @mem0/cli`), substituting your agent identity (e.g. `claude-code`, `cursor`). If you forgot to pass `--agent-caller`, run `mem0 identify <your-name>` after init. The human can claim later with `mem0 init --email <your-email>`.50 51## Step 2: Initialize the client52 53**Python:**54```python55from mem0 import MemoryClient56client = MemoryClient(api_key="m0-xxx")57```58 59**TypeScript:**60```typescript61import MemoryClient from 'mem0ai';62const client = new MemoryClient({ apiKey: 'm0-xxx' });63```64 65For async Python, use `AsyncMemoryClient`.66 67## Step 3: Core operations68 69Every Mem0 integration follows the same pattern: **retrieve → generate → store**.70 71### Add memories72```python73messages = [74 {"role": "user", "content": "I'm a vegetarian and allergic to nuts."},75 {"role": "assistant", "content": "Got it! I'll remember that."}76]77client.add(messages, user_id="alice")78```79 80### Search memories81```python82results = client.search("dietary preferences", filters={"user_id": "alice"})83for mem in results.get("results", []):84 print(mem["memory"])85```86 87### Get all memories88```python89all_memories = client.get_all(filters={"user_id": "alice"})90```91 92### Update a memory93```python94client.update("memory-uuid", text="Updated: vegetarian, nut allergy, prefers organic")95```96 97### Delete a memory98```python99client.delete("memory-uuid")100client.delete_all(user_id="alice") # delete all for a user101```102 103## Common integration pattern104 105```python106from mem0 import MemoryClient107from openai import OpenAI108 109mem0 = MemoryClient()110openai = OpenAI()111 112def chat(user_input: str, user_id: str) -> str:113 # 1. Retrieve relevant memories114 memories = mem0.search(user_input, filters={"user_id": user_id})115 context = "\n".join([m["memory"] for m in memories.get("results", [])])116 117 # 2. Generate response with memory context118 response = openai.chat.completions.create(119 model="gpt-5-mini",120 messages=[121 {"role": "system", "content": f"User context:\n{context}"},122 {"role": "user", "content": user_input},123 ]124 )125 reply = response.choices[0].message.content126 127 # 3. Store interaction for future context128 mem0.add(129 [{"role": "user", "content": user_input}, {"role": "assistant", "content": reply}],130 user_id=user_id131 )132 return reply133```134 135## Common edge cases136 137- **Search returns empty:** Memories process asynchronously. Wait 2-3s after `add()` before searching. Also verify `user_id` matches exactly (case-sensitive) and use `filters={"user_id": "..."}` syntax.138- **AND filter with user_id + agent_id returns empty:** Entities are stored separately. Use `OR` instead, or query separately.139- **Duplicate memories:** Don't mix `infer=True` (default) and `infer=False` for the same data. Stick to one mode.140- **Wrong import:** Always use `from mem0 import MemoryClient` (or `AsyncMemoryClient` for async). Do not use `from mem0 import Memory`.141- **v3 defaults:** `top_k=20`, `threshold=0.1`, `rerank=False`. Adjust as needed for your use case.142 143## v2 Compatibility144 145If you're using SDK v2.x, note these differences:146- **Entity IDs:** Pass `user_id` as top-level kwarg to `search()` instead of inside `filters`147- **Defaults:** `top_k=100`, no threshold, `rerank=True`148- **Graph memory:** Available via `enable_graph=True`149 150See the [migration guide](https://docs.mem0.ai/migration/oss-v2-to-v3) for details.151 152## Live documentation search153 154For the latest docs beyond what's in the references, use the doc search tool:155 156```bash157python ${CLAUDE_SKILL_DIR}/scripts/mem0_doc_search.py --query "topic"158python ${CLAUDE_SKILL_DIR}/scripts/mem0_doc_search.py --page "/platform/features/graph-memory"159python ${CLAUDE_SKILL_DIR}/scripts/mem0_doc_search.py --index160```161 162No API key needed — searches docs.mem0.ai directly.163 164## Client SDK References165 166Language-specific deep references (Platform + OSS):167 168| Language | File |169|----------|------|170| Python (MemoryClient + AsyncMemoryClient + Memory OSS) | [client/python.md](client/python.md) |171| TypeScript/Node.js (MemoryClient + Memory OSS) | [client/node.md](client/node.md) |172| Python vs TypeScript differences | [client/differences.md](client/differences.md) |173 174## Platform References175 176Load these on demand for deeper detail:177 178| Topic | File |179|-------|------|180| Quickstart (Python, TS, cURL) | [references/quickstart.md](references/quickstart.md) |181| SDK guide (all methods, both languages) | [references/sdk-guide.md](references/sdk-guide.md) |182| API reference (endpoints, filters, object schema) | [references/api-reference.md](references/api-reference.md) |183| Architecture (pipeline, lifecycle, scoping, performance) | [references/architecture.md](references/architecture.md) |184| Platform features (retrieval, graph, categories, MCP, etc.) | [references/features.md](references/features.md) |185| Framework integrations (LangChain, CrewAI, OpenAI Agents, etc.) | [references/integration-patterns.md](references/integration-patterns.md) |186| Use cases & examples (real-world patterns with code) | [references/use-cases.md](references/use-cases.md) |187 188## Related Mem0 Skills189 190| Skill | When to use | Link |191|-------|-------------|------|192| mem0-cli | Terminal commands, scripting, CI/CD, agent tool loops | [local](../mem0-cli/SKILL.md) / [GitHub](https://github.com/mem0ai/mem0/tree/main/skills/mem0-cli) |193| mem0-vercel-ai-sdk | Vercel AI SDK provider with automatic memory | [local](../mem0-vercel-ai-sdk/SKILL.md) / [GitHub](https://github.com/mem0ai/mem0/tree/main/skills/mem0-vercel-ai-sdk) |194 Discovery context
Discovered by repository scan. No exact path reference found in the snapshot’s root AGENTS.md.