Search DevTools

Jump to any tool or page

ZenBrain Memory

Unexplored

Seven-layer agent memory: episodic, semantic, procedural and core. Local SQLite, no account.

zensation-ai22 stars5 forksData & Databases
View source

Install

Terminal

$npx -y @zensation/mcp

mcp_config.json

{
  "mcpServers": {
    "ai-zensation-zenbrain": {
      "env": {
        "ZENBRAIN_DB": "${ZENBRAIN_DB}",
        "ZENBRAIN_CONTEXTS": "${ZENBRAIN_CONTEXTS}"
      },
      "args": [
        "-y",
        "@zensation/mcp"
      ],
      "command": "npx"
    }
  }
}

Documentation

ZenBrain The neuroscience-inspired memory system for AI agents. Memory for agents that lasts across sessions: seven layers, from working memory to long-term facts and procedures, and 20 tested algorithm modules for what memory research describes, such as spaced repetition, Hebbian strengthening, sleep replay and emotional tagging.Pure TypeScript. No third-party dependencies in algorithms and core. 1020 tests as of v0.7.0. Extracted from ZenAI, the AI platform we ran in our own operation.

npm install @zensation/algorithms     # the library, Node 22 or newer
claude mcp add --scope user zenbrain -e ZENBRAIN_DB=~/.zenbrain/memory.db -- npx -y @zensation/mcp   # memory for Claude Code

The same MCP server runs in Claude Desktop and Cursor (configuration) and comes as a Claude Code plugin · Vercel AI SDK middleware: @zensation/ai-sdk

Status: pre-1.0, semver — the public API can still change before 1.0. 1020 tests green in CI as of v0.7.0: 1007 on each of Node 22, 24 and 26, and 13 more against PostgreSQL with pgvector · the current version of every package published to npm with build provenance · every change recorded in the CHANGELOG · issues and pull requests are answered; replications and counter-results are especially welcome.

Self-hosted: the library makes no network calls of its own. Memory lives in SQLite or PostgreSQL that you operate; an embedding model or an LLM is optional and your choice.

Versions at a glance (checked 4 November 2026)

Repository releasev0.7.0, 22 November 2026.
Packages@zensation/algorithms 0.6.2 · @zensation/core 0.7.0 · @zensation/mcp 0.3.3 · Claude Code plugin 0.1.4 (manifest)
Research recordsSoftware: Zenodo 10.5281/zenodo.24426158 (v0.6.3; all versions under 10.5281/zenodo.22260018) · Paper: version 9, Zenodo 10.5281/zenodo.23832288 and arXiv:2604.23878v4

▶ Try the live playground in your browser — runs this published code, no install required.

Three ways in

  • In the browser: the playground above runs this published code; nothing to install.
  • Across Claude Code sessions: the Claude Code plugin starts @zensation/mcp 0.3.1. A note stored in one session comes back in the next when the question shares words with it, as the top semantic result with a score above 0; recall is lexical until you add an embedding provider. Checked on 4 November 2026 at the protocol level: two server processes, one memory file, Node 22.23.3.
  • Re-running the numbers: first what was measured, then the reproduction packages with the raw material and the scripts that check it.

📄 Paper & Citation — ZenBrain: A Neuroscience-Inspired 7-Layer Memory Architecture for Autonomous AI Systems

@misc{bering2026zenbrain,
  title         = {ZenBrain: A Neuroscience-Inspired 7-Layer Memory Architecture for Autonomous AI Systems},
  author        = {Bering, Alexander},
  year          = {2026},
  eprint        = {2604.23878},
  archivePrefix = {arXiv},
  primaryClass  = {cs.AI},
  doi           = {10.5281/zenodo.19353663},
  url           = {https://arxiv.org/abs/2604.23878}
}

Feedback, replications, and counter-results are explicitly welcome — please open an issue or reach out via research@zensation.ai.

Your AI forgets everything after every conversation. ZenBrain gives it a memory that lasts across sessions, split into layers the way human memory is, and ships the mechanisms memory research describes (spaced repetition, emotional tagging, Hebbian strengthening, forgetting curves, sleep replay) as tested functions. Which of them run on their own and which you call yourself is in one table.

Architecture vs. this package. ZenBrain's architecture is seven memory layers, a MemoryCoordinator and nine foundational algorithms, plus six Predictive Memory Architecture (PMA) components (paper, version 9). The six PMA components are proprietary: they run in our own private production system and are not in these packages, which contain the hooks they plug into. This open-source package ships the algorithm library: 10 core algorithms + 10 advanced research modules (20 modules), zero-dependency.


Benchmark: LongMemEval-500

What was measured. On LongMemEval-500 (500 questions), the measured ZenBrain arm is a Python port of a scoring class from our test harness, not the seven-layer system and not an import of these packages. Input tokens are counted in the answer step only; building the memory is not counted. Source: paper version 9, Zenodo 10.5281/zenodo.23832288 (31 October 2026) and arXiv:2604.23878v4.

In that setup, three of nine head-to-head comparisons hold against Letta, Mem0 and A-Mem — all three against A-Mem; the remaining six, against Letta and Mem0, show no significant difference. Three competitors x three LLM judges, Bonferroni-corrected (alpha = 0.05/18) and version-matched. That arm reaches 91.3% of the binary-judge accuracy of a full-context comparison arm (whose answer model reads the whole history) with 1/109.7 of its input tokens in the answer step (47.7% vs. 52.2%).

Agreement between LLM judges is not the same as independent confirmation: the paper counts three repetitions of one model as one rater. Our separate package voteworth measures how often two voters of a judge or voter panel pick the same answer when both break from the plurality, and corrects the vote for voters that do, naming the panel shape where it cannot.

Works out of the box without an embedding provider — lexical ranking, nothing extra to install. nomic-embed-text can be added as the embedding provider; it was the embedder of the measured run. The figures above were not measured with this package: per the correction notice, the measured arm is a Python port of a test-harness class, not an import of the packages.

The paper prints where ZenBrain loses as well: on LoCoMo, substring-based aggregate F1 favours lexical retrieval (BM25) by metric design, and we do not contest that. The advantage is most pronounced in the judge-graded comparisons and on cross-session reasoning.

The mechanism comparison further down re-runs from this repository in under a minute — bash scripts/compare-mechanisms.sh, no API keys; it needs git, Node and network access to clone the three compared repositories at the pinned commits. It prints a positive and a negative control before the result, so the instrument can be checked before its output is trusted. The mechanism ablation behind paper Tables 7–9 also runs from here: cd backend && npm run experiments, and CI compares every point estimate with the published ones. The method and the effect sizes behind the LongMemEval numbers above are in the paper; this repository ships no runner for those. The archived packages below run the significance tests and effect sizes in full, and the mechanism ablation behind paper Tables 7–9.


Reproduction packages

The raw material behind the numbers above is deposited on Zenodo, open access and citable. Both links are concept DOIs and resolve to the latest version, the same convention this README uses for the paper archive; each description was measured against the version named after it.

  • Mechanism ablation, paper Tables 7–9 — 10.5281/zenodo.22162063 (described here: v1.0.0). Four experiment suites (95 tests), the reference JSON the paper's tables were generated from, and verify-against-reference.mjs, which diffs a fresh run against that reference and exits non-zero on drift. npm install && npm run experiments; the run itself needs no API keys and no network, and finishes in under a minute on a laptop. Two of the paper's other ablation tables need data this package does not carry: Table 11 the LoCoMo corpus, Table 13 a different pipeline. The package says so itself.
  • Measurement package, LongMemEval-500 and the real-pipeline flag ablation — 10.5281/zenodo.22161977 (described here: v1). Per-(system, judge, seed) judged outputs, the flag manifests as recorded at run time, a SHA256SUMS.txt covering every file in the package, and the analysis scripts. Three of those scripts are stdlib-only and self-checking — the full-context comparison behind the 91.3% figure, the judge-agreement figures, and the real-pipeline flag-ablation table: each prints every re-derived value next to the reference it has to match, and exits non-zero on mismatch. The significance tests behind the nine head-to-head comparisons against Letta, Mem0 and A-Mem sit in a separate script that needs numpy and scipy; it recomputes all eighteen pairwise tests and rewrites the deposited significance JSON byte-identically, so what catches a mismatch there is the checksum, not an exit code.

Both packages name what they do not cover. Replications and counter-results are welcome: research@zensation.ai.


How ZenBrain differs from Mem0, Letta and Zep

ZenBrain's architecture takes its mechanisms from human memory research: nine foundational algorithms, which are in this library, and six Predictive Memory Architecture components, which are not public. In the paper's comparison table, none of the eight compared systems has more than two of the nine features. The table below records which of five of these mechanisms appear in the public source of three widely used memory systems, at pinned versions, on a fixed date.

MechanismZenBrainMem0LettaZep
FSRS-style spaced repetitionyes———
Hebbian learningyes———
Ebbinghaus forgetting curvesyes———
Sleep consolidationyes———
Emotional taggingyes———
Zero runtime dependenciesyes——n/a

How this was measured, 27 August 2026. Full-text search over the public source of mem0ai/mem0 at tag ts-v3.1.7 (npm mem0ai 3.1.7, PyPI mem0ai 2.0.19), letta-ai/letta-code at tag v0.31.2 (npm @letta-ai/letta-code 0.31.2) and getzep/zep at commit 7de18df, its last before that date, lockfiles excluded. getzep/zep holds examples and integrations for the hosted Zep Cloud, whose own source is not public: a dash in the Zep column covers that repository only, and there is no library to count dependencies of. A dash means the term does not occur in that snapshot — not that the system cannot do something comparable under another name. One case we know of: Letta Code revises memory in the background and calls it "dreaming" (sleep-time compute), which the term search for sleep consolidation does not match. In ZenBrain the mechanisms in this table are library functions; which of them the coordinator runs is in this table. Dependency counts are declared direct dependencies: @zensation/core resolves to two packages, both our own; mem0ai declares four, @letta-ai/letta-code eighteen. Re-run the whole check — the five mechanism rows and the dependency counts, at these pins — with scripts/compare-mechanisms.sh (--latest runs it against today's default branches instead); it prints its own positive and negative controls so you can see the instrument works before you trust the result.

Human memory does not work like a key-value store. The brain keeps specialised systems for different kinds of memory, forgets actively, modulates by emotion and retrieves by context. ZenBrain brings those mechanisms to AI agents, as a memory system with seven layers and as a library of the algorithms behind them.

Advanced algorithms (since v0.3.0, May 2026)

On top of the 10 core algorithms above, @zensation/algorithms ships 10 advanced algorithms grounded in recent neuroscience and ML research. Each is exposed as its own sub-path (@zensation/algorithms/<name>) and remains zero-dependency:

  • fsrs-vmPFC — Prediction-Error coupled FSRS
  • hebbian-two-factor — Two-Factor synaptic consolidation
  • sleep-simulation-selection — RL-based replay selection
  • spectral-health — Fiedler-value KG health monitor
  • ib-budget — Information-Bottleneck retention budget
  • dopamine-routing · hopfield-stm · personalized-pagerank · surprise-gradient-memory · temporal-multi-route

See CHANGELOG.md for details.

What runs on its own, and what you call yourself

@zensation/core is a memory system: the MemoryCoordinator stores, recalls, consolidates and forgets. @zensation/algorithms is a library of twenty modules of tested functions, and the coordinator calls only a few of them. Several mechanisms named in this README live in the library alone; you wire them into your own system where you want them.

MechanismThe coordinator (@zensation/core)The library (@zensation/algorithms)
LayersSeven layer classes. recall() searches episodic, semantic, procedural and core memory, working memory on request; the cross-context layer is not part of recall.—
Routingstore() picks the layer: step-by-step content becomes a procedure, an emotional weight above 0.5 an episode, a confidence above 0.9 a pinned core block, anything else a fact.—
Emotional taggingAt store() with automatic routing — not with an explicit type, and not when steps or procedural wording already made it a procedure. The weight decides episode or fact, and which episodes consolidation promotes; a weight you pass for a fact stretches its starting FSRS-style stability by 1 + weight.tagEmotion, computeEmotionalWeight
Spaced repetition (FSRS-style)Every fact gets an FSRS-style schedule. getReviewQueue() lists the due facts; a review your application reports with recordReview() updates the schedule. Recall does not rank by retrievability.FSRS-style scheduling, prediction-error-coupled FSRS
ForgettingNothing in long-term memory decays or is deleted on its own. forget(id, layer) deletes a memory on request together with what consolidation linked to it (episode ⇄ fact) and its working-memory copies; { cascade: false } deletes only the one memory. Working memory decays exponentially with the minutes since its last decay.Ebbinghaus retention, personal decay profiles
Consolidationconsolidate() turns each emotionally weighted episode among the 100 most recent into a fact, once.Sleep replay (selectForReplay, simulateReplay, pruneWeakConnections), simulation-selection loop
Hebbian learningNot used: core keeps no knowledge graph.Classic and two-factor Hebbian
Bayesian confidenceNot used.propagateForRelation and the rest of the module
Context-dependent retrievalNot used. The includeContext option never had an effect and was withdrawn in 0.5.0.captureEncodingContext, calculateContextSimilarity

The six Predictive Memory Architecture components of the paper are not in the packages; the packages contain the hooks they plug into (see Architecture vs. this package above).

Quick Start

Requires Node.js 22 or newer (since 0.4.0). On Node 20 or older, npm silently installs the last compatible release (@zensation/algorithms@0.3.4, @zensation/core@0.2.2) instead of the current one — which looks like a broken package but is a platform mismatch. See CHANGELOG.

npm install @zensation/algorithms
import {
  initFromDecayClass,
  getRetrievability,
  updateAfterRecall,
  tagEmotion,
  computeEmotionalWeight,
  computeHebbianStrengthening,
  propagateForRelation,
} from '@zensation/algorithms';

// 1. Schedule a memory with the FSRS-style scheduler
const memory = initFromDecayClass('normal_decay');

// 2. A week later, check recall probability (Ebbinghaus curve)
const aWeekLater = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000);
const retention = getRetrievability(memory, aWeekLater);
console.log(`Recall probability: ${(retention * 100).toFixed(1)}%`);
// ~36.8% — retrievability has decayed over the week

// 3. User recalled it anyway — update scheduling
const updated = updateAfterRecall(memory, 4, retention, aWeekLater);
// stability 7 -> 8.19: recalling at low retrievability gives a bigger boost

// 4. Tag emotional significance
const emotion = tagEmotion('I am absolutely thrilled — I got the promotion!');
const weight = computeEmotionalWeight(emotion);
console.log(`Decay multiplier: ${weight.decayMultiplier}x`);
// 2.7x — emotional memories

Sourced from the repository README.

More in Data & Databases