Skip to main content

engrim

CI PyPI Python License: MIT Local & private

The Universal Cross-Model & Cross-Agent Episodic Memory Store.

A local-first, project-scoped SQLite memory engine that allows developers to freely switch between models and environments (Google Antigravity, Claude Code, Cursor MCP, Windsurf) on the SAME project without losing architectural decisions, user constraints, or project state.


1. The Core Value Proposition

"Why pay for 200,000 tokens of forgotten noise on every turn? The models are disposable utilities; your project's decisions are not."

As context windows scale to 1M+ tokens, developers face attention dilution: reasoning degrades, cost multiplies with every conversational turn, and clearing context causes total amnesia.

engrim replaces attention dilution with 4,000 characters of curated episodic working memory:

  • Switzerland of AI Memory: Decouples project intelligence from any single AI vendor or proprietary cloud silo. Switch from Gemini 3.8 in Antigravity to Claude 3.7 Sonnet in Claude Code to GPT-4o in Cursor mid-project — your agents pick up right where the others left off.
  • Save Button for Autonomous Coding: Externalize decisions, constraints, and state as you work. Clear your agent session freely (/clear) and watch context reload intact.
  • Smart, Hot Context Loading: Combines SQLite FTS5 (bm25 keyword search) with static vector embeddings (model2vec) in a zero-latency hybrid reciprocal-rank fusion engine.

2. Empirical Proof (The 105-Session Case Study)

Tested across 105 continuous sessions on a 50,000-line algorithmic trading system. Zero regressions across 186 unit tests, zero context amnesia across model switches.

In production testing on an active algorithmic trading codebase running real capital:

  • Over 153,000 tokens of work across days of architecture, parameter tuning, and debugging was consolidated into an active memory pack under 1,000 tokens (<1% of the context window).
  • That is a 99%+ cut in reloaded context cost on every session restart.
  • Seamlessly switched between Google Antigravity CLI, Claude Code, and Cursor MCP on identical repos with zero model drift or architectural regression.

3. Architecture

graph TD
    subgraph Agents ["Supported Agent Environments"]
        AGY["Google Antigravity<br/>(PreInvocation & Stop Hooks)"]
        CLAUDE["Claude Code<br/>(SessionStart & Stop Hooks)"]
        CURSOR["Cursor / Windsurf<br/>(Model Context Protocol stdio)"]
    end

    subgraph CoreEngine ["engrim Core Engine (v1.3.0)"]
        ADAPTERS["Adapters & Hooks<br/>(agy, claude, mcp)"]
        PROVENANCE["Agent Provenance Engine<br/>(origin_agent tracking)"]
        ROUTER["Hybrid Retrieval & Minder<br/>(bm25 lexical + vector cosine)"]
    end

    subgraph Storage ["Local-First SQLite Store (~/.engrim/memory.db)"]
        MEMORIES[("Curated Memories<br/>(decisions, facts, feedback)")]
        FTS5["FTS5 Full-Text Search<br/>(porter stemmer, triggers)"]
        VEC["Vector Embeddings<br/>(model2vec static embeddings)"]
        LOG["Flight Recorder Log<br/>(turns + action lines)"]
    end

    AGY <-->|"hook / CLI"| ADAPTERS
    CLAUDE <-->|"hook / CLI"| ADAPTERS
    CURSOR <-->|"JSON-RPC (stdio)"| ADAPTERS
    ADAPTERS --> PROVENANCE
    PROVENANCE --> ROUTER
    ROUTER --> MEMORIES
    MEMORIES --- FTS5
    MEMORIES --- VEC
    ADAPTERS --> LOG

4. Multi-Agent Quickstart

Installation

pip install engrim

Auto-Detection (Recommended)

Run engrim setup without arguments. It automatically detects installed environments on your machine and configures them all:

engrim setup
  • If ~/.gemini exists $\rightarrow$ wires Antigravity lifecycle hooks, skill, and MCP server.
  • If ~/.claude exists $\rightarrow$ wires Claude Code SessionStart, Stop, status line, and CLAUDE.md.
  • If ~/.cursor exists $\rightarrow$ generates and merges Cursor MCP configuration.

Explicit Platform Setup

Google Antigravity

engrim setup --agy
  • Configures ~/.gemini/config/hooks.json to execute engrim hook --agent agy --event boot on PreInvocation and engrim hook --agent agy --event stop on Stop.
  • Deploys the canonical Antigravity skill to ~/.gemini/config/skills/engrim/SKILL.md.
  • Registers the MCP server in ~/.gemini/antigravity-cli/mcp_config.json and ~/.gemini/config/mcp_config.json.

Claude Code

engrim setup --claude
  • Wires SessionStart, SessionEnd, Stop, and UserPromptSubmit hooks in ~/.claude/settings.json.
  • Configures live ambient status line in Claude Code's status bar.
  • Appends memory usage notes to ~/.claude/CLAUDE.md.

Cursor & Windsurf

engrim setup --cursor
  • Adds engrim to ~/.cursor/mcp.json running engrim serve --mcp.

All Platforms

engrim setup --all
  • Configures every supported environment in one command.

(Use --dry-run with any setup command to inspect changes without modifying disk).


5. Agent Provenance Tracking

When multiple agents collaborate on a single codebase, provenance matters. engrim records the origin of every memory entry with the origin_agent field:

  • Allowed values: antigravity, claude-code, cursor, cli, or user.
  • Automatically populated based on the active hook, MCP client, or CLI session.
  • Subtly surfaced in engrim context and engrim list:
🧠 engrim · memory restored for this project — you don't have to re-explain · /workspace
  18 of 54 curated records loaded (~3850 chars) · the rest one `recall` away

[DECISION]
- #961 [DECISION] (via Antigravity): Inverted stop loss matrix for high volatility  (risk, execution)
- #942 [DECISION] (via Claude Code): Switched primary database from MongoDB to PostgreSQL  (db, schema)
- #910 [DECISION] (via Cursor): Standardized on Pydantic v2 schemas across API boundaries  (api, types)

Existing databases are non-destructively migrated on first access via ALTER TABLE memories ADD COLUMN origin_agent TEXT.


6. Hardened Model Context Protocol (MCP) Server

Launch the zero-dependency, JSON-RPC 2.0 stdio MCP server:

engrim serve --mcp
# or: engrim mcp

stdout is strictly reserved for JSON-RPC messages, redirecting all diagnostic logs to stderr.

Core MCP Tools Exposed:

Tool Signature Purpose
engrim_recall (query: str, project: str = "auto", k: int = 5, type: str = None) Hybrid (keyword + semantic) search over project memory.
engrim_add (type: str, summary: str, detail: str = None, tags: list[str] = []) Write a durable memory record persisted across sessions.
engrim_context (project: str = "auto", budget: int = 4000) Retrieve the session-boot memory pack within a character budget.
engrim_review (project: str = "auto") Check uncaptured decisions from transcript logs before clearing.

7. CLI Reference

Command Usage Description
engrim add engrim add -t decision -s "..." [--origin-agent agy] Insert memory record (types: decision, fact, feedback, state, user, reference).
engrim recall engrim recall -q "database" Ranked hybrid recall for the project (--log searches raw turns).
engrim context engrim context [-b 4000] Priority-ordered, budget-capped session-boot pack.
engrim hook engrim hook --agent agy --event boot Agent lifecycle hook runner for Antigravity and Claude Code.
engrim setup engrim setup [--agy|--claude|--cursor|--all] Universal multi-agent environment configuration.
engrim serve engrim serve --mcp Start stdio MCP server for agent integrations.
engrim review engrim review "Safe to clear" coverage check: scans logs for uncurated decisions.
engrim list engrim list [-k 20] List recent memories for the current project.
engrim supersede engrim supersede --id 12 --status superseded Mark a record superseded without erasing history.
engrim sync engrim sync [DIR] Mirror markdown memories into the store (idempotent seed-once).

8. Continue-As-Clear Workflow

  1. Capture as you work: Whenever a major decision or architectural rule is made, run engrim add or invoke engrim_add via your agent.
  2. Use resume-pointer: Before ending a session or clearing, add a record tagged resume-pointer describing the immediate next task. The newest pointer is pinned under [▶ RESUME HERE] at the top of the next session's boot pack.
  3. Verify with engrim review: Check that all recent decisions are captured.
  4. Clear freely (/clear): The session window is wiped clean; engrim automatically re-injects the active memory pack on the next prompt or invocation.

9. Security & Privacy

  • 100% Local & Offline: All memory records and logs reside in a local SQLite file (~/.engrim/memory.db). No telemetry, no cloud sync, no tracking.
  • Model Storage: Uses model2vec for local static embeddings (~30ms load time, no GPU required, runs on CPU). Can run pure-lexical (ENGRIM_EMBED=off) for zero extra dependencies.
  • POSIX File Permissions: Databases are created with restricted owner-only permissions (0600).
  • Git Protection: *.db is gitignored by default; your memories never accidentally commit to version control.

10. License

MIT © 2026 Tim Gordon.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

engrim-1.3.0.tar.gz (80.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

engrim-1.3.0-py3-none-any.whl (55.0 kB view details)

Uploaded Python 3

File details

Details for the file engrim-1.3.0.tar.gz.

File metadata

  • Download URL: engrim-1.3.0.tar.gz
  • Upload date:
  • Size: 80.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for engrim-1.3.0.tar.gz
Algorithm Hash digest
SHA256 232c5b0fd4a000fb38d53f67b51394e8e6a032de43cc65dc9653ab75454396fd
MD5 bbd0fde3a893483805b5f2eddd5b822e
BLAKE2b-256 9dad6a6e229a5cc4ecb264a6e4c9b26c0b97543399b81f62e3f89c1aa1294cfb

See more details on using hashes here.

Provenance

The following attestation bundles were made for engrim-1.3.0.tar.gz:

Publisher: release.yml on timgordontg/engrim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file engrim-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: engrim-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 55.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for engrim-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f619a6ae62a86b5ad5777804f483e0ed80c80c8d52d578fa135c0accf9126741
MD5 c3e1635b7ee2a4bef3605927c14ad4f4
BLAKE2b-256 74ff8f2b4d6529fd83d0adb3fef5c6444f68793b90216eaed9fe5cf33144cfa0

See more details on using hashes here.

Provenance

The following attestation bundles were made for engrim-1.3.0-py3-none-any.whl:

Publisher: release.yml on timgordontg/engrim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 files

1.2.2

2 files

1.2.1

2 files

1.2.0

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.0

2 files

0.8.1

2 files

0.8.0

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page