Sandbox
@BennettSchwartz/membrane

Agent memory library and daemon for memory-aware systems

Membrane adds persistent, structured memory to agent workflows. It uses typed records, entity links, retrieval, revision, decay, and access policy so an agent can remember what happened, correct stale facts, and bring back the right context later.

95 stars11 forksGoUpdated 12d ago
Who it's for

Builders who want their agents to carry context across sessions and update knowledge as work changes.

What it delivers

You can give an agent memory that stays useful, editable, and retrieval-aware instead of re-explaining everything each session.

What it does

Typed memory layers

Stores episodic, working, semantic, competence, plan, and entity memories as separate record types.

Revision and retraction

Lets you supersede stale facts, contest claims, fork alternatives, or retract records while keeping audit history.

Decay and consolidation

Changes what is remembered over time based on reinforcement, decay, and consolidation.

Trust and access controls

Applies scope and sensitivity rules so reads and writes follow policy and restricted responses are redacted.

Go library and daemon

Use Membrane as an embedded Go package or as a gRPC service running as `membraned`.

Agent integrations

Includes OpenClaw plugin support and TypeScript and Python SDKs for connecting other agent setups.

README

Membrane logo

Membrane

Memory that agents can connect, revise, and learn from.

Documentation · Quickstart · Architecture · API reference

CI Go Reference License: MIT

Membrane gives LLM agents persistent, structured memory. An agent can remember what happened, connect it to existing knowledge, retrieve the context a task needs, and correct that knowledge when circumstances change.

Use it for agents that carry work across sessions, maintain changing facts, reuse successful procedures, or need to explain which memories informed an answer.

What changes when an agent has memory?

  • Context stays connected. Facts, episodes, procedures, and plans link through shared entities. Retrieval returns a bounded graph of relevant records.
  • Knowledge can be corrected. Supersede stale facts, contest uncertain claims, fork alternatives, or retract a record while retaining its audit history.
  • Experience influences future work. Reinforcement, decay, and consolidation change what gets remembered and retrieved over time.
  • Access follows policy. Scope and sensitivity rules govern reads and writes; restricted responses omit or redact information the caller cannot access.

How it fits together

flowchart LR
    Experience["Events, observations<br/>and task state"] --> Memory["Typed memory<br/>+ entity links"]
    Memory --> Context["Relevant context<br/>within access limits"]
    Context --> Agent["Agent acts"]
    Agent -->|"New evidence and outcomes"| Memory

Five memory layers, connected by entities:

MemoryThe question it answersExample
EpisodicWhat happened?An incident, a tool result, an observation
WorkingWhat are we doing now?The current goal, next action, open questions
SemanticWhat do we know?A preference, a system fact, a relationship
CompetenceWhat has worked before?A debugging procedure and its success history
Plan graphHow should this work unfold?A rollout with dependencies and checkpoints
EntityWhat is this about?The same service, project, file, or person across memories

Explore the memory model →

Choose your integration

Use Membrane from…ConnectionStart here
GoEmbed the library in your processGo guide · Package reference
TypeScript / JavaScriptConnect to the gRPC daemonSDK and examples
PythonConnect to the gRPC daemonSDK and examples
OpenClawAdd memory tools and context through the pluginPlugin setup
Another languageUse the protobuf service contractgRPC API

For a complete agent loop, see the agent harness. It exercises capture, graph retrieval, revisions, and access controls against a running daemon, with both deterministic and optional live-model scenarios.

Run it locally

[!IMPORTANT] PostgreSQL with pgvector is required, whether you embed the Go library or run the daemon. Embedding and LLM providers are optional: structured capture, graph retrieval, revisions, and access controls work without a model API key.

Build and start the daemon — Go, Docker Compose, and Make

Use the Go toolchain declared in go.mod. From a fresh checkout:

git clone https://github.com/BennettSchwartz/membrane.git
cd membrane
make build

export MEMBRANE_POSTGRES_PASSWORD="$(openssl rand -hex 24)"
export MEMBRANE_POSTGRES_DSN="postgres://membrane:${MEMBRANE_POSTGRES_PASSWORD}@127.0.0.1:5432/membrane_test?sslmode=disable"
docker compose up -d
until docker compose exec -T postgres pg_isready -U membrane -d membrane_test; do sleep 1; done
./bin/membraned --postgres-dsn "$MEMBRANE_POSTGRES_DSN"

The daemon applies its database schema on startup and listens on 127.0.0.1:9090. Its default policy permits the default scope at LOW sensitivity. See configuration for scopes, provider settings, TLS, and authentication.

The TypeScript and Python quickstarts connect to this daemon.

Add capabilities as you need them

SetupWhat it enables
PostgreSQL + pgvectorTyped records, entity links, bounded retrieval, revisions, and salience
+ Embedding providerAutomatic vector population and hybrid vector/salience ranking
+ LLM providerOptional interpretation during capture and semantic extraction during consolidation

Full quickstart · Deployment guide · Security guide

Explore the project

I want to…Read
Understand the designArchitecture · Specification
Configure a deploymentConfiguration · Deployment
Understand retrieval and revisionRetrieval · Revision
Inspect behavior and limitationsObservability · Trust and sensitivity
Change the codeContributing · Core packages · Integration and evaluation tests
Development and verification

Go uses the toolchain in go.mod. The TypeScript SDK and examples need Node.js 20.19+, the docs toolchain needs Node.js 22+, and the Python SDK needs Python 3.10+.

CommandWhat it checks
make buildBuild the daemon
make testRun Go tests
make verifyCheck storage/protobuf/package contracts, SDKs, harness tools, and the docs build
make lintRun Go vet and Staticcheck
make agent-harness-deterministicExercise an agent scenario against PostgreSQL

Set disposable PostgreSQL DSNs to include database integration tests. Provider credentials enable live embedding and model evaluations. See CONTRIBUTING.md and the harness guide.

Contributing

Bug reports, integration feedback, and contributions are welcome. Open an issue or read the contribution guide.

MIT licensed. See LICENSE.

Files in the repo

Repository payload33 top-level entries
  • .deepsec
  • .github
  • api
  • clients
  • cmd
  • docs
  • examples
  • internal
  • pkg
  • scripts
  • src
  • static
  • tests
  • tools
  • .assetsignore
  • .coderabbit.yaml
  • .env.example
  • .gitattributes
  • .gitignore
  • CODE_OF_CONDUCT.md
  • CONTRIBUTING.md
  • docker-compose.yml
  • docusaurus.config.js
  • go.mod
  • go.sum
  • LICENSE
  • Makefile
  • package-lock.json
  • package.json
  • README.md
  • rfc.md
  • sidebars.js
  • wrangler.jsonc

Discussion (0)

Ask about usage, or say what you built with it

Sign in to join the discussion.

No comments yet. Be the first to say what this is good for.

More frameworks & sdks

HKUDS/nanobotFrameworks & SDKs

Ultra-lightweight, open-source, self-hosted personal AI agent framework in Python with WebUI, tools, memory, MCP, multi-agent workflows, automation, and chat apps

48k
microsoft/
SkillOpt
microsoft/SkillOptFrameworks & SDKs

SkillOpt is a text-space optimizer that trains reusable natural-language skills for frozen LLM agents through trajectory-driven edits, validation-gated updates, and deployable best_skill.md artifacts.

17k
omnigent-ai/omnigentFrameworks & SDKs

Omnigent is an open-source AI agent framework and meta-harness: orchestrate Claude Code, Codex, Cursor, Pi, and custom agents — swap harnesses without rewriting, enforce policies and sandboxing, and collaborate in real time from any device.

9.8k
kyegomez/
OpenMythos
kyegomez/OpenMythosFrameworks & SDKs

A theoretical reconstruction of the Claude Mythos architecture, built from first principles using the available research literature.

15k
D4Vinci/ScraplingFrameworks & SDKs

🕷️ An adaptive Web Scraping framework that handles everything from a single request to a full-scale crawl!

80k