Skip to main content

Cortex: Persistent Graph Memory for Coding Agents

Cortex is a high-performance Model Context Protocol (MCP) server that provides AI coding agents with persistent, branch-aware, and mutable memory powered by an embedded graph database (KùzuDB).

Unlike traditional vector databases that suffer from outdated context, conflicting documents, and context bloat, Cortex tracks active architectural decisions, explicit supersession lineages, negative knowledge (failed attempts), and task handovers.


⚡ Core Capabilities

  1. Decision Supersession: When a tool or framework is replaced (e.g. SQLite → SQLAlchemy), Cortex updates the old decision to superseded and creates an explicit [:SUPERSEDES] graph edge. Agents never hallucinate obsolete architectures.
  2. Negative Knowledge Tracking: Store failed engineering attempts as kind="failed_attempt" to prevent future agents from repeating loops of known mistakes.
  3. Live Git Handover Checkpoints: handoff() captures project summaries, next steps, blockers, and automatically discovers uncommitted dirty files from Git status without manual tracking.
  4. Authority & Injection Defense: Untrusted external memories (e.g. untrusted README injections) are quarantined as proposed. Agent overrides against explicit user decisions are flagged as honest abstentions.
  5. Zero Disk Locks on Reads: recall() is a 100% pure read operation (<30ms latency), allowing multiple concurrent tools, subagents, and terminals without file lock contention.

📁 Repository Structure

├── brain/
│   ├── __init__.py
│   ├── db.py               # Lean KùzuDB connection & schema (Memory, Handover, SUPERSEDES)
│   ├── git_context.py      # Batched live Git discovery (branch, commit, dirty files)
│   ├── memory_service.py   # Core logic: recall, remember, handoff, forget
│   └── server.py           # FastMCP stdio server exposing tools to agents
├── scripts/
│   ├── benchmark_30_sessions.py # Official 30-session evaluation benchmark
│   ├── test_git_timeline.py     # Live Git branch isolation demo
│   ├── brain_cli.py             # CLI bridge for running tools directly
│   └── audit_graph.py           # Database inspection & verification tool
├── .agents/
│   └── mcp_config.json     # Workspace-scoped Antigravity configuration
├── .mcp.json               # Standard VS Code / Cursor / Claude Desktop MCP config
├── opencode.json           # Native OpenCode MCP configuration
├── AGENTS.md               # Agent guidelines instructing models when to use Cortex
├── requirements.txt
└── pyproject.toml

🚀 Quickstart

1. Installation

Install directly via pip from GitHub:

pip install git+https://github.com/Harimuraliksofficial/Cortex.git

Or clone for development:

git clone https://github.com/Harimuraliksofficial/Cortex.git
cd Cortex
pip install -e .

2. Run the Benchmark

Verify that all 30 simulated sessions pass end-to-end:

python scripts/benchmark_30_sessions.py

3. Test Git Timeline Isolation

See how Cortex automatically isolates memories and captures uncommitted files across Git branches:

python scripts/test_git_timeline.py

🔌 Connecting to Coding Agents

Antigravity (IDE & 2.0 Desktop)

Add Cortex to ~/.gemini/config/mcp_config.json or .agents/mcp_config.json:

{
  "mcpServers": {
    "cortex": {
      "command": "cortex",
      "args": [],
      "env": {
        "PYTHONIOENCODING": "utf-8"
      }
    }
  }
}

OpenCode

Add Cortex to ~/.config/opencode/opencode.jsonc or opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "cortex": {
      "type": "local",
      "command": ["cortex"],
      "environment": {
        "PYTHONIOENCODING": "utf-8"
      }
    }
  }
}

Claude Desktop / Cursor

Use the included .mcp.json.


🛠️ MCP Tool Reference

Tool Parameters Description
recall query, token_budget, repo_path Retrieves active decisions, constraints, and open handovers fitted into the token budget. Pure read (<30ms).
remember title, content, topic, kind, subject_key, replaces_previous, repo_path Records durable knowledge (decision, constraint, failed_attempt). Supports decision supersession.
handoff summary, next_steps, blockers, repo_path Checkpoints current task state and attaches uncommitted dirty files from Git status.
forget target, repo_path Cascading verified deletion that scrubs matching memories with 0 leaks.

📄 License

MIT License.

Metadata

Release files for cortex-graph-memory 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cortex-graph-memory 1.0.0
File Size Uploaded Provenance Actions
cortex_graph_memory-1.0.0.tar.gz 12.5 kB Without provenance Details for cortex_graph_memory-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cortex-graph-memory 1.0.0
File Interpreter ABI Platform Actions
cortex_graph_memory-1.0.0-py3-none-any.whl Python 3 none any Details for cortex_graph_memory-1.0.0-py3-none-any.whl

Total release size: 24.5 kB

Release files / cortex_graph_memory-1.0.0.tar.gz

Download URL cortex_graph_memory-1.0.0.tar.gz
Size 12.5 kB
Tags Source
SHA-256 checksum
How to use checksums
54970224cbaae4b70097c16d87942d94cf3e773a7d37856b475e238d5f64fe73
BLAKE2b-256 checksum
How to use checksums
8648d31811a9f7e0d685f2e0125ef1f9c67435520cec7fffc158a1608d8441fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release files / cortex_graph_memory-1.0.0-py3-none-any.whl

Download URL cortex_graph_memory-1.0.0-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1d6f13161ea70d6ca47d9b0ebf4a86e152b670781ea35eaf0c1f0a84316f0cb9
BLAKE2b-256 checksum
How to use checksums
b3145abe93598ec3f48e8b42d0eb4286b5c8f03963b28fee279fef58e6de4f88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Security for cortex-graph-memory 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

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