Cortext
Read this in Português.
Long-term memory for AI agents: an indexed W5H memory graph that stores and recalls in under a millisecond, plugs into Claude Code, Cursor and Copilot, and shows its memory levels in a live dashboard.
Cortext gives an agent a memory that is structured rather than a flat vector store. Every memory is a W5H record (who, what, why, when, where, how), checked against what is already known so contradictions don't slip in, and recalled by a deterministic, index-backed parser that returns a compact context block instead of raw chunks. Pure Python, zero required dependencies, local-first.
pip install cortext-memory
cortext-memory install claude # or: cursor | copilot | vscode | mcp
cortext-memory dashboard
What's inside
| Indexed memory graph | Inverted indexes by token, participant and place; candidates come from the indexes, never a scan. Entities link memories into a graph. |
| Incremental SQLite | WAL-mode store that writes only what changed, one file for every namespace. Access counts are written behind, so reads never wait on the disk. |
| Memory levels | working → episodic → semantic → fading → archived, from age, reinforcement, importance and Ebbinghaus retrievability. |
| Contradiction-aware writes | CanonicalValidator flags or blocks X vs not X at write time (heuristic → embedding → LLM levels). |
| Self-pruning | Ebbinghaus decay, a forget gate, and a DreamAgent that merges duplicates and prunes what's no longer used. It never prunes important memories or summaries. |
| Agent integrations | Claude Code mod (function hooks), universal hook adapter (Claude Code, Cursor, Copilot), MCP server for any client, one-command installers. |
| Control panel | Live dashboard served by the local daemon: memory clouds per level, latency, recall playground, memory browser, activity feed. |
Performance
Measured with python bench/latency_benchmark.py (synthetic corpus: 300
participants, a verb shared by 10% of memories; Linux, CPython 3.10, NVMe). Writes
are validated and persisted to SQLite before returning.
| Memories | Write + validate + persist | Recall by participant | Recall by text | Cold reload |
|---|---|---|---|---|
| 1,000 | 0.37 ms | 0.38 ms | 0.06 ms | 58 ms |
| 5,000 | 0.39 ms | 0.18 ms | 0.12 ms | 0.24 s |
| 20,000 | 0.44 ms | 0.53 ms | 0.26 ms | 0.93 s |
| 50,000 | 0.53 ms | 1.13 ms | 0.55 ms | 2.3 s |
The same corpus on 0.3.1 (in-memory only, nothing persisted): at 20,000 memories, a write took 4.3 ms, a recall 193 ms, and saving rewrote the whole JSON file (0.7 s). That is ~10× faster writes and ~360× faster recall, now with durable storage. Through the daemon, an agent hook's recall round-trip costs about 1 ms plus process start.
Quality, from python bench/run_benchmark.py against an unstructured top-k baseline:
| Scenario | Tokens (baseline → Cortext) | Savings | P@5 (baseline → Cortext) | Contradiction detection |
|---|---|---|---|---|
| customer_support | 540 → 115 | 78.7% | 0.367 → 0.917 | 100% |
| personal_assistant | 380 → 88 | 76.8% | 0.840 → 0.800 | 67% |
| Average | — | 77.8% | 0.603 → 0.859 | 83.5% |
Coding agents
cortext-memory install claude # Claude Code: function-hook mod
cortext-memory install cursor # Cursor: hooks + MCP (+ --project <repo> for a rule)
cortext-memory install copilot # Copilot CLI: hooks + MCP
cortext-memory install vscode --project . # VS Code Copilot Chat: MCP + instructions
cortext-memory install mcp # print config for any other MCP client
- Claude Code: the mod attaches recalled memory to every prompt, stores every
finished turn, gives the model
memory_recall/memory_remember/memory_forgettools, and adds a/memorypane with the levels. Also installable as/plugin install cortext --marketplace jhonymiler/Cortex. - Cursor / Copilot: their hooks inject the project's long-term memory at session start and capture every turn. Per-prompt recall runs through the MCP tools, guided by an instructions file ("hook emulation").
- Agents without hooks (Windsurf, Claude Desktop, Codex, Gemini CLI, Zed, …): the MCP server's instructions make the model recall at the start of a task, remember durable facts, and log a summary at the end.
Every agent talks to one local daemon (127.0.0.1:7077, started on demand) that
keeps a warm graph per project. See docs/AGENTS.md.
Library
from cortext import CortextV5
cortex = CortextV5(namespace="myapp", path="~/.cortext/memory.db") # path is optional
cortex.remember(who=["Maria"], what="reportou erro de pagamento",
why="cartão expirado", how="orientada a atualizar dados")
context, result = cortex.recall("O que Maria reportou?")
print(context)
# Maria | reportou erro de pagamento → orientada a atualizar dados
cortex.levels() # {'working': 1, 'episodic': 0, 'semantic': 0, 'fading': 0, 'archived': 0}
cortex.stats() # sizes, writes, levels, p50/p95 latency
CortexV5 is thread-safe. For the "recall before the call, store after it"
loop there is a framework-neutral AgentMemoryBridge:
from cortext.integration import AgentMemoryBridge
bridge = AgentMemoryBridge(namespace="session-1", path="~/.cortext/memory.db")
context = bridge.recall_context(user_input) # before the LLM call
bridge.store_turn(user_message=user_input, assistant_message=reply) # after the turn
LangChain, LangGraph and other frameworks: docs/INTEGRATION.md.
Hermes: cortext-memory setup installs the bundled provider, see
integrations/hermes/README.md.
How it works
WRITE W5H ─▶ CanonicalValidator (candidates from the indexes) ─▶ MemoryGraph ─▶ SQLite (changed rows only)
RECALL query ─▶ extractor (PT/EN/ES regex, optional LLM) ─▶ indexed candidates ─▶ rank ─▶ compact block
DECAY Ebbinghaus retrievability + forget gate; DreamAgent merges duplicates, prunes, replays
LEVELS working → episodic → semantic → fading → archived
Design details: docs/ARCHITECTURE.md.
Install
pip install cortext-memory
pip install "cortext-memory[embeddings]" # optional: sentence-transformers for embedding recall/validation
Development
python3 -m venv .venv && .venv/bin/pip install -e ".[dev]"
.venv/bin/python -m pytest -q # 243 tests
.venv/bin/ruff check .
.venv/bin/python bench/latency_benchmark.py # latency at scale
.venv/bin/python bench/run_benchmark.py # token savings / precision
claude plugin test cortext/agents/claude_mod # the Claude Code mod
License
MIT — see LICENSE.
Metadata
Release files for cortext-memory 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cortext_memory-0.4.0.tar.gz | 121.5 kB | With provenance | Details for cortext_memory-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cortext_memory-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for cortext_memory-0.4.0-py3-none-any.whl |
Total release size: 244.5 kB
Release files / cortext_memory-0.4.0.tar.gz
| Download URL | cortext_memory-0.4.0.tar.gz |
|---|---|
| Size | 121.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4cc91abe1863ab9f2169d3c60c53ce0afaa7869d3a78c10df687db0105920a9f
|
|
BLAKE2b-256 checksum How to use checksums |
a9ebe71d0b6c0a5a8d0e1cc6c0db5d214ea8eeee6039a5e2f5a4661032acdf23
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 8, 2026.
Transparency logRelease files / cortext_memory-0.4.0-py3-none-any.whl
| Download URL | cortext_memory-0.4.0-py3-none-any.whl |
|---|---|
| Size | 123.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
899e438c026c6d7c8f6fee788a2e8a1fec17ee8986b3d78a18f6148ac55145dc
|
|
BLAKE2b-256 checksum How to use checksums |
42f12a452c2499b85c68b9ee3dbef9007bb5c6e68a71783308fdd6945a9cac49
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 8, 2026.
Transparency logSecurity for cortext-memory 0.4.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for cortext_memory-0.4.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 8, 2026.
Transparency logA 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.