[email protected]
Portfolio / open-brain

Open Brain

Open source under the MIT licence. View the source

Agent memory served as an MCP server on PostgreSQL with pgvector, using hybrid vector plus full-text retrieval.

Open Brain

The problem

Coding agents forget everything between sessions. Open Brain is the one place several agents (Claude Code, Codex, chat bots) write to and read from, with scoped identity, a published tool contract, and a grading step so nothing becomes durable memory on its own.

How it works

A Node 24 / TypeScript / Express server stores thoughts, decisions, session events, repo facts and contacts in PostgreSQL with pgvector and serves them through versioned MCP tools. Retrieval fuses vector similarity and full-text with reciprocal rank fusion. Every caller has a bearer token mapped to a role, memory lives in namespaces, and a context pack returns only items whose agent, platform, channel and session scope match exactly. Captured conversation turns are distilled into candidates that become memory only after a human grades them or an explicit promotion rule fires.

How Open Brain works

Features

  • Hybrid retrieval: vector similarity plus full-text fused with reciprocal rank fusion
  • Scope and identity: bearer token per caller mapped to a role (admin, agent, readonly, promoter), namespace isolation, exact-match scope on context packs
  • get_contract publishes the tool surface, input schemas and a schema hash so clients negotiate instead of hard-coding tool names
  • Candidate grading: captured turns are distilled into candidates and promoted only after grading or an explicit rule
  • Python client library and CLI, Claude Code / Codex session-capture hooks, and a TypeScript client
  • Optional NATS request/reply transport, DREAM distillation stages, backup and restore scripts

How it was built

Open Brain started on 2026-03-13 to give AI coding agents a shared memory across sessions and machines, so each new session stopped relearning the same decisions.

Everything went into Postgres: entries, embeddings, full-text search, the entity graph and the session journal. That kept backups, transactions and restore drills covering one system.

Agents capture freely into their own lane, and promotion into shared memory goes through a reviewer with receipts. After captures were lost without notice, failed captures became visible in the health check and in the agent's turn.

Tests against a shared development database failed 37 to 41 tests on unchanged code, so an isolated per-run database became the default. On 2026-07-27 three merged changes were reverted because one rested on an unverified claim about a retired database host.

AI coding agents built it across 668 commits, and every v1 phase was reviewed by an agent review swarm before it closed. Rico directed the work and required each acceptance claim to be a script with a fixed exit code.