Skip to main content

2D graph visualization of a Python codebase

Epistemic Graph Memory

A local knowledge graph that gives AI coding agents long-term project memory.
5,000 lines of Python. Zero cloud dependencies. One pip install.

pip install epistemic-graph-memory[all]

PyPI License Tests Python


The problem

AI coding agents reconstruct project context from scratch every session. They re-read files they've already read, re-derive architecture they've already derived, and lose decisions made yesterday. Claude Code, Cursor, Codex, OpenCode — they all forget.

The solution

A SQLite-backed knowledge graph that lives in your project at .agents/graph_memory.sqlite. It ingests your codebase's AST (functions, classes, call graphs, imports), records agent decisions in an append-only ledger, detects when agents contradict each other, and produces deterministic snapshots that inject directly into agent system prompts — with byte-stable caching so prompt caches stay hot.

All 12 MCP tools, a 25-command CLI, lifecycle hooks for 9 agent harnesses, and a streamable HTTP endpoint for remote agents.


What it actually does

Code understanding. Parses Python, TypeScript, JS/JSX, Go, and Rust via Tree-sitter. Extracts signatures, docstrings, line ranges, call graphs, and inheritance. Cross-file call resolution wires stubs to real definitions across your entire repo. Batch ingestion processes this repo's 37 files in 0.45 seconds; unchanged re-ingests take 0.06 seconds (hash-skip).

Agent memory. Every decision an agent makes — what it changed, why, when — goes into an append-only Decision_Ledger. A reflection engine digests the last 30 days of real decisions into structured memory cards. When two agents disagree about a fact (different values for the same field), the contradiction is recorded and surfaced — no silent overwrites.

Trust decay. Facts decay over time with effective = base × 0.5^(days/30). Re-verifying a fact resets it to 100%. Stale, unreferenced nodes get garbage-collected. This means the graph self-maintains — old assumptions fade, recent verifications stay sharp.

Prompt injection. graph-memory snapshot produces a deterministic, content-fingerprinted Markdown snapshot. If nothing changed, you get the exact same bytes — so Claude's prompt cache, Cursor's context cache, whatever — stays warm. Zero wasted tokens on unchanged context.

Transport. Runs over stdio MCP (Claude Desktop, Cursor, Codex) and streamable HTTP MCP (OpenCode, Docker, remote agents). One binary, both transports. Health check at /health.

Import / export. Migrating from mem0? graph-memory import-mem0 export.json. Have a CLAUDE.md? graph-memory import-md CLAUDE.md. Want a browsable Obsidian vault with [[wikilinks]] for every graph edge? graph-memory export-obsidian ~/vault.


Setup

pip install epistemic-graph-memory[all]

The [all] extra installs Tree-sitter parsers for all 6 languages plus the HTTP transport (uvicorn + starlette). If you only need Python:

pip install epistemic-graph-memory

MCP configuration

Add to your agent's MCP config:

{
  "mcpServers": {
    "graph-memory": {
      "command": "graph-memory-mcp"
    }
  }
}

For remote-only agents (OpenCode, Docker):

graph-memory-mcp-http                    # http://127.0.0.1:8765/mcp

Then point your agent at http://127.0.0.1:8765/mcp.

One-command agent hooks

graph-memory hook install                 # auto-detect and configure all frameworks
graph-memory hook install --framework cursor
graph-memory hook status

This wires lifecycle capture into Claude Code, ZCode, Cursor, Codex, OpenCode, Antigravity, Qoder, and Hermes — PostToolUse triggers incremental AST ingest of edited files (<5ms), session-end distills transcripts into graph facts, and session-start refreshes all snapshots.


CLI

# Ingest entire codebase (polyglot AST + call graphs)
graph-memory ingest-code .

# Re-parse a single changed file (<5ms, skips if unchanged)
graph-memory ingest-file src/engine.py

# Generate prompt-cache-stable snapshot
graph-memory snapshot --max-tokens 600 --min-trust 0.7

# Search nodes (FTS5 + identifier substring fallback)
graph-memory search "effective_tr"
graph-memory search "trust decay"

# Decision audit trail
graph-memory query-history --agent Hermes --days 7

# Contradiction detection
graph-memory contradictions

# Stale-node garbage collection
graph-memory prune --days 60

# Import existing memories
graph-memory import-md CLAUDE.md
graph-memory import-mem0 memories.json

# Export to Obsidian vault
graph-memory export-obsidian ~/vaults/my-project

# HTML / 3D visualization
graph-memory export-html graph.html
graph-memory export-3d graph_3d.html

MCP tools

Tool What it does
get_active_snapshot Deterministic, cache-stable Markdown snapshot of high-trust graph state
distill_session Micro-compaction: distills raw transcript turns into structured graph facts
search_session_history FTS5 search across episodic session logs
query_decision_history Append-only decision ledger (who changed what, why, when)
search_nodes FTS5 + substring search across nodes
read_code_snippet AST-derived signature, docstring, line bounds, source snippet
ingest_file Incremental single-file AST re-parse (<5ms, hash-skip)
create_entities Create graph nodes with trust scores
create_relations Create directed edges between nodes
merge_entities Merge entities with canonical pointer redirect
open_nodes Serialize subgraphs around specific nodes
read_graph Serialize the complete knowledge graph

Architecture

graph_memory/
├── core/
│   ├── engine.py        # SQLite graph engine: CRUD, trust decay, ledger, search, batch upsert, contradictions, prune
│   ├── ingest.py        # Tree-sitter AST ingestion, batch pipeline, cross-file call resolution
│   ├── importers.py     # Markdown + mem0 import
│   ├── obsidian.py      # Obsidian vault export with [[wikilinks]]
│   ├── snapshot.py      # Deterministic, cache-stable snapshot generation
│   ├── memory.py        # Data-driven reflection engine
│   ├── lifecycle.py      # Harness-agnostic event dispatcher
│   ├── distill.py       # Session transcript micro-compaction
│   └── knowledge.py     # LLM-powered MOC summarization
├── mcp/
│   ├── server.py        # Stdio MCP server (12 tools)
│   └── http_server.py   # Streamable HTTP MCP transport
├── integrations/
│   └── framework_hooks.py  # 9-framework auto-install + lifecycle wiring
└── cli.py               # 25-command CLI

Storage: Single SQLite file per project at .agents/graph_memory.sqlite. WAL mode for concurrent safety. FTS5 for full-text search. No external databases, no servers, no cloud.

Node types: Fact_Node (deterministic ground truth from AST/Git), Knowledge_Node (architecture, design decisions), Episode_Node (completed task sequences), Release_Node (published versions).

Trust model: Query-time decay — effective = base × 0.5^(Δdays/half_life). Re-verification resets to 100%. Stale, unreferenced nodes get soft-deleted by the prune command.


Numbers

Metric Value
Source code 5,066 lines Python
Test code 1,672 lines, 57 tests
MCP tools 12
CLI commands 25
Agent harnesses 9
AST languages 6 (Python, TS, TSX, JS, JSX, Go, Rust)
Dependencies 4 runtime (mcp, tree-sitter + 2 parsers)
External services 0

License

MIT — Divyansh Ailani

Download files

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

Source Distribution

epistemic_graph_memory-3.7.1.tar.gz (75.0 kB view details)

Uploaded Source

Built Distribution

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

epistemic_graph_memory-3.7.1-py3-none-any.whl (89.8 kB view details)

Uploaded Python 3

File details

Details for the file epistemic_graph_memory-3.7.1.tar.gz.

File metadata

  • Download URL: epistemic_graph_memory-3.7.1.tar.gz
  • Upload date:
  • Size: 75.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for epistemic_graph_memory-3.7.1.tar.gz
Algorithm Hash digest
SHA256 d34f1b13b1fd1ca54f1b66e5871f9f8349e109168171d0f68cc1069ed247bbd1
MD5 18d6acca2ffc5e3348725d0763318a8d
BLAKE2b-256 61c7c6d5122c4efa8640950ac0019deb83e378033e9c591b0c1bbcdc3868cb0d

See more details on using hashes here.

File details

Details for the file epistemic_graph_memory-3.7.1-py3-none-any.whl.

File metadata

  • Download URL: epistemic_graph_memory-3.7.1-py3-none-any.whl
  • Upload date:
  • Size: 89.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for epistemic_graph_memory-3.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aafc8b72c3843c6bd21ab03b982731d66f3f4ba31d31753fa60b33ce9b87af72
MD5 9ef6a429eee199a25b874fd0c783d4b2
BLAKE2b-256 0a4c8e5cb29db88b11657c39ea586b2283c7bafad75fb2c280fe94488f2e9dcd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page