# blade47/mem0 Wiki
## Technical docs: mem0 API
URL: https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/api/api-overview
# mem0 API
**Version:** inferred
**27** endpoints detected from `(inferred from code)`
## Endpoints
### General
| Method | Path | Description |
|--------|------|-------------|
| `GET` | `/configure` | Get current Mem0 configuration |
| `GET` | `/configure/providers` | List bundled LLM and embedder providers |
| `POST` | `/configure` | Configure Mem0 |
| `POST` | `/generate-instructions` | Generate custom instructions from a use case |
| `POST` | `/memories` | Create memories |
| `GET` | `/memories` | Get memories |
| `GET` | `/memories/{memory_id}` | Get a memory |
| `POST` | `/search` | Search memories |
| `PUT` | `/memories/{memory_id}` | Update a memory |
| `GET` | `/memories/{memory_id}/history` | Get memory history |
| `DELETE` | `/memories/{memory_id}` | Delete a memory |
| `DELETE` | `/memories` | Delete all memories |
| `POST` | `/reset` | Reset all memories |
### api-keys
| Method | Path | Description |
|--------|------|-------------|
| `GET` | `/api-keys` | list_keys |
| `POST` | `/api-keys` | create_key |
| `DELETE` | `/api-keys/{key_id}` | revoke_key |
### auth
| Method | Path | Description |
|--------|------|-------------|
| `GET` | `/auth/setup-status` | Setup Status |
| `POST` | `/auth/register` | Register |
| `POST` | `/auth/login` | Login |
| `POST` | `/auth/refresh` | Refresh Token |
| `GET` | `/auth/me` | Get Current User |
| `PATCH` | `/auth/me` | Update Current User |
| `POST` | `/auth/change-password` | Change Password |
| `POST` | `/auth/onboarding-complete` | Complete Onboarding |
### entities
| Method | Path | Description |
|--------|------|-------------|
| `GET` | `/entities` | List Entities |
| `DELETE` | `/entities/{entity_type}/{entity_id}` | Delete Entity |
### requests
| Method | Path | Description |
|--------|------|-------------|
| `GET` | `/requests` | List Requests |
---
## Technical docs: GET Get current Mem0 configuration
URL: https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/api/endpoints/get-config
## Responses
## Try It
---
## Technical docs: Overview
URL: https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/orientation/overview
Relevant source files
The following files were used as context for generating this wiki page:
- [cli/python/src/mem0_cli/__init__.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/cli/python/src/mem0_cli/__init__.py)
- [cli/node/src/index.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/cli/node/src/index.ts)
- [cli/python/src/mem0_cli/app.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/cli/python/src/mem0_cli/app.py)
- [integrations/agent-plugin-core/python/memory_cli.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/agent-plugin-core/python/memory_cli.py)
- [integrations/mem0-agent-plugin/core/memory_cli.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-agent-plugin/core/memory_cli.py)
- [integrations/antigravity-plugin/core/memory_cli.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/antigravity-plugin/core/memory_cli.py)
- [integrations/kimi-plugin/core/memory_cli.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/kimi-plugin/core/memory_cli.py)
- [integrations/cursor-plugin/core/memory_cli.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/cursor-plugin/core/memory_cli.py)
- [integrations/codex-plugin/core/memory_cli.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/codex-plugin/core/memory_cli.py)
- [integrations/mem0-agent-plugin/core/memory_core.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-agent-plugin/core/memory_core.py)
- [integrations/claude-code-plugin/core/memory_cli.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/claude-code-plugin/core/memory_cli.py)
- [integrations/agent-plugin-core/python/memory_core.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/agent-plugin-core/python/memory_core.py)
- [integrations/hermes-plugin-mem0/__init__.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/hermes-plugin-mem0/__init__.py)
- [cli/node/src/commands/init.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/cli/node/src/commands/init.ts)
- [integrations/antigravity-plugin/core/memory_core.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/antigravity-plugin/core/memory_core.py)
- [integrations/kimi-plugin/core/memory_core.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/kimi-plugin/core/memory_core.py)
- [integrations/cursor-plugin/core/memory_core.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/cursor-plugin/core/memory_core.py)
- [integrations/codex-plugin/core/memory_core.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/codex-plugin/core/memory_core.py)
- [mem0/__init__.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/__init__.py)
- [integrations/claude-code-plugin/core/memory_core.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/claude-code-plugin/core/memory_core.py)
- [mem0/client/__init__.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/client/__init__.py)
- [integrations/mem0-agent-plugin/mcp.json](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-agent-plugin/mcp.json)
- [mem0/memory/__init__.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/memory/__init__.py)
- [cli/cli-spec.json](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/cli/cli-spec.json)
- [integrations/openclaw/index.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/openclaw/index.ts)
- [integrations/mem0-strands/python/src/mem0_strands/__init__.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-strands/python/src/mem0_strands/__init__.py)
- [cli/python/src/mem0_cli/__main__.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/cli/python/src/mem0_cli/__main__.py)
- [cli/python/src/mem0_cli/commands/__init__.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/cli/python/src/mem0_cli/commands/__init__.py)
- [integrations/mem0-agent-plugin/core/_harness_id.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-agent-plugin/core/_harness_id.py)
- [integrations/pi-agent-plugin/src/index.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/pi-agent-plugin/src/index.ts)
## Overview
Mem0 provides an extensible memory infrastructure and agent runtime integration suite designed to equip AI agents and applications with persistent context across dual deployment tiers: open-source (OSS) local backends and the hosted Mem0 Platform. At its core, the architecture coordinates cross-runtime command-line interfaces in both Python and Node.js [Python CLI Architecture](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/cli-tools/python-cli-architecture), [Node.js CLI Architecture](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/cli-tools/node-js-cli-architecture), alongside a unified family of agent harness plugins such as [Claude Code Plugin](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/agent-plugins/claude-code-plugin) that synchronize conversation history, background session flows, and diagnostic telemetry.
## Platform Architecture and Core Concepts
### Core Components and Client Entrypoints
Mem0 defines its foundational memory layers and client entrypoints across dedicated package modules. The core package exposes synchronous and asynchronous interfaces for both local engine management via `Memory` and `AsyncMemory`, alongside hosted cloud interactions through `MemoryClient` and `AsyncMemoryClient`.
| Component / Class | Module Path | Purpose |
| :--- | :--- | :--- |
| `Memory` | `mem0.memory.main` | Synchronous core memory engine for local management |
| `AsyncMemory` | `mem0.memory.main` | Asynchronous core memory engine |
| `MemoryClient` | `mem0.client.main` | Synchronous client interface for the Mem0 platform |
| `AsyncMemoryClient` | `mem0.client.main` | Asynchronous client interface for the Mem0 platform |
Sources: [mem0/__init__.py:5-6](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/__init__.py#L5-L6)
### Deployment Tiers and Versioning
The architecture operates across dual deployment tiers: open-source self-hosted backends and remote platform synchronization. Package versioning is dynamically retrieved via metadata for the underlying distribution (`mem0ai`), while command-line operations are governed by the dedicated CLI distribution version.
```python
"""mem0 CLI — the command-line interface for the mem0 memory layer."""
__version__ = "0.2.13"
```
Sources: [cli/python/src/mem0_cli/__init__.py:1-3](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/cli/python/src/mem0_cli/__init__.py#L1-L3), [mem0/__init__.py:1-3](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/__init__.py#L1-L3)
> [!NOTE]
> The Python core package inspects installed distribution metadata via `importlib.metadata.version("mem0ai")` to populate `__version__`, distinguishing the core library version from the `mem0-cli` package distribution version (`0.2.13`).
> Sources: [cli/python/src/mem0_cli/__init__.py:3-3](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/cli/python/src/mem0_cli/__init__.py#L3-L3), [mem0/__init__.py:3-3](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/__init__.py#L3-L3)
## Unified CLI Specification and Dual-Runtime Interfaces
### CLI Schema and Branding Specifications
Mem0 unifies its command-line interfaces through a cross-runtime JSON specification file (`cli/cli-spec.json`) that establishes metadata, brand assets, configuration directories, and remote API endpoints for both Python and Node client entrypoints. The specification defines global branding identifiers, color palettes, and operational icons used to render terminal output consistently across runtime boundaries.
| Branding Property | Key / Value | Purpose |
| :--- | :--- | :--- |
| `name` | `mem0` | CLI application command name |
| `version` | `0.1.0` | CLI specification version |
| `logoMini` | `◆ mem0` | Compact CLI banner logo |
| `brand` | `#8b5cf6` | Primary brand color hex code |
| `accent` | `#a78bfa` | Accent color hex code |
| `success` | `#22c55e` | Success indicator color |
| `error` | `#ef4444` | Error indicator color |
| `warning` | `#f59e0b` | Warning indicator color |
| `dim` | `#6b7280` | Dimmed text color |
Sources: [cli/cli-spec.json:1-34](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/cli/cli-spec.json#L1-L34)
> [!NOTE]
> The cross-runtime specification centralizes icon characters such as success (`✓`), error (`✗`), warning (`⚠`), info (`◆`), pending (`⧗`), add (`+`), update (`~`), delete (`-`), noop (`·`), connected (`●`), and disconnected (`●`) to ensure identical terminal rendering across Python and Node.js wrapper implementations.
> Sources: [cli/cli-spec.json:20-32](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/cli/cli-spec.json#L20-L32)
### Configuration Schema and Environment Bindings
Client configuration is structured around local directory storage combined with environment variable overrides. The configuration subsystem maps platform settings and default identifiers to specific environment variables, allowing seamless authentication and scoping for autonomous agents and developer workstations.
| Config Section | Field Name | Type | Default Value | Environment Variable | Redact |
| :--- | :--- | :--- | :--- | :--- | :--- |
| `platform` | `api_key` | `string` | `""` | `MEM0_API_KEY` | `true` |
| `platform` | `base_url` | `string` | `https://api.mem0.ai` | `MEM0_BASE_URL` | — |
| `defaults` | `user_id` | `string` | `""` | `MEM0_USER_ID` | — |
| `defaults` | `agent_id` | `string` | `""` | `MEM0_AGENT_ID` | — |
| `defaults` | `app_id` | `string` | `""` | `MEM0_APP_ID` | — |
| `defaults` | `run_id` | `string` | `""` | `MEM0_RUN_ID` | — |
| `defaults` | `enable_graph` | `boolean` | `false` | `MEM0_ENABLE_GRAPH` | — |
Sources: [cli/cli-spec.json:35-86](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/cli/cli-spec.json#L35-L86)
> [!WARNING]
> The `api_key` field enforces credential redaction (`redact: true`) within logs and configuration dumps, preventing sensitive tokens from leaking into terminal outputs or diagnostic telemetry.
> Sources: [cli/cli-spec.json:43-48](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/cli/cli-spec.json#L43-L48)
### REST Endpoint Mappings
The CLI specification maps remote control actions to standardized REST API endpoints, defining HTTP methods, path patterns, authentication headers, and entity type mappings for remote synchronization [Python Client SDK](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/python-core/python-client-sdk).
| Operation Name | HTTP Method | API Path Pattern |
| :--- | :--- | :--- |
| `add` | `POST` | `/v1/memories/` |
| `search` | `POST` | `/v2/memories/search/` |
| `get` | `GET` | `/v1/memories/{memory_id}/` |
| `list` | `POST` | `/v2/memories/` |
| `update` | `PUT` | `/v1/memories/{memory_id}/` |
| `delete` | `DELETE` | `/v1/memories/{memory_id}/` |
| `deleteAll` | `DELETE` | `/v1/memories/` |
| `entities` | `GET` | `/v1/entities/` |
| `deleteEntities` | `DELETE` | `/v1/entities/` |
Sources: [cli/cli-spec.json:87-98](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/cli/cli-spec.json#L87-L98)
> [!TIP]
> All REST requests enforce an authentication scheme using the `Authorization` header prefixed with the `Token` scheme, operating with a default network timeout of 30 seconds.
> Sources: [cli/cli-spec.json:99-101](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/cli/cli-spec.json#L99-L101)
## Agent Harness Architecture and Plugins Family
### Shared Core and Harness Configuration
The Mem0 agent plugin family relies on a shared core implementation (`memory_core.py`) that handles session event recording, background flushing, redacting sensitive secrets, and local storage operations across diverse IDE harnesses and coding assistants. Plugins configure their runtime environment using `configure_harness()`, which sets up harness-specific naming prefixes, data directories, and source tags for telemetry tracking.
| Harness Parameter | Default Value | Purpose |
| :--- | :--- | :--- |
| `name` | `generic` | Identifier for the active coding assistant harness |
| `env_prefix` | `MEM0_PLUGIN` | Environment variable prefix for configuration overrides |
| `data_dir_name` | `mem0-plugin` | Directory name for local evidence and state storage |
| `source_tag` | `mem0_plugin` | Telemetry source tag identifying the originating plugin |
Sources: [integrations/mem0-agent-plugin/core/memory_core.py:34-38](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-agent-plugin/core/memory_core.py#L34-L38), [integrations/antigravity-plugin/core/memory_core.py:34-38](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/antigravity-plugin/core/memory_core.py#L34-L38), [integrations/kimi-plugin/core/memory_core.py:34-38](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/kimi-plugin/core/memory_core.py#L34-L38), [integrations/cursor-plugin/core/memory_core.py:34-38](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/cursor-plugin/core/memory_core.py#L34-L38), [integrations/codex-plugin/core/memory_core.py:34-38](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/codex-plugin/core/memory_core.py#L34-L38)
> [!NOTE]
> The shared core defines strict operational boundaries including command, result, and episode character limits, extraction input token caps, and a maximum of 5 flush attempts for offline retry queues.
> Sources: [integrations/mem0-agent-plugin/core/memory_core.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-agent-plugin/core/memory_core.py#L62-L72), [integrations/antigravity-plugin/core/memory_core.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/antigravity-plugin/core/memory_core.py#L62-L72), [integrations/kimi-plugin/core/memory_core.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/kimi-plugin/core/memory_core.py#L62-L72), [integrations/cursor-plugin/core/memory_core.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/cursor-plugin/core/memory_core.py#L62-L72), [integrations/codex-plugin/core/memory_core.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/codex-plugin/core/memory_core.py#L62-L72)
### Diagnostic CLI and Control Operations
Each IDE plugin embeds a command-line interface (`memory_cli.py`) that exposes diagnostic checks, user controls, and lifecycle actions for managing local and remote memories. The CLI uses Python's `argparse` module to dispatch subcommands such as status inspection, health diagnostics, pausing, resuming, and repository purging.
| CLI Subcommand | Arguments / Flags | Action Performed |
| :--- | :--- | :--- |
| `status` | `--json` | Prints operational summary, repo ID, local data path, and API key status |
| `doctor` | `--json` | Runs diagnostic checks against the current workspace and environment |
| `pause` | — | Stops saving and searching memories locally |
| `resume` | — | Resumes saving and searching memories locally |
| `forget` | `--remote`, `--yes`, `--include-project-memory` | Deletes local repository evidence and optionally purges remote scopes |
Sources: [integrations/mem0-agent-plugin/core/memory_cli.py:61-80](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-agent-plugin/core/memory_cli.py#L61-L80), [integrations/antigravity-plugin/core/memory_cli.py:61-80](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/antigravity-plugin/core/memory_cli.py#L61-L80), [integrations/kimi-plugin/core/memory_cli.py:61-80](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/kimi-plugin/core/memory_cli.py#L61-L80), [integrations/cursor-plugin/core/memory_cli.py:61-80](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/cursor-plugin/core/memory_cli.py#L61-L80), [integrations/codex-plugin/core/memory_cli.py:61-80](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/codex-plugin/core/memory_cli.py#L61-L80)
> [!WARNING]
> The `forget` command enforces a safety check requiring the `--yes` flag; without it, the command refuses to delete data and exits with code 2.
> Sources: [integrations/mem0-agent-plugin/core/memory_cli.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-agent-plugin/core/memory_cli.py#L123-L129), [integrations/antigravity-plugin/core/memory_cli.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/antigravity-plugin/core/memory_cli.py#L123-L129), [integrations/kimi-plugin/core/memory_cli.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/kimi-plugin/core/memory_cli.py#L123-L129), [integrations/cursor-plugin/core/memory_cli.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/cursor-plugin/core/memory_cli.py#L123-L129), [integrations/codex-plugin/core/memory_cli.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/codex-plugin/core/memory_cli.py#L123-L129)
### MCP Server Integration and Manifests
Model Context Protocol (MCP) manifests (`mcp.json`) bind the memory core into host IDE environments using standard input/output transport streams. The manifest defines server registration parameters that execute the Python MCP server script within the plugin root directory.
```json
{
"$schema": "https://agent-plugins.org/schemas/1.0.0/mcp.schema.json",
"mcpServers": {
"mem0": {
"type": "stdio",
"command": "python3",
"args": [
"${PLUGIN_ROOT}/core/mcp_server.py"
]
}
}
}
```
Sources: [integrations/mem0-agent-plugin/mcp.json:1-12](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-agent-plugin/mcp.json#L1-L12)
## External Agent and Workflow Ecosystem
### OpenClaw and Pi Agent Integrations
Mem0 extends beyond core LLM memory engines by providing specialized integrations for agent frameworks, runtime environments, and workflow automation tools. These packages bridge external architectures into the Mem0 memory fabric without requiring custom storage layers.
The [OpenClaw Integration](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/agent-plugins/openclaw-integration) plugin (`openclaw-mem0`) exposes six core memory tools (`memory_search`, `memory_add`, `memory_get`, `memory_list`, `memory_update`, and `memory_delete`) while handling automatic recall and capture across agent turns. It isolates multi-agent setups by routing per-agent namespaces through session key resolution and supports both platform and self-hosted backends. Similarly, the [Pi Agent Plugin](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/agent-plugins/pi-agent-plugin) package structures memory management through exported configuration loaders, scoping handlers, formatting utilities, and command extensions.
```typescript
/**
* OpenClaw Memory (Mem0) Plugin
*
* Long-term memory via Mem0 — supports both the Mem0 platform
* and the open-source self-hosted SDK. Uses the official `mem0ai` package.
*
* Features:
* - 6 core tools: memory_search, memory_add, memory_get, memory_list,
* memory_update, memory_delete
* - Short-term (session-scoped) and long-term (user-scoped) memory
* - Auto-recall: injects relevant memories (both scopes) before each agent turn
* - Auto-capture: stores key facts scoped to the current session after each agent turn
* - Per-agent isolation: multi-agent setups write/read from separate userId namespaces
* automatically via sessionKey routing (zero breaking changes for single-agent setups)
* - CLI: openclaw mem0 search, openclaw mem0 status
* - Dual mode: platform or open-source (self-hosted)
*/
```
Sources: [integrations/openclaw/index.ts:1-17](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/openclaw/index.ts#L1-L17)
```typescript
export type {
Scope,
Mem0Config,
ScopeContext,
CustomCategory,
} from "./types.ts";
export { DEFAULT_CUSTOM_CATEGORIES } from "./types.ts";
export { loadConfig, CONFIG_DIR } from "./config/index.ts";
export { registerMemoryTool, buildToolExecute } from "./memory/tools.ts";
export { detectAppId, detectRunId, resolveSearchFilters, resolveAddParams } from "./memory/scoping.ts";
export { formatAge, formatMemoryCompact, formatMemoryList, groupByCategory } from "./memory/formatting.ts";
export { setupAutoCapture, extractConversation } from "./capture/index.ts";
export { MEMORY_POLICY } from "./prompt.ts";
export { registerCommands } from "./commands.ts";
export { captureEvent, captureToolEvent, captureCommandEvent, _getEventQueue, _resetForTesting } from "./telemetry.ts";
```
Sources: [integrations/pi-agent-plugin/src/index.ts:1-22](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/pi-agent-plugin/src/index.ts#L1-L22)
> [!NOTE]
> The OpenClaw plugin reads authentication settings dynamically from `openclaw.json` plugin config via `readPluginAuth()`, accommodating post-startup login commands (`openclaw mem0 login`) as the single source of truth.
> Sources: [integrations/openclaw/index.ts:98-104](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/openclaw/index.ts#L98-L104)
### Strands Agent Framework Integration
The [Mem0 Strands](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/ecosystem-integrations/mem0-strands) package (`mem0-strands`) provides persistent long-term memory for Strands agents via `Mem0MemoryStore`. It plugs into agent execution loops through a `MemoryManager` to deliver automatic memory injection and extraction.
```python
"""Strands Mem0 -- persistent long-term memory for Strands agents, backed by Mem0.
:class:`Mem0MemoryStore` is a Strands ``MemoryStore`` that plugs into the agent
loop via a :class:`~strands.memory.MemoryManager`, with automatic memory injection
and extraction. It implements both write sinks, so ``extraction`` uses Mem0's
server-side extraction (no extra model call).
For the explicit, model-called tool (``store`` / ``retrieve`` / ``get`` / ``delete``),
use the ``mem0_memory`` tool from ``strands-agents-tools``; a store and the tool can
share one Mem0 backend and namespace.
"""
```
Sources: [integrations/mem0-strands/python/src/mem0_strands/__init__.py:1-11](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-strands/python/src/mem0_strands/__init__.py#L1-L11)
> [!TIP]
> `Mem0MemoryStore` implements both write sinks so that extraction leverages Mem0's server-side extraction natively, avoiding extra language model calls during agent execution.
> Sources: [integrations/mem0-strands/python/src/mem0_strands/__init__.py:4-6](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-strands/python/src/mem0_strands/__init__.py#L4-L6)
## Cross-Subsystem Data and Telemetry Flow
### Background Telemetry and Execution Coordination
End-to-end data coordination across host harnesses, background sync workers, and anonymized diagnostic telemetry relies on decoupled logging and asynchronous flushing. In agent CLI implementations, commands execute within an instantiated `EvidenceStore` context that records control actions, telemetry payloads, and local sqlite state updates before finalizing execution through deferred background worker threads.
```python
if args.plugin_data_dir:
os.environ["MEM0_CODE_DATA_DIR"] = args.plugin_data_dir
store = EvidenceStore()
try:
repo = resolve_repo(os.getcwd())
telemetry.record("control", repo=repo, action=args.command)
```
Sources: [integrations/mem0-agent-plugin/core/memory_cli.py:86-91](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-agent-plugin/core/memory_cli.py#L86-L91)
```python
finally:
store.close()
telemetry.spawn_flush()
return 0
```
Sources: [integrations/mem0-agent-plugin/core/memory_cli.py:147-150](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-agent-plugin/core/memory_cli.py#L147-L150)
> [!NOTE]
> Telemetry flushing and local store closures are guaranteed via a `finally` block in CLI entry points, invoking `telemetry.spawn_flush()` to transmit diagnostics asynchronously without blocking shell process exit.
> Sources: [integrations/mem0-agent-plugin/core/memory_cli.py:147-150](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-agent-plugin/core/memory_cli.py#L147-L150)
### Harness Configuration and Data Routing
Runtime contexts receive environment parameters, configuration prefixes, and source identifiers through modular configuration routines. The harness configuration initializes specific global variables governing environment lookup paths, local plugin data directories, and source telemetry tagging.
```python
def configure_harness(
name: str,
env_prefix: str = "",
data_dir_name: str = "",
source_tag: str = "",
) -> None:
global _harness_name, _harness_env_prefix, _harness_data_dir_name, _harness_source_tag
_harness_name = name
_harness_env_prefix = env_prefix or f"MEM0_{name.upper().replace('-', '_')}"
_harness_data_dir_name = data_dir_name or f"{name}-plugin"
_harness_source_tag = source_tag or f"{name.replace('-', '_')}_plugin"
```
Sources: [integrations/mem0-agent-plugin/core/memory_core.py:40-51](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-agent-plugin/core/memory_core.py#L40-L51)
| Parameter | Default Value | Purpose | Sources |
| :--- | :--- | :--- | :--- |
| `name` | `"generic"` | Identifies the active agent harness or plugin framework | [integrations/mem0-agent-plugin/core/memory_core.py:34](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-agent-plugin/core/memory_core.py#L34) |
| `env_prefix` | `"MEM0_PLUGIN"` | Prefix for environment variable overrides | [integrations/mem0-agent-plugin/core/memory_core.py:35](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-agent-plugin/core/memory_core.py#L35) |
| `data_dir_name` | `"mem0-plugin"` | Subdirectory name for local evidence and state storage | [integrations/mem0-agent-plugin/core/memory_core.py:36](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-agent-plugin/core/memory_core.py#L36) |
| `source_tag` | `"mem0_plugin"` | Telemetry tag identifying the event origin channel | [integrations/mem0-agent-plugin/core/memory_core.py:37](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-agent-plugin/core/memory_core.py#L37) |
Sources: [integrations/mem0-agent-plugin/core/memory_core.py:34-51](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-agent-plugin/core/memory_core.py#L34-L51)
## Where to go next
| I want to… | Read |
| --- | --- |
| How do developers and autonomous agents initialize Mem0, capture conversational memories, and query hybrid memory stores with copy-pasteable snippets across Python and Node.js? | [Quick Start](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/orientation/quick-start) |
| How is the Mem0 monorepo organized across Python packages, TypeScript packages, FastAPI backend, Next.js dashboard, CLI implementations, and agent plugins? | [Project Structure](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/orientation/project-structure) |
| How does the Python core memory engine extract, add, update, delete, search, and reset user, agent, and session memories using LLMs and vector backends? | [Memory Lifecycle](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/python-core/memory-lifecycle) |
| How does the Python retrieval engine fuse dense vector similarity, BM25 keyword matching, entity boosting, and temporal recency scoring to rank memories? | [Multi-Signal Retrieval](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/python-core/multi-signal-retrieval) |
| How does the Python engine record state changes, manage SQLite or relational audit logs, and isolate user, agent, run, and metadata scopes? | [Storage and History](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/python-core/storage-and-history) |
| How does Mem0 parse structured entities and temporal facts from raw messages using spaCy and entity extraction pipelines for cross-memory linking? | [Entity Extraction](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/python-core/entity-extraction) |
| How does the Python client interface with the Mem0 hosted platform and self-hosted HTTP endpoints for remote memory synchronization and project scoping? | [Python Client SDK](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/python-core/python-client-sdk) |
| How does the TypeScript OSS package implement the core Memory class, orchestrate LLM extraction, manage message state, and execute CRUD memory operations? | [Typescript Core](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/typescript-core/typescript-core) |
| How does the Python core adapt diverse LLM backends (OpenAI, Anthropic, Bedrock, DeepSeek, Gemini, Groq, Ollama, vLLM, LiteLLM) for structured fact extraction? | [Python LLM Adapters](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/llm-providers/python-llm-adapters) |
| How does the TypeScript engine configure and communicate with language model providers including OpenAI, Anthropic, Google, DeepSeek, and Mistral? | [TypeScript LLM Adapters](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/llm-providers/typescript-llm-adapters) |
| How does the Python engine generate vector embeddings across OpenAI, Azure OpenAI, AWS Bedrock, FastEmbed, Gemini, Hugging Face, Ollama, and Vertex AI? | [Python Embedding Adapters](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/llm-providers/python-embedding-adapters) |
| How does the TypeScript engine instantiate and call embedding generators across providers such as OpenAI, Google, Hugging Face, Bedrock, and FastEmbed? | [TypeScript Embedding Adapters](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/llm-providers/typescript-embedding-adapters) |
| How do Cohere, Hugging Face Cross-Encoder, LLM-based, Sentence Transformer, and ZeroEntropy rerankers re-score candidate memory retrievals? | [Reranking Models](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/llm-providers/reranking-models) |
| What base abstractions, collection schemas, and query filters govern vector store drivers across both Python and TypeScript runtimes? | [Vector Store Architecture](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/vector-stores/vector-store-architecture) |
| How do Qdrant, Pinecone, Milvus, Weaviate, Turbopuffer, Upstash, and S3 Vectors execute cloud-native vector insertion and ANN querying? | [Cloud Vector Backends](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/vector-stores/cloud-vector-backends) |
| How do relational and search engines (pgvector, Elasticsearch, OpenSearch, Redis, Valkey, Cassandra, Neptune Analytics, Oracle, MongoDB, Azure AI Search, Baidu) store embeddings? | [Database Vector Stores](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/vector-stores/database-vector-stores) |
| How do Chroma, FAISS, and in-memory vector implementations provide zero-dependency local indexing for prototyping and unit testing? | [Embedded Vector Stores](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/vector-stores/embedded-vector-stores) |
| How does the self-hosted FastAPI application bootstrap application state, handle CORS, register routers, enforce rate limits, and map errors? | [FastAPI Application](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/server-dashboard/fastapi-application) |
| How does the server issue and validate API keys, manage user passwords, enforce admin RBAC, and handle JWT refresh tokens? | [Server Authentication](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/server-dashboard/server-authentication) |
| How are database connections, SQLAlchemy models, and Alembic migrations structured for user credentials, API keys, request logs, and system settings? | [Database and Migrations](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/server-dashboard/database-and-migrations) |
| What REST endpoints and schemas are exposed for memory manipulation, entity browsing, API key rotation, request telemetry, and health inspection? | [Server API Endpoints](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/server-dashboard/server-api-endpoints) |
| How is the Next.js admin dashboard structured with Redux store state, API query hooks, authentication session providers, and setup wizards? | [Dashboard Architecture](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/server-dashboard/dashboard-architecture) |
| How do the memories, entities, analytics, API keys, webhooks, and settings dashboard pages render system data and trigger admin mutations? | [Dashboard Views](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/server-dashboard/dashboard-views) |
| How does the Python CLI dispatch terminal commands, switch backends (OSS vs Platform), and format rich output? | [Python CLI Architecture](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/cli-tools/python-cli-architecture) |
| How does the TypeScript/Node.js CLI process command line options, resolve authentication tokens, and talk to platform or local backends? | [Node.js CLI Architecture](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/cli-tools/node-js-cli-architecture) |
| How do the CLI init and agent mode commands allow autonomous agents to mint API keys without web browsers and later claim accounts? | [Agent Account Provisioning](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/cli-tools/agent-account-provisioning) |
| How does the CLI sync configuration, MCP tool declarations, and hooks into agent IDE environments? | [Plugin Synchronization](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/cli-tools/plugin-synchronization) |
| How does the common Python plugin core implement memory capture, background flush workers, hook runners, and MCP servers across IDE plugins? | [Python Agent Core](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/agent-plugins/python-agent-core) |
| How does the common TypeScript agent core manage lifecycle hooks, session scoping, prompt synthesis, identity detection, and memory formatting? | [TypeScript Agent Core](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/agent-plugins/typescript-agent-core) |
| How does the Claude Code plugin intercept transcript streams and run MCP tools to synchronize conversation history with Mem0? | [Claude Code Plugin](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/agent-plugins/claude-code-plugin) |
| How do the Cursor, Codex, Kimi, and Antigravity plugins configure MCP manifests, adapt host event hooks, and forward IDE state? | [IDE Plugins Family](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/agent-plugins/ide-plugins-family) |
| How does OpenClaw register memory tools, handle isolation and recall, provide CLI setup wizards, and execute memory CRUD operations? | [OpenClaw Integration](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/agent-plugins/openclaw-integration) |
| How does the OpenCode plugin bind workspace project scopes, manage API key authentication, and inject memories into developer agent turns? | [OpenCode Integration](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/agent-plugins/opencode-integration) |
| How does the Pi Agent plugin implement attribution, command handling, memory formatting, and scoping for agent execution loops? | [Pi Agent Plugin](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/agent-plugins/pi-agent-plugin) |
| How does the Hermes plugin bridge Mem0 memory management into Hermes agent pipelines using custom LLM bindings? | [Hermes Plugin](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/agent-plugins/hermes-plugin) |
| How does Mem0 wrap Vercel AI SDK LanguageModel instances to inject long-term user context and intercept completions? | [Vercel AI SDK Integration](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/ecosystem-integrations/vercel-ai-sdk-integration) |
| How does the mem0-strands package structure thread-level and hierarchical memory graphs for complex agent trajectories? | [Mem0 Strands](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/ecosystem-integrations/mem0-strands) |
| How does the n8n community node expose Mem0 memory operations inside low-code workflow automations? | [n8n Workflow Nodes](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/ecosystem-integrations/n8n-workflow-nodes) |
| How does the Zapier integration implement authentication, memory addition, deletion, and search triggers for automated app zaps? | [Zapier Integration](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/ecosystem-integrations/zapier-integration) |
| How do developer agent skills and the doc search tool provide inline documentation retrieval to AI coding assistants? | [Documentation Agent Skills](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/ecosystem-integrations/documentation-agent-skills) |
| How does Mem0 record, anonymize, and transmit anonymous usage metrics across Python, TypeScript, CLI, and server components? | [Telemetry and Metrics](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/telemetry-ops/telemetry-and-metrics) |
| How does the conformance suite validate plugin adapters and harness behaviors against standardized memory artifacts? | [Plugin Conformance Testing](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/telemetry-ops/plugin-conformance-testing) |
| How do operators migrate memory collections, vector embeddings, and configurations from open-source instances to the Mem0 cloud platform? | [OSS to Platform Migration](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/telemetry-ops/oss-to-platform-migration) |
## Related
- [Quick Start](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/orientation/quick-start)
- [Project Structure](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/orientation/project-structure)
- [Memory Lifecycle](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/python-core/memory-lifecycle)
---
## Technical docs: GET List bundled LLM and embedder providers
URL: https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/api/endpoints/list-bundled-providers
## Responses
## Try It
---
## Technical docs: Quick Start
URL: https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/orientation/quick-start
Relevant source files
The following files were used as context for generating this wiki page:
- [mem0-ts/src/community/src/integrations/langchain/mem0.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/community/src/integrations/langchain/mem0.ts)
- [integrations/opencode-plugin/opencode-mem0.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/opencode-plugin/opencode-mem0.ts)
- [integrations/hermes-plugin-mem0/__init__.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/hermes-plugin-mem0/__init__.py)
- [mem0-ts/src/oss/src/memory/index.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/memory/index.ts)
- [integrations/mem0-strands/python/src/mem0_strands/store.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-strands/python/src/mem0_strands/store.py)
- [integrations/deepseek-plugin/src/index.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/deepseek-plugin/src/index.ts)
- [integrations/agent-plugin-core/python/memory_core.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/agent-plugin-core/python/memory_core.py)
- [integrations/antigravity-plugin/core/memory_core.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/antigravity-plugin/core/memory_core.py)
- [integrations/mem0-agent-plugin/core/memory_core.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-agent-plugin/core/memory_core.py)
- [integrations/codex-plugin/core/memory_core.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/codex-plugin/core/memory_core.py)
- [integrations/kimi-plugin/core/memory_core.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/kimi-plugin/core/memory_core.py)
- [integrations/claude-code-plugin/core/memory_core.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/claude-code-plugin/core/memory_core.py)
- [integrations/cursor-plugin/core/memory_core.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/cursor-plugin/core/memory_core.py)
- [cli/node/src/index.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/cli/node/src/index.ts)
- [mem0/memory/main.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/memory/main.py)
- [mem0/configs/prompts.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/configs/prompts.py)
- [mem0-ts/src/oss/src/prompts/index.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/prompts/index.ts)
- [integrations/vercel-ai-sdk/src/mem0-utils.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/vercel-ai-sdk/src/mem0-utils.ts)
- [integrations/mem0-strands/python/src/mem0_strands/__init__.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-strands/python/src/mem0_strands/__init__.py)
- [integrations/n8n-nodes-mem0/nodes/Mem0/Mem0.node.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/n8n-nodes-mem0/nodes/Mem0/Mem0.node.ts)
- [integrations/mem0-strands/python/src/mem0_strands/client.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/mem0-strands/python/src/mem0_strands/client.py)
- [mem0/proxy/main.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/proxy/main.py)
- [mem0/__init__.py](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/__init__.py)
- [integrations/pi-agent-plugin/src/prompt.ts](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/pi-agent-plugin/src/prompt.ts)
## Overview
This quick start guide demonstrates how to install, initialize, and integrate Mem0 across Python and TypeScript environments to equip language models and coding agents with persistent, context-aware memory [Python Agent Core](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/agent-plugins/python-agent-core), [Typescript Core](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/typescript-core/typescript-core). By combining client instantiation, conversational write paths, and scoped semantic search, developers can store user preferences, manage project trajectories, and bridge agent frameworks without boilerplate [Memory Lifecycle](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/python-core/memory-lifecycle), [Mem0 Strands](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/ecosystem-integrations/mem0-strands).
```typescript
constructor(config: Partial = {}) {
// Merge and validate config
this.config = ConfigManager.mergeConfig(config);
```
Sources: [mem0-ts/src/oss/src/memory/index.ts:220-222](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/oss/src/memory/index.ts#L220-L222)
The architecture supports both local self-hosted configurations and the managed Mem0 platform [Hermes Plugin](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/agent-plugins/hermes-plugin), enabling seamless zero-code proxying via OpenAI-compatible endpoints Proxy as well as native plugins for ecosystem harnesses like LangChain mem0.ts, Vercel AI SDK mem0-utils.ts, and IDE assistants [Claude Code Plugin](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/agent-plugins/claude-code-plugin).
```typescript
add_memory: tool({
description: "Add a new memory. This method is called everytime the user informs anything about themselves, their preferences, or anything that has any relevant information which can be useful in the future conversation. This can also be called when the user asks you to remember something. Set infer to false to store the memory verbatim without LLM fact extraction.",
args: {
text: tool.schema.string().describe("Memory text content"),
user_id: tool.schema.string().optional().describe("User ID"),
app_id: tool.schema.string().optional().describe("App/Project ID"),
agent_id: tool.schema.string().optional().describe("Agent ID"),
metadata: tool.schema.record(tool.schema.string(), tool.schema.any()).optional().describe("Metadata key-value pairs"),
infer: tool.schema.boolean().optional().describe("Set to false to store memory verbatim without LLM fact extraction"),
scope: tool.schema.string().optional().describe('Write scope: "project" (this repo, default), "session" (this run), or "global" (user-wide, all projects). Use "global" only when explicitly asked.')
},
```
Sources: [integrations/opencode-plugin/opencode-mem0.ts:380-390](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/opencode-plugin/opencode-mem0.ts#L380-L390)
## Installing and Initializing Mem0
### Python and TypeScript SDK Setup
To install Mem0 in Python and TypeScript environments, package managers install the core client libraries from PyPI and npm. Python environments import `Memory` or `MemoryClient` from the `mem0` package mem0/__init__.py, while TypeScript projects utilize `MemoryClient` from `mem0ai` or community integrations such as `Mem0Memory` mem0-ts/src/community/src/integrations/langchain/mem0.ts.
```bash
pip install mem0ai
npm install mem0ai @langchain/core @langchain/community
```
Sources: [mem0-ts/src/community/src/integrations/langchain/mem0.ts:1-2](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/community/src/integrations/langchain/mem0.ts#L1-L2), [mem0/__init__.py:3-6](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/__init__.py#L3-L6)
### Client Instantiation and Configuration
Client initialization requires passing configuration options containing credentials and optional host endpoints. In TypeScript, `Mem0Memory` validates that both `apiKey` and `sessionId` are present during construction before instantiating the underlying `MemoryClient` mem0-ts/src/community/src/integrations/langchain/mem0.ts.
```typescript
import { Mem0Memory } from "./mem0";
const memory = new Mem0Memory({
sessionId: "user123",
apiKey: "your-api-key",
memoryOptions: {
user_id: "user123",
},
});
```
Sources: [mem0-ts/src/community/src/integrations/langchain/mem0.ts:151-206](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/community/src/integrations/langchain/mem0.ts#L151-L206)
> [!WARNING]
> Omitting `apiKey` or `sessionId` when constructing `Mem0Memory` throws an immediate runtime error before any client connection occurs.
Sources: [mem0-ts/src/community/src/integrations/langchain/mem0.ts:172-178](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/community/src/integrations/langchain/mem0.ts#L172-L178)
| Property | Type | Default | Purpose |
| :--- | :--- | :--- | :--- |
| `apiKey` | `string` | *Required* | Authentication credential for the Mem0 service |
| `sessionId` | `string` | *Required* | Unique identifier for the chat session or user scope |
| `memoryKey` | `string` | `"history"` | Key used to store and retrieve memory variables in LangChain |
| `humanPrefix` | `string` | `"Human"` | Prefix label for human utterances in formatted buffer strings |
| `aiPrefix` | `string` | `"AI"` | Prefix label for assistant responses in formatted buffer strings |
| `separateMessages` | `boolean` | `false` | Return separate messages for chat history versus a single condensed `HumanMessage` |
Sources: [mem0-ts/src/community/src/integrations/langchain/mem0.ts:152-170](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/community/src/integrations/langchain/mem0.ts#L152-L170)
## Storing Conversational Context
### Conversation Context Capture and Extraction
### LangChain Integration and Message Condensation
```typescript
import { Mem0Memory } from "./mem0";
import { ChatOpenAI } from "@langchain/openai";
import { ConversationChain } from "langchain/chains";
const memory = new Mem0Memory({
sessionId: "user123",
apiKey: process.env.MEM0_API_KEY!,
memoryOptions: {
user_id: "user123",
},
});
const model = new ChatOpenAI({
modelName: "gpt-4o-mini",
temperature: 0,
});
const chain = new ConversationChain({ llm: model, memory });
```
Sources: [mem0-ts/src/community/src/integrations/langchain/mem0.ts:131-149](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/community/src/integrations/langchain/mem0.ts#L131-L149)
```typescript
export const condenseMem0MemoryIntoHumanMessage = (
memory: Memory[],
): HumanMessage => {
const basePrompt =
"These are the memories I have stored. Give more weightage to the question by users and try to answer that first. You have to modify your answer based on the memories I have provided. If the memories are irrelevant you can ignore them. Also don't reply to this section of the prompt, or the memories, they are only for your reference. The MEMORIES of the USER are: \n\n";
const systemPrompt = mem0MemoryContextToSystemPrompt(memory);
return new HumanMessage(`${basePrompt}\n${systemPrompt}`);
};
```
Sources: [mem0-ts/src/community/src/integrations/langchain/mem0.ts:50-58](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/community/src/integrations/langchain/mem0.ts#L50-L58)
> [!NOTE]
> `condenseMem0MemoryIntoHumanMessage` formats retrieved memories into a single instruction-prefixed `HumanMessage` by default, instructing the model to prioritize direct user questions while referencing stored facts.
Sources: [mem0-ts/src/community/src/integrations/langchain/mem0.ts:50-58](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/community/src/integrations/langchain/mem0.ts#L50-L58)
### Memory Formatting Utilities
```typescript
export const mem0MemoryToMessages = (memories: Memory[]): BaseMessage[] => {
if (!memories || !Array.isArray(memories)) {
return [];
}
const messages: BaseMessage[] = [];
const memoryContent = memories
.filter((m) => m?.memory)
.map((m) => m.memory)
.join("\n");
if (memoryContent) {
messages.push(new SystemMessage(memoryContent));
}
memories.forEach((memory) => {
if (memory.messages) {
memory.messages.forEach((msg) => {
const content =
typeof msg.content === "string"
? msg.content
: JSON.stringify(msg.content);
if (msg.role === "user") {
messages.push(new HumanMessage(content));
} else if (msg.role === "assistant") {
messages.push(new AIMessage(content));
} else if (content) {
messages.push(new ChatMessage(content, msg.role));
}
});
}
});
return messages;
};
```
Sources: [mem0-ts/src/community/src/integrations/langchain/mem0.ts:65-102](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/community/src/integrations/langchain/mem0.ts#L65-L102)
> [!TIP]
> Setting `separateMessages: true` in `Mem0MemoryInput` causes `loadMemoryVariables` to return distinct `SystemMessage` and chat history objects via `mem0MemoryToMessages` rather than a unified prompt block.
Sources: [mem0-ts/src/community/src/integrations/langchain/mem0.ts:123-124](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/community/src/integrations/langchain/mem0.ts#L123-L124), [mem0-ts/src/community/src/integrations/langchain/mem0.ts:240-246](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/community/src/integrations/langchain/mem0.ts#L240-L246)
## Querying Memories Across Scopes
### Semantic Retrieval and Scoped Parameters
Memories can be queried dynamically based on conversation input or retrieved entirely via scoped identifiers. When input values are present during memory loading, `Mem0Memory` executes a semantic search query against the client; otherwise, it retrieves all stored records for the target entity.
```typescript
async loadMemoryVariables(values: InputValues): Promise {
const searchType = values.input ? "search" : "get_all";
let memories: Memory[] = [];
try {
if (searchType === "get_all") {
memories = await this.mem0Client.getAll({
user_id: this.sessionId,
...this.memoryOptions,
});
} else {
memories = await this.mem0Client.search(values.input, {
user_id: this.sessionId,
...this.memoryOptions,
});
}
} catch (error) {
console.error("Error loading memories:", error);
return this.returnMessages
? { [this.memoryKey]: [] }
: { [this.memoryKey]: "" };
}
if (this.returnMessages) {
return {
[this.memoryKey]: this.separateMessages
? mem0MemoryToMessages(memories)
: [condenseMem0MemoryIntoHumanMessage(memories)],
};
}
return {
[this.memoryKey]: this.separateMessages
? getBufferString(
mem0MemoryToMessages(memories),
this.humanPrefix,
this.aiPrefix,
)
: (condenseMem0MemoryIntoHumanMessage(memories).content ?? ""),
};
}
```
Sources: [mem0-ts/src/community/src/integrations/langchain/mem0.ts:217-257](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/community/src/integrations/langchain/mem0.ts#L217-L257)
> [!WARNING]
> If a query execution throws an error during `loadMemoryVariables`, the method catches the failure and returns an empty array or empty string depending on `returnMessages` configuration rather than interrupting the chat chain.
Sources: [mem0-ts/src/community/src/integrations/langchain/mem0.ts:233-238](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/community/src/integrations/langchain/mem0.ts#L233-L238)
### Agent Harness Filtering and Tool Parameters
Agent harnesses partition memory access using granular identifiers such as user IDs, agent IDs, and run IDs. For instance, the DeepSeek integration registers a `search_memory` tool that validates user overrides and resolves filters prior to querying the vector client.
```typescript
const scopeParams = {
userId: {
type: "string",
description:
"Entity that owns the memory. Defaults to the plugin's configured userId; cross-user overrides require allowUserOverride in plugin configuration.",
},
agentId: {
type: "string",
description: "Optional agent scope, to partition memories by agent.",
},
runId: {
type: "string",
description: "Optional run/session scope, to partition memories by session.",
},
} as const;
```
Sources: [integrations/deepseek-plugin/src/index.ts:80-94](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/deepseek-plugin/src/index.ts#L80-L94)
> [!CAUTION]
> The platform rejects top-level entity parameters during search operations; search scopes must be nested inside the `filters` property, unlike memory addition calls which accept top-level parameters.
Sources: [integrations/deepseek-plugin/src/index.ts:200-202](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/deepseek-plugin/src/index.ts#L200-L202)
## Configuring Framework and SDK Adapters
### LangChain Integration Architecture
The LangChain integration package maps Mem0 persistent memory storage into LangChain memory management abstractions through the `Mem0Memory` class. This class extends `BaseChatMemory` to load, format, and save conversational turns and retrieved facts using `MemoryClient` from `mem0ai`.
```typescript
export class Mem0Memory extends BaseChatMemory implements Mem0MemoryInput {
memoryKey = "history";
apiKey: string;
sessionId: string;
humanPrefix = "Human";
aiPrefix = "AI";
mem0Client: InstanceType;
memoryOptions: AddMemoryOptions | SearchMemoryOptions | GetAllMemoryOptions;
mem0Options: ClientOptions;
separateMessages?: boolean;
```
Sources: [mem0-ts/src/community/src/integrations/langchain/mem0.ts:151-170](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/community/src/integrations/langchain/mem0.ts#L151-L170)
Formatting utilities transform retrieved memory items into structured message formats or consolidated prompt strings. The `condenseMem0MemoryIntoHumanMessage` function builds a `HumanMessage` incorporating stored facts with explicit instructions for the model to prioritize user questions and treat retrieved memory strictly as reference context.
```typescript
export const condenseMem0MemoryIntoHumanMessage = (
memory: Memory[],
): HumanMessage => {
const basePrompt =
"These are the memories I have stored. Give more weightage to the question by users and try to answer that first. You have to modify your answer based on the memories I have provided. If the memories are irrelevant you can ignore them. Also don't reply to this section of the prompt, or the memories, they are only for your reference. The MEMORIES of the USER are: \n\n";
const systemPrompt = mem0MemoryContextToSystemPrompt(memory);
return new HumanMessage(`${basePrompt}\n${systemPrompt}`);
};
```
Sources: [mem0-ts/src/community/src/integrations/langchain/mem0.ts:50-58](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/community/src/integrations/langchain/mem0.ts#L50-L58)
> [!TIP]
> Setting `separateMessages: true` in `Mem0MemoryInput` causes `loadMemoryVariables` to return distinct `SystemMessage` instances and chat history objects via `mem0MemoryToMessages` rather than collapsing all context into a single unified prompt block.
Sources: [mem0-ts/src/community/src/integrations/langchain/mem0.ts:116-124](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/community/src/integrations/langchain/mem0.ts#L116-L124), [mem0-ts/src/community/src/integrations/langchain/mem0.ts:240-246](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0-ts/src/community/src/integrations/langchain/mem0.ts#L240-L246)
### Vercel AI SDK Utilities
The Vercel AI SDK utilities module provides functions for adding, updating, retrieving, and searching memories within language model pipelines. The `updateMemories` function dispatches POST requests to the Mem0 API endpoint, transmitting conversation messages alongside optional configuration fields with specific attribution headers.
```typescript
const updateMemories = async (messages: Array, config?: Mem0ConfigSettings) => {
try {
const apiKey = loadApiKey({
apiKey: config?.mem0ApiKey,
environmentVariableName: "MEM0_API_KEY",
description: "Mem0",
});
const body: Record = { messages };
if (config?.user_id) body.user_id = config.user_id;
if (config?.app_id) body.app_id = config.app_id;
if (config?.agent_id) body.agent_id = config.agent_id;
if (config?.run_id) body.run_id = config.run_id;
if (config?.metadata) body.metadata = config.metadata;
if (config?.infer != null) body.infer = config.infer;
const options = {
method: 'POST',
headers: {
Authorization: `Token ${apiKey}`,
'Content-Type': 'application/json',
// Surface attribution. Set-once by contract: this wrapper is the
// outermost layer on these raw fetch calls.
'X-Mem0-Source': 'VERCEL_AI_SDK',
'X-Mem0-Client': `mem0-vercel-ai-provider/${PROVIDER_VERSION}`
},
body: JSON.stringify(body),
};
const baseUrl = config?.host || 'https://api.mem0.ai';
const response = await fetch(`${baseUrl}/v3/memories/add/`, options);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error("Error in updateMemories:", error);
throw error;
}
}
```
Sources: [integrations/vercel-ai-sdk/src/mem0-utils.ts:325-365](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/vercel-ai-sdk/src/mem0-utils.ts#L325-L365)
Memory retrieval routines in the [Vercel AI SDK integration](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/technical/ecosystem-integrations/vercel-ai-sdk-integration) normalize varying API response structures into standard formats. The `getMemories` function guarantees a flat array output whether the underlying data payload returns as a raw array or an object containing a results key.
```typescript
const getMemories = async (prompt: LanguageModelV3Prompt | string, config?: Mem0ConfigSettings) => {
try {
const message = typeof prompt === 'string' ? prompt : flattenPrompt(prompt);
const data = await searchInternalMemories(message, config);
// Normalize: always return a flat array regardless of API response shape
return Array.isArray(data) ? data : (data?.results ?? []);
} catch (error) {
console.error("Error in getMemories:", error);
throw error;
}
}
```
Sources: [integrations/vercel-ai-sdk/src/mem0-utils.ts:391-401](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/vercel-ai-sdk/src/mem0-utils.ts#L391-L401)
## Executing Transparent Memory Proxying
### Proxy Architecture and Interception
The transparent memory proxy intercepts chat completion requests through an OpenAI-compatible interface powered by `litellm`. The proxy client initializes via the `Mem0` class, selecting either a hosted `MemoryClient` when an API key is supplied or a local `Memory` instance configured with user settings. Incoming chat requests hit the `Completions.create` method, which enforces that at least one identifier among `user_id`, `agent_id`, or `run_id` is present before processing.
```python
class Mem0:
def __init__(
self,
config: Optional[dict] = None,
api_key: Optional[str] = None,
host: Optional[str] = None,
):
if api_key:
self.mem0_client = MemoryClient(api_key, host)
else:
self.mem0_client = Memory.from_config(config) if config else Memory()
self.chat = Chat(self.mem0_client)
```
Sources: [mem0/proxy/main.py:23-36](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/proxy/main.py#L23-L36)
> [!WARNING]
> Omitting all three scope identifiers (`user_id`, `agent_id`, and `run_id`) in a proxy completion call triggers a `ValueError` during validation. At least one scope parameter must be provided for memory persistence and retrieval.
Sources: [mem0/proxy/main.py:92-93](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/proxy/main.py#L92-L93)
### Automatic Memory Augmentation
When a completion request includes a user-role final message, the proxy performs background ingestion and semantic search concurrently. The user message is dispatched to storage asynchronously via a daemon thread running `_async_add_to_memory`, preventing blocking on write operations. Simultaneously, `_fetch_relevant_memories` queries the underlying client using the last six conversation turns, bounded by the configured `top_k` parameter.
```python
prepared_messages = self._prepare_messages(messages)
if prepared_messages[-1]["role"] == "user":
self._async_add_to_memory(messages, user_id, agent_id, run_id, metadata, filters)
relevant_memories = self._fetch_relevant_memories(messages, user_id, agent_id, run_id, filters, top_k)
logger.debug(f"Retrieved {len(relevant_memories)} relevant memories")
prepared_messages[-1]["content"] = self._format_query_with_memories(messages, relevant_memories)
```
Sources: [mem0/proxy/main.py:100-106](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/proxy/main.py#L100-L106)
The retrieved facts and associated relational entities are formatted directly into the final user prompt using `MEMORY_ANSWER_PROMPT` as a system message prefix. Telemetry events (`mem0.chat.create`) are captured upon completion based on whether the client instance is local or remote.
```python
def _format_query_with_memories(self, messages, relevant_memories):
# Check if self.mem0_client is an instance of Memory or MemoryClient
entities = []
if isinstance(self.mem0_client, mem0.memory.main.Memory):
memories_text = "\n".join(memory["memory"] for memory in relevant_memories["results"])
if relevant_memories.get("relations"):
entities = [entity for entity in relevant_memories["relations"]]
elif isinstance(self.mem0_client, mem0.client.main.MemoryClient):
memories_text = "\n".join(memory["memory"] for memory in relevant_memories)
return f"- Relevant Memories/Facts: {memories_text}\n\n- Entities: {entities}\n\n- User Question: {messages[-1]['content']}"
```
Sources: [mem0/proxy/main.py:176-186](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/proxy/main.py#L176-L186)
> [!TIP]
> The proxy automatically inspects the model for function calling compatibility using `litellm.supports_function_calling(model)` and rejects unsupported models immediately before executing storage or retrieval steps.
Sources: [mem0/proxy/main.py:95-98](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/mem0/proxy/main.py#L95-L98)
## Managing Agent Plugin Embeddings
### Plugin Architecture and Cordis Bindings
The DeepSeek agent plugin integrates Mem0 long-term memory into the Cordis harness architecture by defining the plugin module name as `mem0` and declaring dependencies on `tools` and `systemPrompt` services. During bootstrap, the `apply` function validates configuration inputs, enforcing that an API key is present via `config.apiKey` or the `MEM0_API_KEY` environment variable and that `config.userId` is a non-empty string.
```typescript
export const name = "mem0";
export const inject = ["tools", "systemPrompt"];
```
Sources: [integrations/deepseek-plugin/src/index.ts:30-31](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/deepseek-plugin/src/index.ts#L30-L31)
```typescript
export function apply(ctx: Context, config: Config): void {
const apiKey = config.apiKey ?? process.env.MEM0_API_KEY;
if (!apiKey) {
throw new Error("deepseek-plugin: set config.apiKey or the MEM0_API_KEY env var");
}
const userId = config.userId?.trim();
if (!userId || /^\*+$/.test(userId)) {
throw new Error("deepseek-plugin: config.userId is required");
}
```
Sources: [integrations/deepseek-plugin/src/index.ts:96-104](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/deepseek-plugin/src/index.ts#L96-L104)
| Configuration Option | Type | Default | Purpose |
| :--- | :--- | :--- | :--- |
| `apiKey` | `string` | `process.env.MEM0_API_KEY` | Mem0 API authentication token. |
| `userId` | `string` | *required* | Default entity owning stored memories. |
| `allowUserOverride` | `boolean` | `false` | Explicitly permits model-selected cross-user access. |
| `host` | `string` | `api.mem0.ai` | Optional Mem0 Platform base-URL override. |
| `autoRecall` | `boolean` | `true` | Recalls relevant memory before each model request. |
| `autoCapture` | `boolean` | `true` | Stores completed interaction turns automatically. |
Sources: [integrations/deepseek-plugin/src/index.ts:53-66](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/deepseek-plugin/src/index.ts#L53-L66)
> [!WARNING]
> Providing an asterisk wildcard (`*`) or leaving `userId` empty causes initialization to throw an immediate error during plugin application.
Sources: [integrations/deepseek-plugin/src/index.ts:101-104](https://github.com/blade47/mem0/blob/b7ad69afda6b6ed030347c66d48a13e4de9dec08/integrations/deepseek-plugin/src/index.ts#L101-L104)
### Session Lifecycle and Event Hooks
The plugin utilizes a weak map to maintain per-session states, tracking both conversation messages and local lifecycle handlers. When `autoRecall` is active, the system prompt assembly hook intercepts context requests, extracts the latest user prompt, and queries the memory client with an auto-recall limit of 5 results.
```typescript
const sessionStates = new WeakMap