SuperAPI AI Directory

zenbrain

Seven-layer local agent memory that routes input into facts, episodes or procedures, searches all layers and consolidates repeated episodes into facts.

Open website

About this tool

ZenBrain is a dynamic memory system designed for AI agents, with the core goal of providing LLM agents with persistent memory across sessions. Drawing inspiration from human memory research, it builds a seven-layer memory architecture and comes with a library containing 20 neuroscience-inspired algorithm modules.

Purpose

ZenBrain is designed to solve the problem of AI agents forgetting everything after each conversation. Through layered memory and multiple memory mechanisms, it enables agents to remember information across sessions and simulates the consolidation, forgetting, and retrieval processes of human memory.

Main Capabilities

  • Seven-layer memory architecture: Each layer stores different types of memory and stores and searches in its own way. The specific layers include working memory, episodic memory, semantic memory, procedural memory, etc. (the material mentions seven layers, but does not list all names one by one).
  • MemoryCoordinator: Unifies all layers under one API, responsible for storage, recall, consolidation, and forgetting.
  • FSRS spaced repetition: Each fact receives an FSRS schedule, the application reports reviews via recordReview(), and FSRS sets the next review time.
  • Emotional tagging: Uses a 400+ keyword lexicon (English and German) to assign arousal, valence, and importance scores to memories, and emotional weighting can extend the decay half-life by up to 3 times.
  • Hebbian learning: Frequently co-activated edges in the knowledge graph are strengthened, unused edges decay and are eventually pruned, with homeostatic normalization.
  • Ebbinghaus forgetting curve: Implements personalized decay curves and is compatible with SM-2.
  • Context-dependent retrieval: Captures temporal context and task type, and context matching can bring up to a 30% retrieval improvement.
  • Bayesian confidence propagation: Propagates confidence in the knowledge graph, where supporting evidence increases confidence and contradictions decrease confidence.
  • Sleep consolidation: Simulates sleep replay, selectForReplay() prioritizes emotional and recently accessed memories, simulateReplay() boosts their stability by 50%, and pruneWeakConnections() removes weak Hebbian edges.
  • Advanced algorithm modules: Since v0.3.0, @zensation/algorithms provides 10 advanced algorithms, including fsrs-vmPFC, hebbian-two-factor, sleep-simulation-selection, spectral-health, ib-budget, dopamine-routing, hopfield-stm, personalized-pagerank, surprise-gradient-memory, temporal-multi-route.
  • Zero dependencies: pure TypeScript, dual ESM + CJS, supports tree-shakeable subpath exports.
  • Self-hosted: the library itself makes no network calls, memories are stored in a SQLite or PostgreSQL operated by the user, and the embedding model or LLM is optional.
  • MCP server and Vercel AI SDK middleware: provides integration methods.

Usage

  • Installation: requires Node.js 22 or newer. On Node 20 or older, npm will silently install the last compatible version (@zensation/algorithms@0.3.4, @zensation/core@0.2.2).
  • The core package @zensation/core provides MemoryCoordinator, which handles storage, recall, consolidation, and forgetting.
  • The algorithms library @zensation/algorithms provides tested functions for 20 modules, with each advanced algorithm having an independent subpath (such as @zensation/algorithms/spectral-health).
  • The coordinator only calls some of the algorithms; many mechanisms require users to wire them into their own systems.
  • Seven self-contained examples are provided in the examples/ directory; integration examples require installing the corresponding SDK.
  • A browser live playground is provided, allowing the published code to run without installation.
  • Mechanism comparison script: bash scripts/compare-mechanisms.sh, requires no API key, runs in under a minute, and prints positive and negative controls.

Applicable scenarios

  • AI chatbots that need long-term memory.
  • Knowledge graphs with self-organizing edges.
  • RAG with confidence scoring.
  • Any LLM agent application that needs cross-session memory, memory consolidation, and retrieval augmentation.

Limitations

  • The current version is pre-1.0, and the public API may still change before 1.0.
  • The six in the paper Predictive Memory Architecture (PMA) components are proprietary and are not in the open-source package.
  • The coordinator does not run sleep replay; consolidate() only turns emotionally weighted episodes into facts, one each time.
  • The coordinator does not maintain a knowledge graph; functions such as Hebbian learning need to be applied by users to their own graphs.
  • The coordinator does not store encoding context; the includeContext option never took effect and was withdrawn in 0.5.0.
  • On LoCoMo, the substring-based aggregate F1 metric is by design biased toward lexical retrieval (BM25), and the project does not dispute this.
  • The other ablation tables in the paper require data that this package does not carry (Table 11 requires the LoCoMo corpus, Table 13 requires a different pipeline).
  • Requires Node.js 22 or newer.
  • The embedding model or LLM is optional, but some configurations (such as using nomic-embed-text as the embedding provider) are the configuration used when measuring the benchmark data.

Benchmarks and validation

  • On LongMemEval-500, in a nine-item head-to-head comparison with Letta, Mem0, and A-Mem, three maintained an advantage (all against A-Mem), the remaining six were ties, and there were no losses. It reached 91.3% of the full-context oracle binary judgment accuracy, at 1/109.6 of the latter's token cost per query (47.7% vs. 52.2%).
  • All 822 tests pass, covering Node 22, 24, 26, and PostgreSQL with pgvector.
  • Paper: arXiv 2604.23878; open-access archive: doi.org/10.5281/zenodo.19353663.
  • Reproduction packages: mechanism ablation (10.5281/zenodo.22162063) and measurement package (10.5281/zenodo.22161977).
  • License: paper CC BY 4.0, code Apache-2.0.