--- title: AgentMemory Python emoji: ๐ง colorFrom: blue colorTo: indigo sdk: docker pinned: false ---
Persistent memory for AI coding agents โ pure Python, zero external databases.
Works with Claude Code, Cursor, Cline, Windsurf, Gemini CLI, and any MCP client.
English | ็ฎไฝไธญๆ | ๆฅๆฌ่ช | ํ๊ตญ์ด | Espaรฑol | เคนเคฟเคจเฅเคฆเฅ | Portuguรชs | Franรงais | Deutsch
Quick Start • Features • MCP • API • Config • Deploy • Viewer • Architecture
--- ## What Is This? **agentmemory-python** is a Python reimplementation of the [agentmemory](https://github.com/rohitg00/agentmemory) persistent memory server. It exposes a REST API, WebSocket stream, and MCP tools endpoint that AI coding agents use to store and retrieve session observations, long-term memories, lessons, and pinned memory slots. Key differences from the Node.js original: - **No Node.js or iii-engine** โ runs with plain `python src/app.py` - **SQLite instead of Dolt** โ single file, WAL mode, instant startup - **HuggingFace Space ready** โ deploys in one click, data synced to an HF dataset repo - **Same REST + MCP wire format** โ drop-in for any agent already wired to agentmemory Your agent captures every tool call, stores them as observations, compresses them into searchable memory, and injects the right context at the start of every new session โ automatically. --- ## Quick Start ### Run locally ```bash # Clone git clone https://github.com/Yash030/agentmemory-python.git cd agentmemory-python # Install dependencies (no build step) pip install -r requirements.txt # Start the server python src/app.py ``` Server starts on **http://localhost:3111**. Open the viewer at http://localhost:3111/viewer. ### Verify it works ```bash # Health check curl http://localhost:3111/agentmemory/livez # {"status": "ok"} # Save a memory curl -X POST http://localhost:3111/agentmemory/remember \ -H "Content-Type: application/json" \ -d '{"content": "JWT auth uses jose middleware in src/middleware/auth.ts", "concepts": ["auth", "jwt"]}' # Recall it curl -X POST http://localhost:3111/agentmemory/search \ -H "Content-Type: application/json" \ -d '{"query": "authentication middleware", "limit": 5}' ``` --- ## Features | Feature | Status | Notes | |---------|--------|-------| | REST API โ sessions, memories, observations | โ | Full surface | | WebSocket live stream | โ | `/stream/mem-live/viewer` | | MCP tools endpoint | โ | 31 tools | | Built-in HTML viewer | โ | Real-time dashboard at `/viewer` | | BM25 keyword search | โ | Always on, no API key needed | | Hybrid BM25 + vector search | โ | Requires `GEMINI_API_KEY` | | 4-tier memory consolidation | โ๏ธ | `CONSOLIDATION_ENABLED=true` + LLM key | | Knowledge graph extraction | โ๏ธ | `GRAPH_EXTRACTION_ENABLED=true` + LLM key | | LLM observation compression | โ๏ธ | `AGENTMEMORY_AUTO_COMPRESS=true` + LLM key | | Lessons with confidence decay | โ | Fingerprinted, auto-strengthen on repeat | | Memory slots (pinned context) | โ | CRUD + auto-reflect | | Session replay | โ | Full timeline in viewer | | Audit log | โ | Tracks every write with agent_id + timestamp | | HuggingFace Space deploy | โ | One-click, data synced to dataset repo | | Privacy filtering | โ | Strips API keys, tokens before storage | ### 4-Tier Memory Model Inspired by how human memory works โ raw experience โ compressed episodes โ extracted facts โ learned patterns. | Tier | What | When | |------|------|------| | **Working** | Raw observations from tool use | Every tool call | | **Episodic** | Compressed session summaries | Session end | | **Semantic** | Extracted facts and patterns | Consolidation | | **Procedural** | Workflows and decision patterns | Consolidation | --- ## MCP Integration Wire agentmemory-python into your agent's MCP config. It speaks the same MCP protocol as the Node.js original. ### Most agents (Cursor, Claude Desktop, Cline, Windsurf) ```json { "mcpServers": { "agentmemory": { "command": "npx", "args": ["-y", "@agentmemory/mcp"], "env": { "AGENTMEMORY_URL": "http://localhost:3111" } } } } ``` ### Claude Code Paste this prompt and your agent will wire everything: ``` Start agentmemory-python: run `python src/app.py` from the agentmemory-python directory. Then add this MCP server to ~/.claude.json under mcpServers: { "agentmemory": { "command": "npx", "args": ["-y", "@agentmemory/mcp"], "env": { "AGENTMEMORY_URL": "http://localhost:3111" } } } Verify with: curl http://localhost:3111/agentmemory/livez Open the viewer at: http://localhost:3111/viewer ``` ### Available MCP Tools (31) | Tool | Description | |------|-------------| | `memory_save` | Save a long-term insight, decision, or pattern | | `memory_recall` | Search past observations by keyword | | `memory_smart_search` | Hybrid BM25 + vector semantic search | | `memory_sessions` | List recent sessions | | `memory_sessions_list` | Retrieve all memory sessions | | `memory_timeline` | Chronological observations for a session | | `memory_observations` | Observations for a session | | `memory_profile` | Per-project concept + file profile | | `memory_lessons` | List active lessons with confidence scores | | `memory_lesson_save` | Save a lesson (duplicate saves strengthen it) | | `memory_lesson_recall` | Search lessons by query | | `memory_lesson_search` | Search lessons by keywords | | `memory_consolidate` | Run 4-tier memory consolidation | | `memory_reflect` | Reflect on session, update context | | `memory_diagnose` | Health check across all subsystems | | `memory_forget` | Delete memory, session, or observations | | `memory_export` | Export all memory data as JSON | | `agent_observe` | Log agent execution observation | | `agent_remember` | Save agent memory to long-term storage | | `memory_antigravity_sync` | Sync Antigravity transcripts to memory | | `memory_antigravity_sync_all` | Master sync: transcript + crystallize + reflect | | `memory_slot_list` | List all pinned memory slots | | `memory_slot_get` | Retrieve a specific pinned memory slot | | `memory_slot_create` | Create/overwrite a pinned memory slot | | `memory_slot_append` | Append text content to a pinned memory slot | | `memory_slot_replace` | Replace pinned memory slot content | | `memory_slot_delete` | Delete a pinned memory slot | | `memory_action_create` | Create a new work item / action | | `memory_action_update` | Update fields of an existing action | | `memory_frontier` | Get active and pending actions sorted by priority | | `memory_crystallize` | Crystallize/summarize observations in a session | --- ## API Reference Base URL: `http://localhost:3111/agentmemory` ### Health | Method | Path | Description | |--------|------|-------------| | `GET` | `/livez` | Liveness probe โ no auth required | ### Sessions | Method | Path | Description | |--------|------|-------------| | `POST` | `/session/start` | Start a new session | | `POST` | `/session/end` | End a session | | `POST` | `/session/commit` | Commit session with summary | | `GET` | `/sessions` | List all sessions | ### Observations | Method | Path | Description | |--------|------|-------------| | `POST` | `/observe` | Ingest a hook event observation | | `POST` | `/agent/observe` | Simplified observe for direct agent use | | `GET` | `/observations` | List observations (`?session_id=`) | | `POST` | `/timeline` | Chronological observation window | ### Memories | Method | Path | Description | |--------|------|-------------| | `POST` | `/remember` | Save long-term memory | | `POST` | `/agent/remember` | Simplified remember | | `POST` | `/forget` | Delete memory / session / observations | | `POST` | `/search` | BM25 + vector search | | `POST` | `/context` | Compile context for a session + project | | `GET` | `/memories` | List memories (`?latest=true&limit=N`) | | `POST` | `/evolve` | Create a new memory version | ### Lessons | Method | Path | Description | |--------|------|-------------| | `GET` | `/lessons` | List lessons | | `POST` | `/lessons` | Create lesson | | `POST` | `/lessons/search` | Search lessons | | `POST` | `/lessons/strengthen` | Reinforce an existing lesson | ### Slots | Method | Path | Description | |--------|------|-------------| | `GET` | `/slots` | List all pinned slots | | `POST` | `/slot` | Create or update a slot | | `GET` | `/slot` | Get slot by name | | `DELETE` | `/slot` | Delete a slot | | `POST` | `/slot/reflect` | Auto-populate from session observations | ### Graph + Profile | Method | Path | Description | |--------|------|-------------| | `GET` | `/relations` | Knowledge graph edges | | `POST` | `/relations` | Add a relation | | `GET` | `/profile` | Project profile (top concepts, files) | ### Actions | Method | Path | Description | |--------|------|-------------| | `GET` | `/actions` | List actions | | `POST` | `/actions` | Create an action | | `PATCH` | `/actions/