docs/integrations/pi-agent.mdx
Add persistent memory to Pi Agent with @mem0/pi-agent-plugin. Your agent forgets everything between sessions — this plugin fixes that by automatically capturing knowledge from conversations, storing it in Mem0's cloud memory layer, and retrieving relevant context before every response.
The plugin provides:
mem0_memory tool before each responseA Mem0 Platform account and API key:
m0-)Pi Agent installed (pi.dev)
Your API key added to your shell profile:
echo 'export MEM0_API_KEY="m0-your-api-key"' >> ~/.bashrc
source ~/.bashrc
pi install npm:@mem0/pi-agent-plugin
That's it. The extension loads automatically on every Pi session. No config files needed — MEM0_API_KEY from your environment is picked up automatically.
For advanced settings, create ~/.pi/agent/mem0-config.json:
{
"apiKey": "m0-your-key-here",
"userId": "your-username",
"autoCapture": true,
"defaultScope": "project",
"dream": {
"enabled": true,
"auto": true,
"minHours": 24,
"minSessions": 5,
"minMemories": 20
}
}
| Key | Type | Default | Description |
|---|---|---|---|
apiKey | string | $MEM0_API_KEY | Mem0 API key. Environment variable takes precedence. |
userId | string | $MEM0_USER_ID or "default" | User identity for memory scoping |
autoCapture | boolean | true | Store facts from conversations automatically |
defaultScope | string | "project" | Default memory scope: project, session, or global |
dream.enabled | boolean | true | Enable dream consolidation |
dream.auto | boolean | true | Auto-trigger dreams when thresholds are met |
dream.minHours | number | 24 | Minimum hours between auto-dreams |
dream.minSessions | number | 5 | Minimum sessions before first auto-dream |
dream.minMemories | number | 20 | Minimum memories before auto-dream triggers |
| Component | Description |
|---|---|
mem0_memory tool | Agent-callable tool for search, add, get_all, delete, delete_all |
| 8 slash commands | Essential memory management from the command line |
| 8 skills | Guide the agent on how to use each capability |
| Auto-capture | Extracts and stores facts on every agent_end event |
| System prompt | Appends memory policy to every agent turn |
| Dream consolidation | Automated memory maintenance with session/time/count gates |
The mem0_memory tool is registered with Pi and callable by the agent during conversations:
| Action | Required Params | Description |
|---|---|---|
search | query | Semantic search across memories |
add | content | Store a new memory |
get_all | — | List all memories in scope |
delete | memory_id | Delete a specific memory |
delete_all | — | Delete all memories in scope |
All actions accept an optional scope parameter: project (default), session, or global.
Tool output is truncated to 200 lines / 50KB to prevent context overflow.
| Command | Description |
|---|---|
/mem0-remember <text> | Store a memory verbatim (no inference) |
/mem0-forget <query> | Search and delete memories (with confirmation dialog) |
/mem0-search <query> | Semantic search across memories |
/mem0-tour [scope] | Browse all memories grouped by category |
/mem0-dream | Consolidate — merge duplicates, prune stale, resolve contradictions |
/mem0-pin <query> | Pin a memory to protect from dream pruning (preserves memory ID) |
/mem0-scope <scope> | Change default scope for this session (project, session, global) |
/mem0-status | Connection health, identity, and memory count |
Memories are scoped using Mem0's user_id, app_id, and run_id parameters:
| Scope | Filters | Use Case |
|---|---|---|
project | user_id + app_id (git root) | Default. Project-specific knowledge — decisions, architecture, config |
session | user_id + app_id + run_id | Ephemeral context for the current session only |
global | user_id only | All memories across all your projects |
The app_id is auto-detected from the git repository root (git rev-parse --show-toplevel), so all subdirectories within a monorepo share the same memory pool. Falls back to the working directory name for non-git directories. The run_id is derived from Pi's session file path.
Destructive and mutating commands use Pi's built-in ctx.ui.confirm() dialog before acting:
/mem0-forget asks "Delete this memory?" before deleting a single match/mem0-pin asks "Pin this memory?" before modifying it/mem0-pin uses Mem0's update() API to prepend [PINNED] to the memory text. This preserves the original memory ID — no add+delete cycle that would lose history or change the UUID.
The plugin includes automated memory maintenance ("dream") that merges duplicates, resolves contradictions, and prunes stale entries. When enabled, dreams auto-trigger after enough sessions, time, and memories accumulate (configurable via dream.* settings). Run /mem0-dream to trigger consolidation manually at any time. Pinned memories (via /mem0-pin) are protected from pruning.
# Session 1
You: I prefer dark mode and concise answers.
# Mem0 auto-captures preferences
# Session 2 (days later)
You: What do you know about my preferences?
# Pi retrieves stored memories — no re-explaining needed
MEM0_API_KEY is set: echo $MEM0_API_KEY. If empty, add it to your shell profile (see Prerequisites)pi -e ./src/entry.ts from the plugin directory for verbose outputautoCapture is true (default). Check /mem0-status for connection healthapp_id. If not in a git repo, it falls back to the working directory name. Run /mem0-status to see the detected project/mem0-dream to force it manually