nexo-brain

Cognitive co-operator for Claude Code — Atkinson-Shiffrin memory, semantic RAG, trust scoring, and metacognitive error prevention.

NEXO Brain — Your AI Gets a Brain

npm v0.10.0-beta.4 F1 0.588 on LoCoMo +55% vs GPT-4 GitHub stars License: MIT

v0.10.0-beta.4 — Cognitive memory pipeline hardened: quarantine automation, embedding migration fix, smarter STM→LTM promotion, 21% noise reduction from dream insights, zero-decay pinning for corrections, and extended GC windows.

NEXO Brain transforms any MCP-compatible AI agent from a stateless assistant into a cognitive partner that remembers, learns, forgets, adapts, and builds a relationship with you over time.

NEXO Brain Architecture

Watch the 1-minute overview on YouTube · Watch the full deep-dive

Every time you close a session, everything is lost. Your agent doesn't remember yesterday's decisions, repeats the same mistakes, and starts from zero. NEXO Brain fixes this with a cognitive architecture modeled after how human memory actually works.

The Problem

AI coding agents are powerful but amnesic:

  • No memory — closes a session, forgets everything
  • Repeats mistakes — makes the same error you corrected yesterday
  • No context — can't connect today's work with last week's decisions
  • Reactive — waits for instructions instead of anticipating needs
  • No learning — doesn't improve from experience
  • No safety — stores anything it's told, including poisoned or redundant data

The Solution: A Cognitive Architecture

NEXO Brain implements the Atkinson-Shiffrin memory model from cognitive psychology (1968) — the same model that explains how human memory works:

What you say and do
    |
    +---> Sensory Register (raw capture, 48h)
    |       |
    |       +---> Attention filter: "Is this worth remembering?"
    |               |
    |               v
    +---> Short-Term Memory (7-day half-life)
    |       |
    |       +---> Used often? --> Consolidate to Long-Term Memory
    |       +---> Not accessed? --> Gradually forgotten
    |
    +---> Long-Term Memory (60-day half-life)
            |
            +---> Active: instantly searchable by meaning
            +---> Dormant: faded but recoverable ("oh right, I remember now!")
            +---> Near-duplicates auto-merged to prevent clutter

This isn't a metaphor. NEXO Brain literally implements Ebbinghaus forgetting curves, rehearsal-based reinforcement, and memory consolidation during automated "sleep" processes.

What Makes NEXO Brain Different

Without NEXO BrainWith NEXO Brain
Memory gone after each sessionPersistent across sessions with natural decay and reinforcement
Repeats the same mistakesChecks "have I made this mistake before?" before every action
Keyword search onlyFinds memories by meaning, not just words
Starts cold every timeResumes from the mental state of the last session
Same behavior regardless of contextAdapts tone and approach based on your mood
No relationshipTrust score that evolves — makes fewer redundant checks as alignment grows
Stores everything blindlyPrediction error gating rejects redundant information at write time
Vulnerable to memory poisoning4-layer security pipeline scans every memory before storage
No proactive behaviorContext-triggered reminders fire when topics match, not just by date

How the Brain Works

Memory That Forgets (And That's a Feature)

NEXO Brain uses Ebbinghaus forgetting curves — memories naturally fade over time unless reinforced by use. This isn't a bug, it's how useful memory works:

  • A lesson learned yesterday is strong. If you never encounter it again, it fades — because it probably wasn't important.
  • A lesson accessed 5 times in 2 weeks gets promoted to long-term memory — because repeated use proves it matters.
  • A dormant memory can be reactivated if something similar comes up — the "oh wait, I remember this" moment.

Semantic Search (Finding by Meaning)

NEXO Brain doesn't search by keywords. It searches by meaning using vector embeddings (fastembed, 768 dimensions).

Example: If you search for "deploy problems", NEXO Brain will find a memory about "SSH connection timeout on production server" — even though they share zero words. This is how human associative memory works.

Metacognition (Thinking About Thinking)

Before every code change, NEXO Brain asks itself: "Have I made a mistake like this before?"

It searches its memory for related errors, warnings, and lessons learned. If it finds something relevant, it surfaces the warning BEFORE acting — not after you've already broken production.

Cognitive Dissonance

When you give an instruction that contradicts established knowledge, NEXO Brain doesn't silently obey or silently resist. It verbalizes the conflict:

"My memory says you prefer Tailwind over plain CSS, but you're asking me to write inline styles. Is this a permanent change or a one-time exception?"

You decide: paradigm shift (permanent change), exception (one-time), or override (old memory was wrong).

Sibling Memories

Some memories look identical but apply to different contexts. "How to deploy" for Project A is different from Project B. NEXO Brain detects discriminating entities (different OS, platform, language) and links them as siblings instead of merging them:

"Applying the Linux deploy procedure. Note: there's a sibling for macOS that uses a different port."

Trust Score (0-100)

NEXO Brain tracks alignment with you through a trust score:

  • You say thanks --> score goes up --> reduces redundant verification checks
  • Makes a mistake you already taught it --> score drops --> becomes more careful, checks more thoroughly
  • The score doesn't control permissions — you're always in control. It's a mirror that helps calibrate rigor.

Sentiment Detection

NEXO Brain reads your tone (keywords, message length, urgency signals) and adapts:

  • Frustrated? --> Ultra-concise mode. Zero explanations. Just solve the problem.
  • In flow? --> Good moment to suggest that backlog item from last Tuesday.
  • Urgent? --> Immediate action, no preamble.

Sleep Cycle

Like a human brain, NEXO Brain has automated processes that run while you're not using it:

TimeProcessHuman Analogy
03:00Decay + memory consolidation + merge duplicates + dreamingDeep sleep consolidation
04:00Clean expired data, prune redundant memoriesSynaptic pruning
07:00Self-audit, health checks, metricsWaking up + orientation
23:30Process day's events, extract patternsPre-sleep reflection
BootCatch-up: run anything missed while computer was off--

If your Mac was asleep during any scheduled process, NEXO Brain catches up in order when it wakes.

Cognitive Features

NEXO Brain provides 25 cognitive tools on top of the 76 base tools, totaling 109+ MCP tools. These features implement cognitive science concepts that go beyond basic memory:

Input Pipeline

FeatureWhat It Does
Prediction Error GatingOnly novel information is stored. Redundant content that matches existing memories is rejected at write time, keeping your memory clean without manual curation.
Security Pipeline4-layer defense against memory poisoning: injection detection, encoding analysis, behavioral anomaly scoring, and credential scanning. Every memory passes through all four layers before storage.
Quarantine QueueNew facts enter quarantine status and must pass a promotion policy before becoming trusted knowledge. Prevents unverified information from influencing decisions.
Secret RedactionAuto-detects and redacts API keys, tokens, passwords, and other sensitive data before storage. Secrets never reach the vector database.

Memory Management

FeatureWhat It Does
Pin / Snooze / ArchiveGranular lifecycle states for memories. Pin = never decays (critical knowledge). Snooze = temporarily hidden (revisit later). Archive = cold storage (searchable but inactive).
Intelligent ChunkingAdaptive chunking that respects sentence and paragraph boundaries. Produces semantically coherent chunks instead of arbitrary token splits, reducing retrieval noise.
Adaptive DecayDecay rate adapts per memory based on access patterns: frequently-accessed memories decay slower, rarely-accessed ones fade faster. Prevents permanent clutter while keeping active knowledge sharp.
Auto-MigrationFormal schema migration system (schema_migrations table) tracks all database changes. Safe, reversible schema evolution for production systems — upgrades never lose data.
Auto-Merge DuplicatesBatch cosine deduplication during the 03:00 sleep cycle. Respects sibling discrimination — similar memories about different contexts are kept separate.
Memory DreamingDiscovers hidden connections between recent memories during the 03:00 sleep cycle. Surfaces non-obvious patterns like "these three bugs all relate to the same root cause."

Retrieval

FeatureWhat It Does
HyDE Query ExpansionGenerates hypothetical answer embeddings for richer semantic search. Instead of searching for "deploy error", it imagines what a helpful memory about deploy errors would look like, then searches for that.
Hybrid Search (FTS5+BM25+RRF)Combines dense vector search with BM25 keyword search via Reciprocal Rank Fusion. Outperforms pure semantic search on precise terminology and code identifiers.
Cross-Encoder RerankingAfter initial vector retrieval, a cross-encoder model rescores candidates for precision. The top-k results are reordered by true semantic relevance before being returned to the agent.
Multi-Query DecompositionComplex questions are automatically split into sub-queries. Each component is retrieved independently, then fused for a higher-quality answer — improves recall on multi-faceted prompts.
Temporal IndexingMemories are indexed by time in addition to semantics. Time-sensitive queries ("what did we decide last Tuesday?") use temporal proximity scoring alongside semantic similarity.
Spreading ActivationGraph-based co-activation network. Memories retrieved together reinforce each other's connections, building an associative web that improves over time.
Recall ExplanationsTransparent score breakdown for every retrieval result. Shows exactly why a memory was returned: semantic similarity, recency, access frequency, and co-activation bonuses.

Proactive

FeatureWhat It Does
Prospective MemoryContext-triggered reminders that fire when conversation topics match, not just by date. "Remind me about X when we discuss Y" works naturally.
Hook Auto-captureExtracts decisions, corrections, and factual statements from conversations automatically. You don't need to explicitly say "remember this" — the system detects what's worth storing.
Session SummariesAutomatic end-of-session summarization that distills key decisions, errors, and follow-ups into a compact diary entry. The next session starts with full context — not a cold slate.

Benchmark: LoCoMo (ACL 2024)

NEXO Brain was evaluated on LoCoMo (ACL 2024), a long-term conversation memory benchmark with 1,986 questions across 10 multi-session conversations.

SystemF1AdversarialHardware
NEXO Brain v0.5.00.58893.3%CPU only
GPT-4 (128K full context)0.379GPU cloud
Gemini Pro 1.00.313GPU cloud
LLaMA-3 70B0.295A100 GPU
GPT-3.5 + Contriever RAG0.283GPU

+55% vs GPT-4. Running entirely on CPU.

Key findings:

  • Outperforms GPT-4 (128K full context) by 55% on F1 score
  • 93.3% adversarial rejection rate — reliably says "I don't know" when information isn't available
  • 74.9% recall across 1,986 questions
  • Open-domain F1: 0.637 | Multi-hop F1: 0.333 | Temporal F1: 0.326
  • Runs on CPU with 768-dim embeddings (BAAI/bge-base-en-v1.5) — no GPU required
  • First MCP memory server benchmarked on a peer-reviewed dataset

Full results in benchmarks/locomo/results/.

Full Orchestration System (v0.7.0)

Memory alone doesn't make a co-operator. What makes the difference is the behavioral loop — the automated discipline that ensures every session starts informed, runs with guardrails, and ends with self-reflection.

5 Automated Hooks

These fire automatically at key moments in every Claude Code session:

HookWhenWhat It Does
SessionStartSession opensGenerates a briefing from SQLite: overdue reminders, today's tasks, pending followups, active sessions
StopSession endsMandatory post-mortem: self-critique (5 questions), session buffer entry, followup creation, proactive seeds for next session
PostToolUseAfter each tool callCaptures meaningful mutations to the Sensory Register
PreCompactBefore context compressionSaves checkpoint, reminds operator to write diary — prevents losing the thread
CaffeinateAlways (optional)Keeps Mac awake for nocturnal cognitive processes

The Session Lifecycle

Session starts
    ↓
SessionStart hook generates briefing
    ↓
Operator reads diary, reminders, followups
    ↓
Heartbeat on every interaction (sentiment, context shifts)
    ↓
Guard check before every code edit
    ↓
PreCompact hook saves context if conversation is compressed
    ↓
Stop hook triggers mandatory post-mortem:
  - Self-critique: 5 questions about what could be better
  - Session buffer: structured entry for the reflection engine
  - Followups: anything promised gets scheduled
  - Proactive seeds: what can the next session do without being asked?
    ↓
Reflection engine processes buffer (after 3+ sessions)
    ↓
Nocturnal processes: decay, consolidation, self-audit, dreaming

Reflection Engine

After 3+ sessions accumulate, the stop hook triggers nexo-reflection.py:

  • Extracts recurring tasks, error patterns, mood trends
  • Updates user_model.json with observed behavior
  • No LLM required — runs as pure Python

Auto-Migration

Existing users upgrading from v0.5.0:

npx nexo-brain  # detects v0.5.0, migrates automatically
  • Updates hooks, core files, plugins, scripts
  • Never touches your data (memories, learnings, preferences)
  • Saves updated CLAUDE.md as reference (doesn't overwrite customizations)

Knowledge Graph & Dashboard (v0.8)

Knowledge Graph

A bi-temporal entity-relationship graph with 988 nodes and 896 edges. Entities and relationships carry both valid-time (when the fact was true) and system-time (when it was recorded), enabling temporal queries like "what did we know about X last Tuesday?". BFS traversal discovers multi-hop connections between concepts. Event-sourced edges with smart dedup (ADD/UPDATE/NOOP) prevent redundant writes while preserving full history.

4 new MCP tools: nexo_kg_query (SPARQL-like queries), nexo_kg_path (shortest path between entities), nexo_kg_neighbors (direct connections), nexo_kg_stats (graph metrics).

Web Dashboard

A visual interface at localhost:6174 with 6 pages: Overview (system health at a glance), Graph (interactive D3.js visualization of the knowledge graph), Memory (browse and search all memory stores), Somatic (pain map per file/area), Adaptive (personality signals and weights), and Sessions (active and historical sessions). Built with FastAPI backend and D3.js frontend.

Cross-Platform Support

Full Linux support and Windows via WSL. The installer detects the platform and configures the appropriate process manager (LaunchAgents on macOS, catch-up on startup for Linux). PEP 668 compliance (venv on Ubuntu 24.04+). Session keepalive prevents phantom sessions during long tasks. Opportunistic maintenance runs cognitive processes when resources are available.

Windows users: NEXO Brain requires WSL (Windows Subsystem for Linux). Install WSL first, then run npx nexo-brain inside the Ubuntu/WSL terminal.

Storage Router

A new abstraction layer routes storage operations through a unified interface, making the system multi-tenant ready. Each operator's data is isolated while sharing the same cognitive engine.

Learned Weights & Somatic Markers (v0.7.0)

Adaptive Learned Weights

Signal weights learn from real user feedback via Ridge regression. A 2-week shadow mode observes before activating. Weight momentum (85/15 blend) prevents personality whiplash. Automatic rollback if correction rate doubles.

Somatic Markers (Pain Memory)

Files and areas that cause repeated errors accumulate a risk score (0.0–1.0). The guard system warns on HIGH RISK (>0.5) and CRITICAL RISK (>0.8), lowering thresholds for more paranoid checking. Clean guard checks reduce risk multiplicatively (×0.7). Nightly decay (×0.95) ensures old pain fades.

Adaptive Personality v2

6 weighted signals: vibe, corrections, brevity, topic, tool errors, git diff. Emergency keywords bypass hysteresis. Severity-weighted decay. Manual override via nexo_adaptive_override.

Quick Start

Claude Code (Primary)

npx nexo-brain

The installer handles everything:

  How should I call myself? (default: NEXO) > Atlas

  Can I explore your workspace to learn about your projects? (y/n) > y

  Keep Mac awake so my cognitive processes run on schedule? (y/n) > y

  Installing cognitive engine dependencies...
  Setting up NEXO home...
  Scanning workspace...
    - 3 git repositories
    - Node.js project detected
  Configuring MCP server...
  Setting up automated processes...
    5 automated processes configured.
  Caffeinate enabled.
  Generating operator instructions...

  +----------------------------------------------------------+
  |  Atlas is ready. Type 'atlas' to start.                  |
  +----------------------------------------------------------+

Starting a Session

The installer creates a shell alias with your chosen name. Just type it:

atlas

That's it. No need to run claude manually. Atlas will greet you immediately — adapted to the time of day, resuming from where you left off if there's a previous session. No cold starts, no waiting for your input.

What Gets Installed

ComponentWhatWhere
Cognitive enginePython: fastembed, numpy, vector searchpip packages
MCP server109+ tools for memory, cognition, learning, guard~/.nexo/
PluginsGuard, episodic memory, cognitive memory, entities, preferences~/.nexo/plugins/
Hooks (5)SessionStart briefing, Stop post-mortem, PostToolUse capture, PreCompact checkpoint, Caffeinate~/.nexo/hooks/
Reflection engineProcesses session buffer, extracts patterns, updates user model~/.nexo/scripts/
CLAUDE.mdComplete operator instructions (Codex, hooks, guard, trust, memory)~/.claude/CLAUDE.md
LaunchAgentsDecay, sleep, audit, postmortem, catch-up~/Library/LaunchAgents/
Auto-updateChecks for new versions at bootBuilt into catch-up
Claude Code configMCP server + 5 hooks registered~/.claude/settings.json

Requirements

  • macOS or Linux (Windows via WSL)
  • Node.js 18+ (for the installer)
  • Claude Opus (latest version) strongly recommended. NEXO Brain provides 109+ MCP tools across 19 categories. This cognitive load requires a top-tier model with large context window. Smaller models (Haiku, Sonnet) may struggle with tool selection and produce inconsistent results. Opus handles all 109+ tools without hesitation.
  • Python 3, Homebrew, and Claude Code are installed automatically if missing.

Architecture

109+ MCP Tools across 19 Categories

CategoryCountToolsPurpose
Cognitive8retrieve, stats, inspect, metrics, dissonance, resolve, sentiment, trustThe brain — memory, RAG, trust, mood
Cognitive Input5prediction_gate, security_scan, quarantine, promote, redactInput pipeline — gating, security, quarantine
Cognitive Advanced8hyde_search, spread_activate, explain_recall, dream, prospect, hook_capture, pin, archiveAdvanced retrieval, proactive, lifecycle
Guard3check, stats, log_repetitionMetacognitive error prevention
Episodic10change_log/search/commit, decision_log/outcome/search, review_queue, diary_write/read, recallWhat happened and why
Sessions4startup, heartbeat, stop, statusSession lifecycle + context shift detection
Coordination7track, untrack, files, send, ask, answer, check_answerMulti-session file coordination + messaging
Reminders5list, create, update, complete, deleteUser's tasks and deadlines
Followups4create, update, complete, deleteSystem's autonomous verification tasks
Learnings5add, search, update, delete, listError patterns and prevention rules
Credentials5create, get, update, delete, listSecure local credential storage
Task History3log, list, frequencyExecution tracking and overdue alerts
Menu1menuOperations center with box-drawing UI
Entities5search, create, update, delete, listPeople, services, URLs
Preferences4get, set, list, deleteObserved user preferences
Agents5get, create, update, delete, listAgent delegation registry
Backup3now, list, restoreSQLite data safety
Evolution5propose, approve, reject, status, historySelf-improvement proposals
Adaptive & Somatic4adaptive_weights, adaptive_override, somatic_check, somatic_statsLearned signal weights + pain memory per file
Knowledge Graph4kg_query, kg_path, kg_neighbors, kg_statsBi-temporal entity-relationship graph

Plugin System

NEXO Brain supports hot-loadable plugins. Drop a .py file in ~/.nexo/plugins/:

# my_plugin.py
def handle_my_tool(query: str) -> str:
    """My custom tool description."""
    return f"Result for {query}"

TOOLS = [
    (handle_my_tool, "nexo_my_tool", "Short description"),
]

Reload without restarting: nexo_plugin_load("my_plugin.py")

Data Privacy

  • Everything stays local. All data in ~/.nexo/, never uploaded anywhere.
  • No telemetry. No analytics. No phone-home.
  • No cloud dependencies. Vector search runs on CPU (fastembed), not an API.
  • Auto-update is opt-in. Checks GitHub releases, never sends data.
  • Secret redaction. API keys and tokens are stripped before they ever reach memory storage.

The Psychology Behind NEXO Brain

NEXO Brain isn't just engineering — it's applied cognitive psychology:

Psychological ConceptHow NEXO Brain Implements It
Atkinson-Shiffrin (1968)Three memory stores: sensory register --> STM --> LTM
Ebbinghaus Forgetting Curve (1885)Exponential decay: strength = strength * e^(-lambda * time)
Rehearsal EffectAccessing a memory resets its strength to 1.0
Memory ConsolidationNightly process promotes frequently-used STM to LTM
Prediction ErrorOnly surprising (novel) information gets stored — redundant input is gated
Spreading Activation (Collins & Loftus, 1975)Retrieving a memory co-activates related memories through an associative graph
HyDE (Gao et al., 2022)Hypothetical document embeddings improve semantic recall
Prospective Memory (Einstein & McDaniel, 1990)Context-triggered intentions fire when cue conditions match
MetacognitionGuard system checks past errors before acting
Cognitive Dissonance (Festinger, 1957)Detects and verbalizes conflicts between old and new knowledge
Theory of MindModels user behavior, preferences, and mood
Synaptic PruningAutomated cleanup of weak, unused memories
Associative MemorySemantic search finds related concepts, not just matching words
Memory ReconsolidationDreaming process discovers hidden connections during sleep

Integrations

Claude Code (Primary)

NEXO Brain is designed as an MCP server. Claude Code is the primary supported client:

npx nexo-brain

All 109+ tools are available immediately after installation. The installer configures Claude Code's ~/.claude/settings.json automatically.

OpenClaw

NEXO Brain also works as a cognitive memory backend for OpenClaw:

MCP Bridge (Zero Code)

Add NEXO Brain to your OpenClaw config at ~/.openclaw/openclaw.json:

{
  "mcp": {
    "servers": {
      "nexo-brain": {
        "command": "python3",
        "args": ["~/.nexo/src/server.py"],
        "env": {
          "NEXO_HOME": "~/.nexo"
        }
      }
    }
  }
}

Or via CLI:

openclaw mcp set nexo-brain '{"command":"python3","args":["~/.nexo/src/server.py"],"env":{"NEXO_HOME":"~/.nexo"}}'
openclaw gateway restart

ClawHub Skill

npx clawhub@latest install nexo-brain

Native Memory Plugin

npm install @wazionapps/openclaw-memory-nexo-brain
{
  "plugins": {
    "slots": {
      "memory": "memory-nexo-brain"
    }
  }
}

This replaces OpenClaw's default memory system with NEXO Brain's full cognitive architecture.

Any MCP Client

NEXO Brain works with any application that supports the MCP protocol. Configure it as an MCP server pointing to ~/.nexo/src/server.py.

Listed On

DirectoryTypeLink
npmPackagenexo-brain
GlamaMCP Directoryglama.ai
mcp.soMCP Directorymcp.so
mcpservers.orgMCP Directorymcpservers.org
OpenClawNative Pluginopenclaw.com
dev.toTechnical ArticleHow I Applied Cognitive Psychology to AI Agents
nexo-brain.comOfficial Websitenexo-brain.com

Inspired By

NEXO Brain builds on ideas from several open-source projects. We're grateful for the research and implementations that inspired specific features:

ProjectInspired Features
VestigeHyDE query expansion, spreading activation, prediction error gating, memory dreaming, prospective memory
ShieldCortexSecurity pipeline (4-layer memory poisoning defense)
BicameralQuarantine queue (trust promotion policy for new facts)
claude-memHook auto-capture (extracting decisions and facts from conversations)
ClawMemCo-activation reinforcement (memories retrieved together strengthen connections)

Support the Project

If NEXO Brain is useful to you, consider:

  • Star this repo — it helps others discover the project and motivates continued development
  • Sponsor on GitHub — support ongoing development directly
  • Share your experience — tell others how you're using cognitive memory in your AI workflows
  • Contribute — see CONTRIBUTING.md for guidelines. Issues and PRs welcome

Star History Chart

License

MIT -- see LICENSE


Created by Francisco Cerdà Puigserver & NEXO (Claude Opus) · Built by WAzion

Похожие серверы