Membrane: a local-first memory field and seat for AI -- its own web UI (`membrane standalone`) or inside Home Assistant (HACS).
pip install membrane-seat==0.6.3 Copy PIP instructions
Complementary Learning Systems (McClelland, McNaughton & O'Reilly, 1995)
A living entity-field memory for a resident AI seat — hypervectors with a readable geometry, a background mind that works while you're away, every write guarded and audited, shared across seats by construction. Local-first; it runs in front of Ollama (or inside Home Assistant).
A Python lab. It runs as a local HTTP server on 127.0.0.1 — technically a proxy, but that is the mechanism, not the point. The point is the field.
Why that name? The project began as one question — how do you measure "variety" for a memory that decides absorb-a-cached-answer vs escalate-to-the-model? — and the answer is what makes the memory above possible and is why it is called membrane: a selective, active boundary between lived memory (the inside) and the incoming world (the outside) that absorbs what it has the variety for and escalates the rest. The measured underpinnings are in The math findings.
Most memory projects give your agent a store to query. Membrane is built on different ground rules: a non-von-Neumann architecture running on top of a von-Neumann machine — no central fetch-execute CPU; computation is distributed across the field itself and driven by a minimal register-correct-predict-act loop that registers new data, compares it against prediction and uses surprise as signal that adjusts stored memory and makes a new prediction.
The field is not cosine-over-pasted-summaries. It is an entity field over hypervectors with a geometry you can read and measure: entities with positions and states, relations between them, tiers of life (nursery → live → dormant), effective rank, free energy, a conflict fraction. membrane state prints the geometry of a running field; experiments/variety_toy.py shows in one command why a low-variety store reads its outliers as novel and a high-variety store doesn't (the absorb-vs-escalate decision is measured, not vibes); docs/math-findings.md carries the experiments.
You don't bolt it onto an app — the memory is the resident process: its own REST/SSE serve surface, its own chat UI, voice, the Home Assistant integration. The turn loop runs inside the seat, so every client's turn goes through the same field path; conversation transcript and memory are the same store, not two systems reconciling each other (see membrane serve, below). While nobody is talking, a background mind keeps working the field — a thinker digesting event streams, a dreamer consolidating at night, watchers, entity scripts — and its minds are visible as live agents at GET /agent (counters served fresh from the running process, nothing cached, nothing faked). The repo dogfoods it: its own field holds ~14k live entities and learned the codebase while it was written.
No schema to define, no tags to assign, no knowledge graph to hand-build. Entities are born when experience names them, their states move as the world speaks, relations and claims accumulate, symbols crystallize through language (docs/symbol-birth.md). When two seats assert opposite things about the same entity, the divergence is surfaced, never silently overwritten — nothing in a teammate's field is destroyed by yours.
A memory that lets the model whisper to itself unsupervised drifts into self-flattery. Membrane's writes run the same guards a turn runs: dedup, variety gate, length limits, fenced-code refusal, junk cut — every write audited with its origin (agent / mcp / night / operator) in audit.jsonl, and every claim traces back to the events that earned it. A dedicated lane replays earlier gate-verdicts against what the model actually answered and judges agreement — shadow by default (--replay-ab P=0: recorded, never bypassing you), measured at 0.77 mean similarity on a live seat (docs/ab-critic-scorecard.md faces the six criticisms honestly).
Every event, state, relation and claim is namespaced by the seat (origin) that wrote it — writes are disjoint, reads are merged, so one team bucket is collision-free by construction: a foreign entity's effective state is the seed plus the mass-weighted mean of every seat's displacement, cross-seat agreement is promoted into the commons at night, and disputed claims get marked disputed, not overwritten. Live peer asks (LAN/VPN, bounded fan-out) let a seat consult a sibling's field mid-turn. The mechanics: docs/multi-dev-field.md; the team process: docs/shared-field-workflow.md.
No SaaS, no account, no telemetry, no cloud round-trip required: chat and embeddings run on your Ollama (cloud models are routable rungs you add with membrane auth); the substrate is your Couchbase bucket — and with no cluster reachable the seat drops to a RAM field and still boots (degradation, never failure). The whole field is a substrate you own and can move (membrane move / python -m membrane.reembed). The memory is for your data: the PolyForm Noncommercial license covers personal, hobby, research and other noncommercial use and keeps it out of paid products (LICENSE).
Membrane runs three ways: standalone, in Docker, or inside Home Assistant. All need an Ollama server with one chat model and one embedding model (ollama pull qwen3:8b && ollama pull mxbai-embed-large, or any cloud model Ollama serves), and 1–3 GB of RAM for the seat.
pip install membrane-seat # or: uv tool install membrane-seat mkdir ~/bob && cd ~/bob membrane standalone # opens http://localhost:4096/ in your browser You get membrane home: the field in 3D, the chat, and voice ("Hey Bob" — a new membrane is Bob until you agree on a name together; it will ask). Other devices on your network reach it at http:// :4096/. No login on the local network; a public or proxied caller is refused — unless you turn on the optional JWT mode (docs/auth.md): then every caller needs a token, from the LAN or behind an ingress alike. Voice needs a secure origin, so the microphone works on localhost (the first voice use downloads ~65 MB of speech models, checked against their checksums).
docker run -d --name membrane \ -p 4096:4096 -p 11500:11500 \ -v membrane-data:/data \ -e MEMBRANE_BACKEND=http://host.docker.internal:11434 \ -e MEMBRANE_EMBED_MODEL=mxbai-embed-large \ --stop-timeout 60 \ chedim/membrane:latest # then open http://localhost:4096/ The same standalone seat in a container: the web UI on :4096 and the OpenAI-compatible proxy on :11500, the memory on the membrane-data volume. MEMBRANE_BACKEND is the Ollama server (the default shown is the Docker host); on Linux add --add-host=host.docker.internal:host-gateway. The ports have no login unless you set MEMBRANE_JWT_SECRET (JWT mode); without it, publish them only on a network you trust. Details: docs/docker.md.
Home Assistant then runs the seat as its own child process (started and stopped with HA, restarted if it dies; its data in /membrane/), opens on membrane home for everyone (HA's sidebar folds away; ☰ leads to HA's own pages — switch it off in the integration's options), adds the seat as an Assist conversation agent, and its field's readings as sensors.
What it can do in your house: by default the seat may use Home Assistant through a hidden, non-admin, local-only user ("Membrane") — read any state, call any service, and mirror the entities it chooses (they update live). It acts on what people ask, but its commands are written by a model: turn Let the seat use Home Assistant off in the integration's options if you'd rather it only talks. It can't change Home Assistant's configuration or users.
Connect to a seat running elsewhere is for a seat on another machine (the integration is then only its UI and agent).
A seat hands its model the membrane MCP surface — query, state, learn, forget, the entity-hand tools (entity_add/edit/remove/link/inherit, entity_query, entity_tracks, entities_related …), intend, peer_post, graph. Commands compose in Cliffhanger, membrane's command language — specified and documented in its own repo (github.com/chedim/cliffhanger, with membrane's instantiation in docs/cliffhanger.md). The model reads the field with query/state, files an earned lesson with learn (same guards as any turn), cleans its own mistakes with forget — writes are audited with their origin. Meanwhile the ambient layer needs no command at all: every turn the model sees what the field holds about the entities it names, and on later turns only the diff — which entity states moved since the last message it processed, whether the change came from conversation, code, other seats or entity scripts. Two safety lanes run on every turn and stay advisory: the gate replays the nearest past ask against the live answer (A/B, shadow by default), and the [membrane] monologue in the thinking channel shows the gate verdict, field vitals and the per-turn memory flow (/monologue toggles it).
Idle background loops run on a LOCAL, cheaper model by default (--idle-cortex-model) so a stuck background seat can never burn cloud tokens. Token economics and routing: docs/token-economics.md.
github.com/chedim/membrane/issues — your membrane knows this too: when it finds a bug in itself it drafts the issue and hands you the link to file.
curl -fsSL https://raw.githubusercontent.com/chedim/membrane/main/install.sh | bash Installs the membrane CLI globally, user-local (~/.local/bin): uv tool install if you have uv, otherwise a managed venv at ~/.membrane/venv + a symlink on your PATH. Re-running it is safe (upgrade in place). To install from a local checkout instead (e.g. while hacking on membrane):
MEMBRANE_REPO=/path/to/membrane bash install.sh Dependencies, honestly:
docker run -d -p 4096:4096 -p 11500:11500 -v membrane-data:/data \ -e MEMBRANE_EMBED_MODEL=mxbai-embed-large --stop-timeout 60 \ chedim/membrane:latest The public image chedim/membrane (amd64 + arm64, pushed on every release) runs membrane standalone: the web UI and serve API on :4096, the OpenAI-compatible proxy on :11500, Ollama reached at http://host.docker.internal:11434 by default (on Linux add --add-host=host.docker.internal:host-gateway). The field lives on the /data volume. The ports carry no authentication: publish them only on a network you trust. Recipes, env and volume details: docs/docker.md.
cd ~/projects/my-app membrane opencode On first run in a directory it bootstraps that project: auto-installs the agent skills into .opencode/skills/ there (project-scoped on purpose), opens an entity field namespaced by the project's origin, and backfills what it can without cost (the codegraph; with membrane backfill, the project's history). If no memory sharing is configured it offers (once, interactive shell only) to connect a Couchbase cluster — decline and it stays a private local field.
It starts the OpenAI-compatible proxy on :11500 (backend Ollama at http://localhost:11434, override --backend/--model) and opens the opencode TUI attached to membrane's own serve surface: sessions, turns, tool parts and their history live in membrane's stores beside the field — the TUI is a thin client. Every turn is captured into the field (discourse and observations as events), entities move as the conversation names them, and the model is grounded by what those entities hold — docs/entity-field.md is the design doc.
The proxy speaks both APIs through the same memory turn: OpenAI's /v1/chat/completions and Ollama's native /api/chat and /api/generate (translated to the OpenAI body on the way in and back to Ollama's JSON or NDJSON on the way out — gate, injection, capture and routing are the same code). Every other /api/* path (/api/tags, /api/show, /api/embed, /api/pull, …) and a model load/unload request (no prompt, no messages) pass through to Ollama unchanged.
MEMBRANE_EFIELD selects the field's mode: on (the default: capture, embed, apply), shadow (capture events only — a lab ablation), off.
membrane serve runs the seat with no TUI and no opencode at all — sessions, messages, turns, tool parts, aborts, the SSE event stream, served by membrane itself on :4096 (no login of its own by default: keep it on your network, put a reverse proxy with its own login in front, or turn on the optional JWT mode — a token on every request to both ports, docs/auth.md). Any opencode client connects unchanged: the mobile companion app, IDE plugins, a script. The turn loop calls the seat's OWN /v1 on loopback — gate, injection, capture and routing run through the exact code path every other client's turn uses, so the serve surface adds no separate memory, and the model's tool invocations appear to the client as ordinary tool parts riding message.part.updated (pending → completed), so you can watch what it's doing from the room. --serve-port (default 4096, walks up if busy) and --listen (the proxy, default 11500) are independent. The proxy binds all interfaces by default and its write/exec routes carry no auth; --listen-host 127.0.0.1 (or MEMBRANE_LISTEN_HOST=127.0.0.1) keeps it on this machine. Exposure is LAN-only by design: reach the server only from a network you own — or set MEMBRANE_JWT_SECRET and hand each client a token (docs/auth.md).
Point every seat at the same Couchbase bucket: one bucket per team, the membrane scope, the nine entity-field collections (events, sentences, terms, entity_states, entity_deltas, relations, claims, annotations, origin_stats), created and indexed on first boot. Projects distinguish themselves by the origin axis — a seat writes ONLY rows keyed by its own origin; do NOT add per-project buckets (that would defeat cross-seat agreement).
membrane connect # conn string, user, password (hidden), bucket The same offer appears automatically on the first run in a project with no store configured (interactive shell only; declining is remembered). Secrets never touch the repo — credentials are stored per-project OUTSIDE it, at ~/.membrane/projects/ .env (mode 600), and a .env inside the repo is designed-out of the failure mode. Plain env config still works:
export MEMBRANE_STORE=couchbase export COUCHBASE_CONN_STRING=couchbase:// export COUCHBASE_USER=... COUCHBASE_PASSWORD=... COUCHBASE_BUCKET=membrane A local cluster answering at the default endpoint is auto-detected at boot; an unreachable cluster transparently falls back to the RAM field. What sharing guarantees — disjoint writes / merged reads, divergence surfaced, the commons, live peer asks — is in docs/multi-dev-field.md, and the full team process in docs/shared-field-workflow.md.
Token and recall numbers from the operator's own live seat (1,215 sessions, 1,955 user messages, 3,840 assistant turns, through 2026-10-15) — real traffic, not a synthetic benchmark. Reproduce with membrane stats --store .membrane/serve-msgs.json --baseline (read-only, no model call); the recall numbers reproduce with membrane bench --field (held-out, MRR + hit@k) or the scripts in experiments/.
Savings vs a naive full-context runner (the default for an agent runner: replay the whole transcript every turn, growing O(n²)):
The window's saving lands almost entirely on long conversations: turns with 200+ prior messages contribute 68.5M of the 72.4M tokens saved; under the 12-message window it is neutral (recall + tool loop is the standing cost). The naive side uses the seat's own ~4 chars/token estimate, so the −51% is conservative.
Recall quality (held-out, over the same seat's history): entity worldlines lift "who 1,500 never-seen mentions were about" from MRR 0.210 → 0.539 (mature entities 0.206 → 0.634); see the v0.5.0 notes and experiments/.
Source layout: membrane/ (the field: streams → efield/efstore → entity_block/efgate/night; the seat's serve server (server.py, opencode-compatible); the MCP surface (mcp_server.py); the CLI), experiments/ (the e-series rigs behind math-findings), tests/ (unittest + pytest, plain-python runnable), Dockerfile + docker/ (the public image; docker build -t membrane:dev ., see docs/docker.md).
python -m unittest discover -s tests # everything runs against in-process fakes, no server needed python experiments/variety_toy.py # the variety toy: the gate's calibration in one command Status Working lab, in daily use on its own development (dogfooded: this repo's own field holds ~14k live entities and its background mind digests, dreams, and speaks about its own work). Version 0.6.3; API and flag surfaces may still move. Licensing: PolyForm Noncommercial 1.0.0 (see LICENSE) — free to use, modify and share for any noncommercial purpose (personal, hobby, research, education, charities and public institutions); commercial use needs the author's written permission — ask.
PolyForm-Noncommercial-1.0.0 View SPDX License List
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
None of the files in this release were uploaded with provenance metadata.
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.




