@amaster.ai/pi-memory-mem0

Semantic memory extension powered by Mem0, with Platform, embedded, and self-hosted backends and three memory modes (hybrid, active, passive).
How It Works
Passive side: after each conversation turn, the user + assistant messages are automatically sent to Mem0 for fact extraction and storage. When you send a prompt, a semantic search is prefetched in the background and relevant memories are recalled before the agent starts — zero effort required.
Active side: the agent gets a mem0_memory tool (search / add / get_all / delete) so it can look up and manage memories on its own initiative — same idea as the official @mem0/pi-agent-plugin, but backed by this package's provider abstraction, so it works with Platform, embedded, and self-hosted Mem0.
Safety boundaries:
- Recall channel: recalled memories are injected as a custom message delivered on the user channel — never into the system prompt. Each entry is wrapped as
[UNTRUSTED MEMORY DATA] (JSON-quoted), and entries matching prompt-injection patterns are replaced with [BLOCKED UNTRUSTED MEMORY: ...].
- Recall trigger: automatic recall is consumed when a user prompt starts a run. Custom-message runs triggered by another extension do not consume pending recall.
- Project namespacing: memories are scoped to
userId:project:<cwd-hash> by default, so one project's memories are not visible in another. Set userIdScope: "exact" when one identity must be shared across projects.
- Credential redaction: private keys, bearer tokens, and
api_key=…-style values are redacted before anything is stored.
- Platform mode disclosure: in
platform mode the captured turns leave your machine and are processed by Mem0 Cloud. Use embedded or self-hosted mode to keep memory traffic off third-party infrastructure.
Modes
Backend Modes
| Mode |
Vector Store |
Persistence |
Dependencies |
Use Case |
platform |
Mem0 Cloud |
Cloud-managed |
MEM0_API_KEY |
Quick start, multi-device sync |
embedded |
Mem0 OSS vector store |
Vector-store managed |
LLM + Embedding API |
Data privacy, no Mem0 Cloud |
self-hosted |
Mem0 OSS REST server |
Server-managed |
Server URL, optional API key |
Shared infrastructure |
Memory Modes
Memory behavior has three independent controls. Each control is optional and falls back to the selected memoryMode preset when omitted.
Independent Behavior Controls
| Setting |
Controls |
autoCapture |
Automatically send each user + assistant turn to Mem0 for extraction and storage |
autoRecall |
Automatically search Mem0 and inject matching memories before the agent starts |
toolEnabled |
Register the model-callable mem0_memory tool for search, add, list, and delete operations |
toolEnabled affects only the model-callable tool. The user-facing /mem0 command remains available while the provider is active.
topK is the shared result limit for automatic recall and mem0_memory search. It must be an integer greater than 0; use autoRecall: false, not topK: 0, to disable automatic recall.
Presets and Overrides
memoryMode remains a convenient preset for the three controls:
memoryMode |
Auto capture |
Auto recall |
mem0_memory tool |
Use Case |
hybrid (default) |
✅ |
✅ |
✅ |
Automatic memory plus agent-driven lookup |
active |
❌ |
❌ |
✅ |
No background traffic; the agent decides every read/write |
passive |
✅ |
✅ |
❌ |
Zero tool surface; fully automatic memory |
Explicit controls override the preset independently. Unset controls continue to inherit their preset values, so a partial override does not replace the entire mode.
{
"pi-memory-mem0": {
"memoryMode": "hybrid",
"autoRecall": false
}
}
This keeps the hybrid defaults for autoCapture and toolEnabled, while the explicit autoRecall: false disables automatic injection. The agent can still search through mem0_memory on demand.
The same rule works with any preset. For example, this starts from passive and enables only the tool override:
{
"pi-memory-mem0": {
"memoryMode": "passive",
"toolEnabled": true
}
}
Recall Frequency
recallFrequency controls how often automatic recall runs when autoRecall resolves to true:
| Value |
Behavior |
"user-input" (default) |
Search once for each user input and inject the matching memories before that agent run |
"session" |
Search only for the first user input in each persistent session |
Session frequency counts the first search attempt even when it returns no matches or times out. The marker is stored in the Pi session, so switching away and resuming the same session does not search again. /new and /fork create new session IDs and each search once.
When autoRecall is false, no automatic search is started and recallFrequency has no runtime effect. It does not affect manual mem0_memory or /mem0 search calls.
Architecture (Embedded Mode)
User ←→ Agent ←→ Mem0 OSS Memory
↕
Mem0 OSS Vector Store (source of truth)
- Vector search:
mem0ai OSS MemoryVectorStore. Despite the provider name memory, it is backed by SQLite; dbPath selects an in-process SQLite database or a SQLite file.
- LLM extraction: Configured provider extracts facts from conversations
- Persistence: The default
dbPath is <home>/memories/mem0-vectors.db, so Mem0 writes vectors and payloads directly to a durable SQLite file. No second snapshot is maintained.
- Provider mapping: Custom providers are automatically mapped to mem0-compatible providers (e.g.
openai) via the pi model registry's api field.
- Observation date:
add() accepts an optional observedAt (Date or string). In embedded mode it grounds mem0's extraction prompt so relative time references ("yesterday", "last week") resolve against the conversation's date rather than the system clock — important when ingesting historical conversations. Omit it and mem0 falls back to the current date (correct for live turns). The self-hosted OSS REST API does not support observedAt: this provider rejects dated writes before sending rather than silently reinterpreting historical dates.
Quick Start
Store configuration in user/agent settings or in a trusted project's .pi/settings.json. Project settings are ignored when trust is declined and do not expand ${ENV_VAR}; the environment-backed examples below therefore belong in user or agent settings.
Platform Mode
{
"pi-memory-mem0": {
"mode": "platform",
"apiKey": "${MEM0_API_KEY}",
"userId": "${USER}"
}
}
Embedded Mode (Recommended)
Reuses API keys and base URLs from Pi's configured model providers. Embedded defaults require OpenAI access for embeddings and DeepSeek access for extraction. The SDK also accepts OPENAI_API_KEY and DEEPSEEK_API_KEY.
{
"pi-memory-mem0": {
"mode": "embedded",
"userId": "${USER}"
}
}
Defaults to OpenAI text-embedding-3-small for embeddings and DeepSeek deepseek-flash with thinking disabled for extraction. An explicit oss.llm keeps its configured provider and model. Existing embedded configurations without oss.llm now send extraction requests to DeepSeek. Set an explicit LLM to keep extraction on your chosen provider.
To use Jina embeddings, point the OpenAI-compatible embedder at Jina and use a distinct vector database. Vectors from different embedding models cannot share an index. Existing memories stay in their original database and can be re-embedded separately.
{
"pi-memory-mem0": {
"mode": "embedded",
"oss": {
"embedder": {
"provider": "openai",
"config": {
"apiKey": "${JINA_API_KEY}",
"baseURL": "https://api.jina.ai/v1",
"model": "jina-embeddings-v5-text-small"
}
},
"vectorStore": {
"provider": "memory",
"config": { "dbPath": "/path/to/mem0-jina-vectors.db", "dimension": 1024 }
}
}
}
}
Use oss.customInstructions to refine Mem0's fact extraction, for example to keep memories in a specific language:
{
"pi-memory-mem0": {
"mode": "embedded",
"oss": {
"customInstructions": "Always record memories in Simplified Chinese."
}
}
}
These instructions affect only Mem0's extraction model, not pi's system prompt. Recalled memories remain untrusted model input, so only configure extraction instructions from a trusted source.
Embedded initialization starts in the background so session startup does not wait for SDK warmup. Memory operations share the same readiness promise and report initialization failures; cancelling one waiting operation does not cancel initialization for other callers. Automatic recalls whose readiness wait expires do not start a late SDK search after initialization completes.
Existing settings with mode: "open-source" continue to load as embedded, but open-source is not part of the supported configuration interface. New settings should use embedded.
Self-Hosted Mode
Calls the OSS REST server directly. The server uses /memories and /search, not the Mem0 Platform /v1 paths.
{
"pi-memory-mem0": {
"mode": "self-hosted",
"baseUrl": "${MEM0_BASE_URL}",
"apiKey": "${MEM0_API_KEY}",
"userId": "${PAPERCLIP_COMPANY_ID}",
"agentId": "${PAPERCLIP_AGENT_ID}",
"userIdScope": "exact"
}
}
Custom Provider
When your model registry defines a custom provider with api: "openai-completions", you can use it directly:
{
"pi-memory-mem0": {
"mode": "embedded",
"oss": {
"llm": {
"provider": "my-provider",
"config": { "model": "deepseek-v4-pro" }
},
"embedder": {
"provider": "my-provider",
"config": { "model": "text-embedding-v4" }
}
}
}
}
The extension automatically:
- Resolves API key from the model registry
- Injects
baseUrl from the registry
- Maps
api: "openai-completions" → mem0 provider "openai"
Extra OpenAI Request Parameters (Embedded)
The extension supports oss.llm.config.extraBody for the openai and deepseek LLM providers. Parameters are merged into both extraction and chat request bodies, including when the extension is installed outside this workspace.
{
"pi-memory-mem0": {
"mode": "embedded",
"oss": {
"llm": {
"provider": "openai",
"config": {
"model": "qwen3.8-flash",
"apiKey": "${DASHSCOPE_API_KEY}",
"baseURL": "https://dashscope.aliyuncs.com/compatible-mode/v1",
"extraBody": {
"enable_thinking": false,
"temperature": 0
}
}
}
}
}
}
extraBody must be an object. It cannot override model, messages, tools, tool_choice, response_format, or stream; these fields belong to Mem0's request protocol. Use API field names such as max_tokens, reasoning_effort, or chat_template_kwargs inside extraBody. Endpoint support depends on the selected model and provider.
Workspace installs use the SDK patch. The packaged extension forwards the same fields when the installed SDK lacks the patch.
Fully Local (Ollama)
{
"pi-memory-mem0": {
"mode": "embedded",
"userId": "${USER}",
"oss": {
"llm": {
"provider": "ollama",
"config": { "model": "llama3", "url": "http://localhost:11434" }
},
"embedder": {
"provider": "ollama",
"config": { "model": "nomic-embed-text", "url": "http://localhost:11434" }
}
},
"useRegistryKeys": false
}
}
External Vector Store (e.g. Qdrant)
The Qdrant JavaScript client is installed with this extension; a running Qdrant server is still required.
For production workloads that need a dedicated vector database:
{
"pi-memory-mem0": {
"mode": "embedded",
"oss": {
"vectorStore": {
"provider": "qdrant",
"config": { "url": "http://localhost:6333" }
}
}
}
}
Supported vector store providers: memory (default), qdrant, redis, pgvector, supabase.
The configured vector store always owns persistence. To request an intentionally ephemeral SQLite database, set the memory provider's config.dbPath to ":memory:"; no snapshot fallback is created.
Configuration Reference