OpenClaw

Persistent cross-session memory for OpenClaw. Replaces MEMORY.md with a structured knowledge graph that actually scales.

Why Engram + OpenClaw

OpenClaw's built-in MEMORY.md convention is a flat file that grows without bound — it gets stuffed into every session regardless of relevance, becomes expensive and noisy as it grows, and eventually gets truncated. Engram replaces it with a graph-based memory store:

  • Retrieves only what's relevant to the current task — not everything you've ever noted
  • Scales to thousands of facts without context bloat
  • Retires superseded facts automatically — no manual cleanup when decisions change
  • Persists across projects with full export/import portability

Token savings compared to a naive MEMORY.md approach: typically 60–80% fewer context tokens per session on a well-established project — exact savings depend on project age and query specificity. Engram's benchmark data is available under benchmarks/ in the repo.

1. Install Engram

pip install engram

Verify the install:

engram --version

2. Add to openclaw.json

In your OpenClaw config file (openclaw.json), add an mcpServers block:

{
  "mcpServers": {
    "engram": {
      "command": "engram",
      "args": ["mcp-serve"],
      "env": {
        "ENGRAM_PROJECT": "my-project"
      }
    }
  }
}

Replace my-project with the name you want for this project's memory store. Engram will create it automatically the first time it's accessed.

Restart OpenClaw. You should see engram_query, engram_extract, engram_stats, and engram_list_projects in the available tools.

3. Update your agent instructions

Replace your existing MEMORY.md instructions in your OpenClaw system prompt or config with:

## Memory (Engram)
At the start of each session, call engram_query with a brief description of
the current task. This retrieves relevant decisions, constraints, and context
from prior sessions — only what's relevant, not everything.

After completing significant work or at the end of a session, call
engram_extract with a summary of what was built, decided, or changed.
Engram will structure and store the facts automatically.

Do not write to MEMORY.md. Use engram_query and engram_extract instead.

4. Migrate existing MEMORY.md (optional)

If you have an existing MEMORY.md, import it into Engram before your next session:

engram init my-project
engram extract my-project MEMORY.md

Engram will parse the file, extract structured facts, and merge them into the project graph. After this, you can leave MEMORY.md in place as a historical artifact or delete it — Engram won't touch it either way.

To verify the import worked:

engram show my-project

How it works in practice

Once configured, your OpenClaw sessions follow this pattern automatically:

  1. Session start: OpenClaw calls engram_query with the task description. Engram returns the 10–25 most relevant facts from the project's history.
  2. During the session: You work normally. OpenClaw may call engram_query again as the task evolves.
  3. Session end: OpenClaw calls engram_extract with a summary. Engram extracts structured facts, detects which supersede prior decisions, and updates the graph.

The graph grows across sessions. Each session starts with a sharp, relevant slice of accumulated project memory rather than a flat growing file.

Hosted API (optional)

By default, Engram runs locally — the memory store is a SQLite file in ~/.engram/. For cross-machine sync or team access, switch to the hosted API:

{
  "mcpServers": {
    "engram": {
      "command": "engram",
      "args": ["mcp-serve"],
      "env": {
        "ENGRAM_PROJECT": "my-project",
        "ENGRAM_API_KEY": "your-api-key",
        "ENGRAM_REMOTE_URL": "https://api.engram.unbidden.ai"
      }
    }
  }
}

Get an API key from the Pro or Team plan. Local mode is free and has no rate limits.

Troubleshooting

Tools don't appear in OpenClaw after adding config

Make sure engram is on your PATH. Run which engram in a terminal. If not found, reinstall with pip install engram and confirm your Python bin directory is in PATH. Restart OpenClaw after saving the config.

engram_query returns empty results

The project may not exist yet or may be empty. Run engram list to see current projects and node counts. If empty, run engram extract my-project MEMORY.md or engram onboard my-project to seed it from existing session history.

How do I switch projects mid-session?

Pass the project parameter explicitly to engram_query or engram_extract to override the default. Or update the ENGRAM_PROJECT env var in your config and restart the MCP server.