Personal Agent Memory
by mimimaster
README.md
# Personal Agent Memory (PAM)
Personal Agent Memory (PAM) is a self-hosted memory service for your AI assistants and coding tools. Run it on one Linux server so that Cursor, Claude Code, Codex, ChatGPT, and your custom bots all read and write to the same memory—even when your laptop is offline.
It exposes a REST API (`/v1`), a remote MCP endpoint (`/mcp`, Streamable HTTP), and a web admin panel (`/admin`). Passwords, API keys, and private contact details are automatically separated from plain text memories and stored in an encrypted vault, leaving only safe references in the memory records.
## Key Features
- **Organized memory types**: Stores four kinds of records (`personal`, `project`, `knowledge`, `methods`) with importance scores (`salience`, 0–100) and stability levels so the most relevant context is loaded first.
- **Reliable storage**: Uses SQLite as the single source of truth with revision history, soft deletes, a change feed, and background indexing.
- **Hybrid search**: Combines keyword search (BM25) and vector search with Reciprocal Rank Fusion (RRF). Deleted or outdated versions are never returned.
- **Flexible embeddings**:
- `local`: Built-in `sentence-transformers` (`intfloat/multilingual-e5-small` by default, runs on CPU).
- `http`: Any OpenAI-compatible `/embeddings` endpoint (such as a local `llama.cpp` server running `bge-m3`).
- `hash`: Deterministic fallback for tests (no semantic matching).
Switching embedding models automatically rebuilds the vector index in the background.
- **Encrypted vault for secrets**: Uses envelope encryption (per-item AES-256-GCM data keys wrapped by a master key kept outside the database). Ciphertext can live on local disk, a synced folder, or a remote HTTP storage server. Reading plaintext requires an explicit `secrets:read` permission and is logged.
- **Access control & OAuth 2.1**: Supports both static Bearer tokens and OAuth 2.1 (with PKCE) for remote MCP clients. Role-based access control lets you limit each key or app by operation (`read`, `write`, `delete`, `secrets:read`, `admin`), memory kind, and project.
- **Automatic note synthesis & web admin**: Optional background worker summarizes raw notes and conversation turns into clean project briefs, personal preferences, and reusable guides, with a web dashboard at `/admin` to review memories, manage keys, and adjust settings.
- **Backward compatibility**: Imports existing `agent-memory` SQLite databases and keeps the `agent_memory_*` MCP tool names working alongside the `memory_*` tools.
## Repository Layout
- `packages/engine-py` — Python storage engine, hybrid search, encrypted vault, OAuth 2.1, and CLI (`pam`).
- `packages/hub-ts` — TypeScript MCP & REST gateway, background note compiler, and workspace rules exporters.
- `packages/web` — React web admin interface served at `/admin`.
- `integrations/grokbot` — Python and TypeScript helpers for connecting bots.
- `deploy/` — Example `systemd` units, Caddy config, and environment templates.
## Quick Start
### 1. Python Engine (Standalone or Backend)
```bash
python3 -m venv .venv
.venv/bin/pip install -e '.[dev]' # Minimal install (hash embeddings for testing)
.venv/bin/pip install -e '.[local]' # Optional: local multilingual embedding model
export PAM_DATA_DIR=./data
.venv/bin/pam embed doctor # Check current embedding provider and dimensions
# Generate a master key for the encrypted vault (keep it outside the data folder)
.venv/bin/pam secrets keygen > ~/.pam-kek && chmod 600 ~/.pam-kek
export PAM_VAULT_KEK_REF=file:$HOME/.pam-kek
# Create a client token (shown only once)
.venv/bin/pam client create my-laptop --ops read,write
# Start the server
.venv/bin/pam serve --host 127.0.0.1 --port 8765
```
### 2. Full Stack (Python Engine + TypeScript Hub + Web UI)
```bash
npm install
npm --prefix packages/web run build
npm --prefix packages/hub-ts run build
```
See `deploy/v2/` for running the Python engine and TypeScript hub together behind Caddy with `systemd`.
### 3. Connect an MCP Client
Point your MCP client to `http://127.0.0.1:8765/mcp` (or your HTTPS domain) with header:
```text
Authorization: Bearer <your-token>
```
For clients that use OAuth (such as ChatGPT custom MCP connectors), set `PAM_PUBLIC_URL=https://pam.example.com` and approve the login with `pam oauth approval-code`.
### 4. Run Tests
```bash
PYTHONPATH=packages/engine-py/src .venv/bin/pytest -q
npm --prefix packages/hub-ts test
python3 scripts/check_secrets.py
```
## Documentation
- `docs/ARCHITECTURE.md` — System design, data flow, embedding providers, and vault storage
- `docs/CONTRACT.md` — Data schema, REST/MCP API reference, and permission rules
- `docs/OAUTH.md` — OAuth 2.1 configuration for remote MCP clients
- `docs/ADMIN_PANEL.md` — Web admin dashboard guide
- `docs/RBAC.md` — Role-based access control and API keys
- `docs/CHATGPT_CONNECT.md` — Connecting ChatGPT (`PAM Chat` and `PAM Agent` modes)
- `docs/GROKBOT_CONNECT.md` — Connecting bots with per-bot identity
- `docs/SECRET_BACKEND_PROTOCOL.md` — REST protocol for external encrypted vault storage
- `docs/MIGRATION.md` — Migrating from legacy `agent-memory`
## License
Apache-2.0. See `LICENSE` and `NOTICE`.