agent-memory is a long-term memory runtime for AI agents, designed to solve the problem of agents forgetting what they have learned after a session ends. It is not limited to coding agents; any agent capable of executing shell commands can use it.
Purpose
Provide AI agents with long-term memory capabilities across sessions. Memories are stored as plain Markdown files in a storage directory as the sole source of truth; the adjacent SQLite index serves only as a cache that can be deleted at any time. Agents such as Claude Code, Codex CLI, and Muse Code share the same store.
Key capabilities
- Local ranked retrieval: Retrieval is performed locally, without calling models or the network. Results include a one-line summary, file path, anchor, and score; agents can open them layer by layer as needed (index line → summary → full file → raw material), avoiding pasting full text into context.
- Three read paths: Deterministic injection of MEMORY.md at session start; BM25 recall based on the FTS5 index, with an optional vector plugin fused via RRF; and a plain directory tree directly accessible with ls and grep.
- Automatic writes: Distillation is triggered at conversation boundaries without blocking the task; the full trajectory is copied first, ensuring that distillation omissions do not mean system loss.
- Sleep-period management (Manage): Consolidation and forgetting processes run on an independent clock, with a permission hierarchy—unattended processes can add and update, while deletions appear only as proposals and require user confirmation.
- Versioning and traceability: Each memory is a file, with validity defined by valid_from and optional invalid_at; replaced or deleted files remain in the store, supporting recall --as-of date-based lookback.
- Files as truth: All indexes can be rebuilt; running rm -rf .index/ && mem rebuild will not lose any knowledge (covered by tests). Memories remain grep-able, git-manageable, and portable.
- No LLM client: The library contains no LLM client, requires no key installation, and has no billing surface; judgment capabilities borrow the host agent's own CLI, and all writes are visible in the conversation record.
Usage
Requires Python 3.12 or later and uv. Not yet published to PyPI; install from a code checkout:
# 在检出目录中构建 mem、mem-mcp、mem-hook 到 .venv/bin
uv run mem
Add the directory to PATH so the shell can invoke it directly. The store is located at ~/agent-memory-store by default, can be changed via export AGENT_MEMORY_STORE, and must be exported in all agent runtime environments.
Connect an agent:
mem setup claude-code
mem setup codex
mem setup muse
All three commands use the same pipeline: probe the host, initialize or check storage, safely merge host settings, install lifecycle hooks and skills, perform provider-specific setup, and run preflight checks. Success ends with status: READY. Repeated runs are safe and will not reinstall managed hooks, skills, provider routes, or MCP entries.
With --mcp, the host can also receive agent-memory's stdio MCP server, providing core calls such as memory_recall, memory_read, memory_trace, memory_record, memory_correct, memory_supersede, memory_merge, memory_delete, and memory_feedback. Any agent that can run shell commands does not need MCP; the CLI is the universal fallback.
When to use
- AI agents that need to retain knowledge across sessions, especially coding agents.
- Multiple agents (Claude Code, Codex CLI, Muse Code, etc.) sharing the same memory store.
- Scenarios where memory should be auditable, version-controlled, and portable, without relying on external APIs or cloud services.
- Research or debugging scenarios that need to trace memory state back to a point in time.
Limitations
- Requires Python 3.12+ and uv; not yet published to PyPI, so it must be installed from a code checkout.
- Retrieval quality depends on the local index; vector retrieval is an optional plugin.
- Deletion operations in sleep-period management require user confirmation; unattended workflows cannot delete directly.
- When the store is outside the Codex workspace, agent-initiated CLI recall requires write permission for the store access log; the store must be covered via sandbox_workspace_write.writable_roots, or Codex must be started with --add-dir <store>.
- The experimental native management review mode (tool_mode = "native") is supported only on Claude Code, Codex, Hermes, and Muse, and Muse requires version 1.4.4 or later.
- Raw session inspection is a separate experimental permission and is disabled by default.
- Performance figures are based on the bounded LongMemEval-S test set; absolute values cannot be directly compared with public LongMemEval scores.