mem0-integrate
Wire Mem0 into an existing repo with a goal-driven, test-first pipeline.
Pairs with mem0-test-integration for verification.
Canonical sources (fetch before deciding anything)
The skill MUST WebFetch these URLs before step 3 and cite them in
plan.md. They are the ground truth — do not rely on ambient knowledge
of the Mem0 API.
Agent-ready docs
Published Mem0 skills — delegate; do not reimplement
Prefer these over writing your own call-site patterns. Each is a
standalone SKILL.md with triggers, examples, and version-pinned code.
SDK source (read when docs are ambiguous)
Public repo. Cross-check against the mem0_tested_versions range in this
skill's frontmatter if the main branch has moved past a major.
Quickstarts (for bootstrapping unfamiliar stacks)
Integration principles (non-negotiable)
The true goal of this skill is to produce a PR the maintainers can accept
without argument. That rules out anything invasive.
- Additive, not replacing. If the target repo already has a memory
system, a session store, a user-context layer, or anything named
Memory / memory_*, Mem0 sits alongside it, not in place of it.
The existing system keeps working unchanged.
- Opt-in by default. Gate all new Mem0 code behind a feature flag
(env var like
MEM0_ENABLED=1, a config key, or a strategy selector).
With the flag unset, behavior is the repo's original behavior,
byte-for-byte.
- No breakage. No removed exports, no renamed public functions,
no changed method signatures, no modified existing tests, no changed
behavior of existing tests. All pre-existing tests must pass unchanged
both with the flag set and unset.
- Minimal dependency surface. Add
mem0ai (plus any deps the
delegated skill requires) and nothing else. No new vector stores, no
graph databases, no provider SDKs the repo does not already use.
- Separable commits. Code, tests, and config/docs land in separate
commits so reviewers can cherry-pick.
- The null hypothesis wins. If no additive, gated fit exists after
step 6 (plan), exit with code 1 and a rationale. A bad PR is worse
than no PR.
- Backend only. Mem0 integration lives in server-side code. API keys,
memory scope, and user-identity resolution are not safe client-side.
If the repo has both backend and frontend, the call sites live in
backend files. Frontend-only repos are rejected at preconditions.
Enforced at four gates: preconditions (reject frontend-only repos
and repos where additive fit is impossible), step 2 comprehension
(confirm a backend exists and name candidate surfaces), step 6 plan
review (reject plans that mutate existing exports or name client-side
call sites), and step 10 self-healing loop (refuse to "fix" principle
violations — surface them instead).
Skill delegation rules
Before writing any code, check whether a published skill already covers
the target stack. If yes, delegate — copy its call-site pattern into
plan.md and into the tests; do not paraphrase.
| Detected in target repo |
Delegate to |
Why |
@ai-sdk/* + ai in package.json |
skills/mem0-vercel-ai-sdk |
Integration is via createMem0 provider wrapper, not raw MemoryClient. |
| CLI-only repo (Typer, Commander, Click, Cobra) with no LLM call sites |
skills/mem0-cli |
Call sites are command handlers, not model wrappers. Consider whether mem0 actually fits first. |
| Target is an MCP client / editor config (Claude Code, Cursor, Codex settings) |
integrations/mem0-agent-plugin |
Wire via MCP server URL + hooks; no SDK code usually needed. |
| Any other Python or TS repo with an LLM call site |
skills/mem0 |
Default SDK integration path. |
Record the delegated skill's raw URL in plan.md under a
"Delegated skill:" field. The test writer in step 7 and the
implementation subagent in step 8 both read this field.
Preconditions
Refuse to start unless ALL of the following are true:
- Current working directory is inside a git repository with a clean index
(no uncommitted changes). Protects the user's work — every edit lands on
a feature branch, not on top of in-progress changes.
- Repo has a detectable language (
package.json / pyproject.toml /
requirements.txt). No language → exit cleanly with a written rationale.
- Repo has a backend. Detected by: a
backend/ or server/ or api/
directory; a Python package with FastAPI/Flask/Django/Starlette; a Node
package with Express/Fastify/Koa/NestJS/Next-API-routes; an agent-loop
framework (LangGraph, LangChain, LlamaIndex, Agno). Frontend-only repos
(pure React/Vue/Svelte SPAs, static sites, mobile-only) → exit with
code 1 and a rationale. Mem0 is not installed client-side.
- The user has already decided Mem0 fits this repo. This skill does NOT
survey the codebase to justify fit — bring a concrete goal. (Step 2
does read the repo to understand what it does and locate backend
integration surfaces; that is mechanics, not fit-justification.)
Exit with a written rationale if any precondition fails. Do not try to
"make it work anyway."
Pipeline
Ten steps. Full mechanics, document templates, and gate rules are in
references/pipeline.md. Read that file when you
start executing a step; the summary below is only for routing.
| # |
Step |
Gate |
| 1 |
Language detection. package.json / pyproject.toml / requirements.txt. Monorepo, ask which subdirectory. |
|
| 2 |
Repo comprehension. Budgeted read of README, contributor docs, entry points, top two directory levels. Produces repo-summary.md with ranked backend surfaces. |
User confirms the summary and picks a surface. No backend surface, exit 1. |
| 3 |
Product selection. Platform vs OSS, recommended from dependency signals, never asked blank. |
Locked into goal.md, never re-decided. |
| 4 |
API key check. MEM0_API_KEY (Platform) or OPENAI_API_KEY (OSS). Missing on Platform, default to Agent Mode via mem0 init --agent. |
CI mode with a missing key, exit 2. |
| 5 |
Goal doc. goal.md: what gets stored, when it is retrieved, why, product, delegated skill, out of scope. |
Hard gate. Explicit approval required. 3 rejections, exit 3. |
| 6 |
Integration plan. Scoped grep for call sites and identity source. plan.md: write/read patterns, scoping, call sites, dependencies, preserved behavior, coexistence, feature flag, sources, E2E recipe. |
Hard gate. No plausible additive call site or 3 rejections, exit 5. |
| 7 |
Tests first. Failing write and read tests in the repo's native framework, assertion shapes lifted from the canonical signatures. Must be importable with MEM0_API_KEY unset. |
Tests must fail. If they pass, they are wrong. |
| 8 |
Implementation. Fresh-context subagent, prompt in references/subagent-prompts.md, returns a diff reviewed against plan.md and goal.md. |
3 review loops, then exit 4. |
| 9 |
Commit and handoff. Branch mem0-integrate/<slug>, four separable commits: dependency, module, wiring, tests. |
--no-heal stops here. |
| 10 |
Self-healing loop. Runs /mem0-test-integration --ci, categorizes the failure, spawns a bounded remediation subagent, reverts on regression. |
Pre-existing test failure, stop, exit 6. Never "fix" it. |
Artifacts (all under .mem0-integration/)
| File |
Purpose |
Retention |
repo-summary.md |
Repo comprehension + candidate backend surfaces (step 2). |
Keep across runs. |
goal.md |
Approved intent. Never rewritten after step 6. |
Keep across runs. |
plan.md |
Approved mechanics (where, how, call sites, preserved behavior). |
Keep across runs. |
trace.jsonl |
Every tool call, decision, and subagent exchange this run. |
Overwritten per run. |
diff.patch |
The committed integration as a reviewable patch. |
Overwritten per run. |
heal-trace.md |
Per-attempt record of the self-healing loop (step 10). |
Overwritten per run. |
product.json |
{"product": "platform"|"oss", "language": "...", "mem0_version": "...", "write_site": "file:line", "read_site": "file:line", "feature_flag": "MEM0_ENABLED"} — consumed by the verification skill. |
Overwritten per run. |
.mem0-integration/ is added to .gitignore on first run. Nothing is
written outside this directory and the repo's source tree.
Modes
| Mode |
Trigger |
Behavior |
| Interactive (default) |
TTY present, MEM0_INTEGRATE_CI unset |
Asks for keys, confirms goal doc, shows recommendations. |
| CI |
MEM0_INTEGRATE_CI=1 |
Requires keys in env, requires --product, auto-approves goal doc from goal.md if present, fails fast otherwise. |
Invocation
/mem0-integrate # interactive, heal ON
/mem0-integrate --no-heal # stop after commit; manual verify
/mem0-integrate --heal-max 5 # cap heal attempts per category (default 3)
/mem0-integrate --product platform # skip the product ask
/mem0-integrate --product oss
/mem0-integrate --ci # non-interactive (for test harness)
Exit codes
| Code |
Meaning |
| 0 |
Success. Feature branch committed; verification skill ready to run. |
| 1 |
Precondition failed (dirty repo, no detectable language, etc.). |
| 2 |
Missing env key in CI mode. |
| 3 |
Goal doc rejected 3+ times — integration is not well-specified. |
| 4 |
Subagent review loop did not converge in 3 rounds. |
| 5 |
Integration plan rejected 3+ times, or no plausible additive call site found. |
| 6 |
Self-healing loop did not converge, detected a non-invasiveness violation, or a pre-existing test failed. |
Explicitly out of scope
- Surveying the repo for fit points. Humans decide where Mem0 helps before
invoking this skill.
- Replacing any existing memory / session / state system. Always additive
and feature-flagged; see "Integration principles."
- Modifying pre-existing tests, even to "fix" them under self-heal. Tests
that fail after integration with the flag unset are a non-invasiveness
violation, not a bug to patch.
- Deciding Platform vs OSS silently. Always ask with a recommendation.
- Switching branches, pushing, or opening PRs. Commits locally and stops
(or enters the heal loop, still local).
- Data migration between stores. Point user at
migration/oss-to-platform
docs if they ask.
- Provider selection beyond the default LLM for OSS. If they need a custom
LLM / embedder / vector store, route to
components/* docs and re-run
step 4 with the new key.
1---2name: mem0-integrate3description: Integrate Mem0 into an existing repository using a goal-driven, TDD pipeline. Detects the repo's language automatically and asks the user to pick between Mem0 Platform (managed) and Mem0 Open Source (self-hosted). Writes failing tests before any implementation. Produces a local feature branch plus `.mem0-integration/` artifacts consumed by the paired verification skill. TRIGGER when: user says "integrate mem0", "add mem0 to this repo", "wire mem0 into <repo>", or asks how to add memory to an existing project. DO NOT TRIGGER when: the user wants general SDK usage (use skill:mem0), CLI usage (use skill:mem0-cli), or Vercel AI SDK (use skill:mem0-vercel-ai-sdk). After success, invoke skill:mem0-test-integration to verify in the same workspace (loose coupling).4license: Apache-2.05---6
7# mem0-integrate
8
9Wire Mem0 into an existing repo with a goal-driven, test-first pipeline.
10Pairs with `mem0-test-integration` for verification.
11
12## Canonical sources (fetch before deciding anything)
13
14The skill MUST `WebFetch` these URLs before step 3 and cite them in
15`plan.md`. They are the ground truth — do not rely on ambient knowledge
16of the Mem0 API.
17
18### Agent-ready docs
19- Scope-tagged docs index: https://docs.mem0.ai/llms.txt
20- Full docs (single file, deep dives): https://docs.mem0.ai/llms-full.txt
21- OpenAPI spec (Platform REST, machine-readable): https://docs.mem0.ai/openapi.json
22- Hosted MCP server: https://mcp.mem0.ai (requires Platform API key)
23- Integrations index: https://docs.mem0.ai/integrations
24
25### Published Mem0 skills — delegate; do not reimplement
26Prefer these over writing your own call-site patterns. Each is a
27standalone `SKILL.md` with triggers, examples, and version-pinned code.
28
29- SDK (Python + TS, Platform + OSS): https://raw.githubusercontent.com/mem0ai/mem0/main/skills/mem0/SKILL.md
30- CLI: https://raw.githubusercontent.com/mem0ai/mem0/main/skills/mem0-cli/SKILL.md
31- Vercel AI SDK: https://raw.githubusercontent.com/mem0ai/mem0/main/skills/mem0-vercel-ai-sdk/SKILL.md
32- Portable editor/MCP plugin: https://github.com/mem0ai/mem0/tree/main/integrations/mem0-agent-plugin
33
34### SDK source (read when docs are ambiguous)
35Public repo. Cross-check against the `mem0_tested_versions` range in this
36skill's frontmatter if the `main` branch has moved past a major.
37
38- Repo root: https://github.com/mem0ai/mem0
39- Python SDK: https://github.com/mem0ai/mem0/tree/main/mem0
40- TypeScript SDK: https://github.com/mem0ai/mem0/tree/main/mem0-ts
41
42### Quickstarts (for bootstrapping unfamiliar stacks)
43- Platform: https://docs.mem0.ai/platform/quickstart
44- OSS Python: https://docs.mem0.ai/open-source/python-quickstart
45- OSS Node: https://docs.mem0.ai/open-source/node-quickstart
46- Platform vs OSS comparison: https://docs.mem0.ai/platform/platform-vs-oss
47
48## Integration principles (non-negotiable)
49
50The true goal of this skill is to produce a **PR the maintainers can accept
51without argument**. That rules out anything invasive.
52
531. **Additive, not replacing.** If the target repo already has a memory
54 system, a session store, a user-context layer, or anything named
55 `Memory` / `memory_*`, Mem0 sits **alongside** it, not in place of it.
56 The existing system keeps working unchanged.
572. **Opt-in by default.** Gate all new Mem0 code behind a feature flag
58 (env var like `MEM0_ENABLED=1`, a config key, or a strategy selector).
59 With the flag unset, behavior is the repo's original behavior,
60 byte-for-byte.
613. **No breakage.** No removed exports, no renamed public functions,
62 no changed method signatures, no modified existing tests, no changed
63 behavior of existing tests. All pre-existing tests must pass unchanged
64 both with the flag set and unset.
654. **Minimal dependency surface.** Add `mem0ai` (plus any deps the
66 delegated skill requires) and nothing else. No new vector stores, no
67 graph databases, no provider SDKs the repo does not already use.
685. **Separable commits.** Code, tests, and config/docs land in separate
69 commits so reviewers can cherry-pick.
706. **The null hypothesis wins.** If no additive, gated fit exists after
71 step 6 (plan), exit with code 1 and a rationale. A bad PR is worse
72 than no PR.
737. **Backend only.** Mem0 integration lives in server-side code. API keys,
74 memory scope, and user-identity resolution are not safe client-side.
75 If the repo has both backend and frontend, the call sites live in
76 backend files. Frontend-only repos are rejected at preconditions.
77
78Enforced at four gates: **preconditions** (reject frontend-only repos
79and repos where additive fit is impossible), **step 2 comprehension**
80(confirm a backend exists and name candidate surfaces), **step 6 plan
81review** (reject plans that mutate existing exports or name client-side
82call sites), and **step 10 self-healing loop** (refuse to "fix" principle
83violations — surface them instead).
84
85## Skill delegation rules
86
87Before writing any code, check whether a published skill already covers
88the target stack. If yes, delegate — copy its call-site pattern into
89`plan.md` and into the tests; do not paraphrase.
90
91| Detected in target repo | Delegate to | Why |
92|---|---|---|
93| `@ai-sdk/*` + `ai` in `package.json` | `skills/mem0-vercel-ai-sdk` | Integration is via `createMem0` provider wrapper, not raw `MemoryClient`. |
94| CLI-only repo (Typer, Commander, Click, Cobra) with no LLM call sites | `skills/mem0-cli` | Call sites are command handlers, not model wrappers. Consider whether mem0 actually fits first. |
95| Target is an MCP client / editor config (Claude Code, Cursor, Codex settings) | `integrations/mem0-agent-plugin` | Wire via MCP server URL + hooks; no SDK code usually needed. |
96| Any other Python or TS repo with an LLM call site | `skills/mem0` | Default SDK integration path. |
97
98Record the delegated skill's raw URL in `plan.md` under a
99**"Delegated skill:"** field. The test writer in step 7 and the
100implementation subagent in step 8 both read this field.
101
102## Preconditions
103
104Refuse to start unless ALL of the following are true:
105
106- Current working directory is inside a git repository with a clean index
107 (no uncommitted changes). Protects the user's work — every edit lands on
108 a feature branch, not on top of in-progress changes.
109- Repo has a detectable language (`package.json` / `pyproject.toml` /
110 `requirements.txt`). No language → exit cleanly with a written rationale.
111- Repo has a **backend**. Detected by: a `backend/` or `server/` or `api/`
112 directory; a Python package with FastAPI/Flask/Django/Starlette; a Node
113 package with Express/Fastify/Koa/NestJS/Next-API-routes; an agent-loop
114 framework (LangGraph, LangChain, LlamaIndex, Agno). Frontend-only repos
115 (pure React/Vue/Svelte SPAs, static sites, mobile-only) → exit with
116 code 1 and a rationale. Mem0 is not installed client-side.
117- The user has already decided Mem0 fits this repo. This skill does NOT
118 survey the codebase to justify fit — bring a concrete goal. (Step 2
119 *does* read the repo to understand what it does and locate backend
120 integration surfaces; that is mechanics, not fit-justification.)
121
122Exit with a written rationale if any precondition fails. Do not try to
123"make it work anyway."
124
125## Pipeline
126
127Ten steps. Full mechanics, document templates, and gate rules are in
128[`references/pipeline.md`](references/pipeline.md). Read that file when you
129start executing a step; the summary below is only for routing.
130
131| # | Step | Gate |
132|---|---|---|
133| 1 | **Language detection.** `package.json` / `pyproject.toml` / `requirements.txt`. Monorepo, ask which subdirectory. | |
134| 2 | **Repo comprehension.** Budgeted read of README, contributor docs, entry points, top two directory levels. Produces `repo-summary.md` with ranked backend surfaces. | User confirms the summary and picks a surface. No backend surface, exit 1. |
135| 3 | **Product selection.** Platform vs OSS, recommended from dependency signals, never asked blank. | Locked into `goal.md`, never re-decided. |
136| 4 | **API key check.** `MEM0_API_KEY` (Platform) or `OPENAI_API_KEY` (OSS). Missing on Platform, default to Agent Mode via `mem0 init --agent`. | CI mode with a missing key, exit 2. |
137| 5 | **Goal doc.** `goal.md`: what gets stored, when it is retrieved, why, product, delegated skill, out of scope. | **Hard gate.** Explicit approval required. 3 rejections, exit 3. |
138| 6 | **Integration plan.** Scoped grep for call sites and identity source. `plan.md`: write/read patterns, scoping, call sites, dependencies, preserved behavior, coexistence, feature flag, sources, E2E recipe. | **Hard gate.** No plausible additive call site or 3 rejections, exit 5. |
139| 7 | **Tests first.** Failing write and read tests in the repo's native framework, assertion shapes lifted from the canonical signatures. Must be importable with `MEM0_API_KEY` unset. | Tests must fail. If they pass, they are wrong. |
140| 8 | **Implementation.** Fresh-context subagent, prompt in [`references/subagent-prompts.md`](references/subagent-prompts.md), returns a diff reviewed against `plan.md` and `goal.md`. | 3 review loops, then exit 4. |
141| 9 | **Commit and handoff.** Branch `mem0-integrate/<slug>`, four separable commits: dependency, module, wiring, tests. | `--no-heal` stops here. |
142| 10 | **Self-healing loop.** Runs `/mem0-test-integration --ci`, categorizes the failure, spawns a bounded remediation subagent, reverts on regression. | Pre-existing test failure, **stop**, exit 6. Never "fix" it. |
143
144## Artifacts (all under `.mem0-integration/`)
145
146| File | Purpose | Retention |
147|---|---|---|
148| `repo-summary.md` | Repo comprehension + candidate backend surfaces (step 2). | Keep across runs. |
149| `goal.md` | Approved intent. Never rewritten after step 6. | Keep across runs. |
150| `plan.md` | Approved mechanics (where, how, call sites, preserved behavior). | Keep across runs. |
151| `trace.jsonl` | Every tool call, decision, and subagent exchange this run. | Overwritten per run. |
152| `diff.patch` | The committed integration as a reviewable patch. | Overwritten per run. |
153| `heal-trace.md` | Per-attempt record of the self-healing loop (step 10). | Overwritten per run. |
154| `product.json` | `{"product": "platform"\|"oss", "language": "...", "mem0_version": "...", "write_site": "file:line", "read_site": "file:line", "feature_flag": "MEM0_ENABLED"}` — consumed by the verification skill. | Overwritten per run. |
155
156`.mem0-integration/` is added to `.gitignore` on first run. Nothing is
157written outside this directory and the repo's source tree.
158
159## Modes
160
161| Mode | Trigger | Behavior |
162|---|---|---|
163| Interactive (default) | TTY present, `MEM0_INTEGRATE_CI` unset | Asks for keys, confirms goal doc, shows recommendations. |
164| CI | `MEM0_INTEGRATE_CI=1` | Requires keys in env, requires `--product`, auto-approves goal doc from `goal.md` if present, fails fast otherwise. |
165
166## Invocation
167
168 /mem0-integrate # interactive, heal ON
169 /mem0-integrate --no-heal # stop after commit; manual verify
170 /mem0-integrate --heal-max 5 # cap heal attempts per category (default 3)
171 /mem0-integrate --product platform # skip the product ask
172 /mem0-integrate --product oss
173 /mem0-integrate --ci # non-interactive (for test harness)
174
175## Exit codes
176
177| Code | Meaning |
178|---|---|
179| 0 | Success. Feature branch committed; verification skill ready to run. |
180| 1 | Precondition failed (dirty repo, no detectable language, etc.). |
181| 2 | Missing env key in CI mode. |
182| 3 | Goal doc rejected 3+ times — integration is not well-specified. |
183| 4 | Subagent review loop did not converge in 3 rounds. |
184| 5 | Integration plan rejected 3+ times, or no plausible additive call site found. |
185| 6 | Self-healing loop did not converge, detected a non-invasiveness violation, or a pre-existing test failed. |
186
187## Explicitly out of scope
188
189- Surveying the repo for fit points. Humans decide where Mem0 helps before
190 invoking this skill.
191- Replacing any existing memory / session / state system. Always additive
192 and feature-flagged; see "Integration principles."
193- Modifying pre-existing tests, even to "fix" them under self-heal. Tests
194 that fail after integration with the flag unset are a non-invasiveness
195 violation, not a bug to patch.
196- Deciding Platform vs OSS silently. Always ask with a recommendation.
197- Switching branches, pushing, or opening PRs. Commits locally and stops
198 (or enters the heal loop, still local).
199- Data migration between stores. Point user at `migration/oss-to-platform`
200 docs if they ask.
201- Provider selection beyond the default LLM for OSS. If they need a custom
202 LLM / embedder / vector store, route to `components/*` docs and re-run
203 step 4 with the new key.