Skip to main content
Glama
khaled1174

agent-memory

by khaled1174

Agent Memory System

Python License: MIT Tests Zero Dependencies MCP Tools

Persistent memory for AI agents using SQLite + FTS5.
Single-file core ยท Zero dependencies ยท Optional MCP server and Obsidian sync.


โœจ Features

Feature

Description

๐Ÿ—„๏ธ Persistent

SQLite database survives process restarts

๐Ÿ” Full-text search

FTS5 engine with ranked results

๐Ÿ”’ Agent isolation

Each agent gets its own namespace automatically

๐Ÿ› ๏ธ MCP Server

12 tools for Claude Code / Claude Desktop

๐Ÿ“ Obsidian sync

Optional two-way Markdown bridge

๐Ÿค– CLAUDE.md generator

Auto-inject context into every session

๐ŸŒ Cross-platform

macOS, Linux, WSL, Windows

โšก Zero dependencies

Core uses only Python standard library


๐Ÿ—๏ธ Architecture

graph TB
    subgraph Clients["๐Ÿ–ฅ๏ธ Clients"]
        CLI["๐Ÿ’ป CLI\n(memory.py)"]
        MCP["๐Ÿ”Œ MCP Server\n(memory_mcp.py)"]
        HERMES["๐ŸŒ‰ Hermes Bridge\n(hermes/bridge.py)"]
    end

    subgraph Core["โš™๏ธ Core Engine"]
        STORE["๐Ÿ“ฅ Store\nmemory_store()"]
        SEARCH["๐Ÿ” Search\nFTS5 Engine"]
        ISO["๐Ÿ”’ Isolation\nNamespace Handler"]
        CTX["๐Ÿ“‹ Context\nCLAUDE.md Gen"]
    end

    subgraph Storage["๐Ÿ’พ Storage"]
        DB[("๐Ÿ—„๏ธ SQLite DB\nmemory.db")]
        FTS[("๐Ÿ“‘ FTS5 Index")]
    end

    subgraph External["๐Ÿ”— Integrations"]
        OBS["๐Ÿ““ Obsidian Vault\n(Markdown)"]
        N8N["โš™๏ธ n8n Workflow"]
        TG["๐Ÿ“ฑ Telegram Bot"]
    end

    CLI --> STORE
    CLI --> SEARCH
    MCP --> STORE
    MCP --> SEARCH
    HERMES --> STORE
    HERMES --> SEARCH
    STORE --> ISO
    SEARCH --> ISO
    ISO --> DB
    DB --> FTS
    FTS --> SEARCH
    STORE --> OBS
    OBS --> STORE
    N8N --> HERMES
    TG --> HERMES
    CTX --> DB

    style Clients fill:#1f3558,stroke:#58a6ff,color:#cdd9e5
    style Core fill:#2d1f58,stroke:#bc8cff,color:#cdd9e5
    style Storage fill:#1f3a2d,stroke:#3fb950,color:#cdd9e5
    style External fill:#3a2d1f,stroke:#d29922,color:#cdd9e5

๐Ÿ”„ Memory Lifecycle

sequenceDiagram
    actor Agent as ๐Ÿค– AI Agent
    participant CLI as ๐Ÿ’ป CLI / MCP
    participant ISO as ๐Ÿ”’ Namespace
    participant DB as ๐Ÿ—„๏ธ SQLite
    participant FTS as ๐Ÿ” FTS5 Index
    participant OBS as ๐Ÿ““ Obsidian

    Agent->>CLI: memory store --type semantic --content "..."
    CLI->>ISO: Resolve agent namespace (AGENT_NAME)
    ISO-->>CLI: agent_id = "health" (or global)
    CLI->>DB: INSERT INTO memories (agent_id, type, content, ...)
    DB->>FTS: Auto-index content
    DB-->>CLI: memory_id = 42
    CLI-->>Agent: โœ… Stored (id=42)

    Agent->>CLI: memory search --query "rate limit"
    CLI->>ISO: Resolve agent namespace
    ISO-->>CLI: agent_id
    CLI->>FTS: SELECT * FROM memories_fts WHERE content MATCH "rate limit"
    FTS-->>CLI: Ranked results
    CLI-->>Agent: ๐Ÿ“‹ Results (ranked by relevance)

    Note over DB,OBS: Optional Obsidian Sync
    DB->>OBS: Sync to Markdown vault
    OBS->>DB: Sync from Markdown vault

๐Ÿง  Memory Types

mindmap
  root((๐Ÿง  Memory Types))
    ๐Ÿ“… episodic
      Events and decisions
      Switched to Postgres
      Deployed v2 on Monday
    ๐Ÿ“š semantic
      Facts and knowledge
      Rate limit 1000 req/min
      Max upload 50 MB
    โš™๏ธ procedural
      Workflows and how-tos
      Steps build test deploy
      Auth flow OAuth2 JWT

๐Ÿš€ Quick Start

Option 1: CLI (zero dependencies)

cp memory.py /usr/local/bin/memory
chmod +x /usr/local/bin/memory

# Store a memory
memory store --type semantic --content "Max upload: 50 MB" --project api --importance 5

# Search memories
memory search --query "upload"

# List recent
memory list --project api --recent 10

# View stats
memory stats

Option 2: MCP Server (Claude Code / Claude Desktop)

pip install mcp

Add to ~/.claude/settings.json (Claude Code):

{
  "mcpServers": {
    "agent-memory": {
      "command": "python",
      "args": ["/path/to/memory_mcp.py"]
    }
  }
}

Claude Desktop paths:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

  • Windows: %APPDATA%\Claude\claude_desktop_config.json

Restart and you'll see 12 tools available.


๐Ÿ› ๏ธ MCP Tools

graph LR
    subgraph Session["๐Ÿ“‹ Session"]
        T1["memory_brief\nLoad context"]
        T2["memory_who\nAgent identity"]
        T3["memory_stats\nDB statistics"]
    end

    subgraph CRUD["โœ๏ธ CRUD"]
        T4["memory_store\nSave memory"]
        T5["memory_update\nPatch memory"]
        T6["memory_delete\nRemove by ID"]
    end

    subgraph Query["๐Ÿ” Query & Export"]
        T7["memory_search\nFTS5 full-text"]
        T8["memory_list\nFilter and sort"]
        T9["memory_export\nExport to JSON"]
        T10["memory_generate_context\nBuild CLAUDE.md"]
    end

    subgraph Sync["๐Ÿ”„ Sync"]
        T11["memory_sync_to_vault\nSQLite to Obsidian"]
        T12["memory_sync_from_vault\nObsidian to SQLite"]
    end

    style Session fill:#1f3558,stroke:#58a6ff,color:#cdd9e5
    style CRUD fill:#2d1f58,stroke:#bc8cff,color:#cdd9e5
    style Query fill:#1f3a2d,stroke:#3fb950,color:#cdd9e5
    style Sync fill:#3a2d1f,stroke:#d29922,color:#cdd9e5

๐Ÿ”’ Agent Isolation

graph TD
    ENV["๐ŸŒ AGENT_NAME env var"]

    ENV -->|"= 'health'"| HEALTH["๐Ÿฅ health namespace\nWrite: own only\nRead: own + global"]
    ENV -->|"= 'orchestrator'"| ORCH["๐ŸŽฏ orchestrator\nWrite: anywhere\nRead: everything"]
    ENV -->|"not set"| GLOBAL["๐ŸŒ global\nWrite: anywhere\nRead: everything"]

    HEALTH --> DB1[("health::memories")]
    HEALTH -.->|read only| DB2[("global::memories")]
    ORCH --> DB1
    ORCH --> DB2
    ORCH --> DB3[("other::memories")]
    GLOBAL --> DB2

    style ENV fill:#21262d,stroke:#58a6ff,color:#cdd9e5
    style HEALTH fill:#1f3558,stroke:#58a6ff,color:#cdd9e5
    style ORCH fill:#2d1f58,stroke:#bc8cff,color:#cdd9e5
    style GLOBAL fill:#1f3a2d,stroke:#3fb950,color:#cdd9e5
export AGENT_NAME=health   # Linux / macOS / WSL
$env:AGENT_NAME = "health" # Windows PowerShell

Role

Write Access

Read Access

Regular agent

Own namespace only

Own + global

orchestrator

Anywhere

Everything

Not set

Anywhere

Everything


๐ŸŒ‰ Hermes โ€” Cross-Platform Memory

Two agents collaborate on Slack. You ask on Telegram. The memory carries.

flowchart LR
    SLACK["๐Ÿ’ฌ Slack Agent"] -->|POST| N8N["โš™๏ธ n8n"]
    N8N -->|HTTP| BRIDGE["๐ŸŒ‰ Hermes Bridge\nbridge.py :8765"]
    BRIDGE <-->|SQLite| DB[("๐Ÿ—„๏ธ memory.db")]
    TG["๐Ÿ“ฑ Telegram Bot"] <-->|HTTP| BRIDGE
    MCP["๐Ÿ”Œ MCP Server"] <-->|SQLite| DB
    CLI["๐Ÿ’ป CLI"] <-->|SQLite| DB

    style SLACK fill:#1f3a2d,stroke:#3fb950,color:#cdd9e5
    style N8N fill:#3a2d1f,stroke:#d29922,color:#cdd9e5
    style BRIDGE fill:#2d1f58,stroke:#bc8cff,color:#cdd9e5
    style DB fill:#1f3558,stroke:#58a6ff,color:#cdd9e5
    style TG fill:#1f3558,stroke:#58a6ff,color:#cdd9e5
    style MCP fill:#2d1f58,stroke:#bc8cff,color:#cdd9e5
    style CLI fill:#1f3a2d,stroke:#3fb950,color:#cdd9e5
# 1. Start the bridge
python hermes/bridge.py

# 2. Import hermes/n8n_workflow.json into your n8n instance

# 3. Start the Telegram bot
TELEGRAM_TOKEN=xxx HERMES_URL=http://your-server:8765 python hermes/telegram_bot.py

See hermes/README.md for full setup, API reference, and VPS deployment.


๐Ÿ“ฆ Obsidian Integration (Optional)

export OBSIDIAN_VAULT=/path/to/your/vault

# Auto-mirrors every store/update/delete to Markdown
memory store --type semantic --content "API uses JWT" --project api

# Bulk sync
memory sync-to-vault    # SQLite โ†’ Markdown
memory sync-from-vault  # Markdown โ†’ SQLite

๐Ÿ“‹ CLAUDE.md Generator

memory generate-context --output CLAUDE.md

Creates a Markdown file from your most important memories. Place it in your project root and Claude Code reads it automatically every session.


๐Ÿ“ File Structure

agent-memory/
โ”œโ”€โ”€ memory.py              # Core: CLI + library (1282 lines)
โ”œโ”€โ”€ memory_mcp.py          # MCP server (645 lines, requires: pip install mcp)
โ”œโ”€โ”€ assets/
โ”‚   โ””โ”€โ”€ banner.svg         # Repository banner image
โ”œโ”€โ”€ hermes/                # Cross-platform memory layer
โ”‚   โ”œโ”€โ”€ bridge.py          # HTTP gateway (zero new deps)
โ”‚   โ”œโ”€โ”€ telegram_bot.py    # Telegram recall bot (requires: requests)
โ”‚   โ”œโ”€โ”€ n8n_workflow.json  # Ready-to-import Slack โ†’ memory workflow
โ”‚   โ””โ”€โ”€ README.md          # Hermes setup guide
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ requirements.txt       # Runtime: empty (stdlib only)
โ”œโ”€โ”€ requirements-dev.txt   # Dev: pytest, black, mypy, ruff
โ””โ”€โ”€ tests/
    โ”œโ”€โ”€ __init__.py
    โ””โ”€โ”€ test_memory.py     # 58 tests across 8 classes

๐Ÿ—ƒ๏ธ Database Location

Platform

Default Path

macOS / Linux

~/.claude/memory/memory.db

Windows

%APPDATA%\\claude\\memory\\memory.db

Override: export AGENT_MEMORY_DIR=/custom/path


๐Ÿงช Testing

pip install -r requirements-dev.txt
python -m pytest tests/test_memory.py -v          # 58 tests
python -m pytest tests/test_memory.py -v --cov=memory

๐Ÿ“„ License

MIT ยฉ khaled1174


A
license - permissive license
-
quality - not tested
C
maintenance

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/khaled1174/agent-memory'

If you have feedback or need assistance with the MCP directory API, please join our Discord server