MemNet
MemNet is mission working memory for LLM agents. An agent keeps the state of its current job in a named session graph of nodes, edges, and properties. It reads a small, bounded slice of that graph when a turn needs memory, and it writes back only what changed.
The package is memnet-llm. It installs the memnet CLI and the memnet-mcp MCP server.
What it is
MemNet sits between the LLM call pipeline and your data search. The host keeps the corpus and runs its own search, grep, or RAG. MemNet holds the working set for one mission: tasks, decisions, and locators that point into a few technical documents.
- Agents read and write in one language: openCypher-shaped GQL. The wire format is in
docs/grammar/gql-wire-profile.md. - A read is a
pin_map: a cue (a kind, a property, or a keyword) and then a bounded neighbourhood around the matching nodes. - A write is a
mutate: gatedCREATE,MERGE,SET, andDELETEstatements. - The graph is in memory. Durability comes from snapshots, checkpoints, and optional live persist.
MemNet is not a notepad in the chat, not a vector store, not RAG, and not GraphRAG. A typical session holds tens of MiB. A corpus of gigabytes belongs in your search layer. The design reasoning is in docs/SHAPE.md.
Install
MemNet needs Python 3.11 or later.
pip install memnet-llm
# or pin this release
pip install memnet-llm==0.21.1
Install the mcp extra on any host that runs memnet-mcp (stdio, streamable-http, or the product gateway):
pip install 'memnet-llm[mcp]'
Without the extra, memnet-mcp exits with status 2 and prints @ERR: mcp_extra_missing|....
Version 1.0 is not claimed yet. The meaning of each part of the a.b.c version number is in docs/ROADMAP.md. Release notes are in CHANGELOG.md.
Quickstart
This walk-through starts a local server, opens a session, writes three rows, and reads them back. Every memnet command except serve talks to a running server.
-
In terminal 1, start the server on a Unix socket:
export MEMNET_IPC_SOCKET=/tmp/memnet.sock memnet serve --ipc
On a host without Unix sockets, run
memnet serveinstead. It listens on TCP127.0.0.1:18765. -
In terminal 2, set the same socket path and write a session map. The map declares the node kinds and their fields:
export MEMNET_IPC_SOCKET=/tmp/memnet.sock cat > map.txt <<'EOF' SCHEMA TSK ; fields=id goal status SCHEMA NPC ; fields=id name status EOF
-
Open a session. The new session id goes to stderr as
MEMNET_SESSION=mn_…:memnet session open --map-file map.txt 2> open.err SID=$(sed -n 's/^MEMNET_SESSION=//p' open.err)
The server receives your arguments, not your shell environment. Pass
--session "$SID"on every later command. -
Write two nodes and an edge:
memnet mutate --session "$SID" --stdin <<'EOF' CREATE (:TSK {id: 'TSK_report', goal: 'Write the test report', status: 'in_progress'}) CREATE (:NPC {id: 'NPC_ana', name: 'Ana', status: 'active'}) MATCH (n:NPC {id: 'NPC_ana'}), (t:TSK {id: 'TSK_report'}) CREATE (n)-[:helps]->(t) EOF
The reply starts with
ok=3 fail=0. You do not mint ids. Theidproperty is an optional nickname that you can use as a cue. -
Find the task, then read its neighbourhood:
memnet query find --session "$SID" --kind TSK --limit 8 memnet query pin-map --session "$SID" --kind TSK --depth 2
The pin map is shaped GQL:
(:NPC {name: 'Ana', status: 'active'}) (:TSK {goal: 'Write the test report', status: 'in_progress'}) (:NPC {name: 'Ana', status: 'active'})-[:helps]->(:TSK {goal: 'Write the test report', status: 'in_progress'})
A single agent can skip the server. memnet-mcp on stdio runs the engine in its own process. Use a shared server when more than one process must see the same graph.
Core concepts
Sessions
A session is one graph with a time to live (TTL), a row cap, and a byte cap. You open it with a map and get back an opaque session id. Treat the id as a capability: whoever holds it can read and write the session. To hand work to another agent, pass the session id, and let that agent read the graph with pin_map. Do not paste the graph into the chat.
Reads and writes
Call pin_map only when a turn needs something from memory, and give it a real cue. Drop earlier pin maps from the prompt before the next call. An empty cue returns the session outline, which is useful once at the start of a job. When a hard cap clips a result, the reply says so. Write with mutate, and send only what changed. The agent playbook in docs/LLM-GUIDE.md describes the full loop.
PROXY nodes
A PROXY node points at one node in a session, which can be a different session. It has the properties target_session and target, and an optional target_backend. The target does not need to exist when you write the PROXY.
pin_map, find, and walks never follow a PROXY. They show it as a plain node. To follow it one hop, run memnet query follow --id <nickname> or call the MCP tool follow_proxy. There are three results:
@STAT: follow|ok, then the target node.@STAT: follow|dangling|reason=target_missing: the target session is on this server but the node is not.@STAT: follow|not_reachable|..., then@FOLLOW: <target_session>|<target>|<target_backend>: the target session is not on this server. This result does not mean that the target was deleted.
If the target is itself a PROXY, you get that PROXY back. Details are in the "PROXY nodes" section of docs/LLM-GUIDE.md.
Session copy
memnet session copy --from <session id> (MCP session_copy) makes an exact in-memory copy of a live session under a new id. Reads on the copy return the same rows in the same order as the source. The copy gets a fresh TTL. After the copy, the two sessions are independent, and the source is not changed. No file is written. The reply names only the new id:
@SESSION: <new session id>|<expires_at>|<ttl_minutes>
@STAT: copied|<rows>|-
@STAT: nodes|<n>|-
@STAT: edges|<n>|-
stderr gets MEMNET_SESSION=<new session id>. The copy runs the same checks as session save before it is registered, so a failed copy registers nothing.
Durability and live persist
memnet session save and memnet session load write and read a snapshot file. memnet admin checkpoint saves every loaded session without stopping the server.
Live persist is off by default. With MEMNET_PERSIST=full, the server writes a snapshot of each session to disk after the session changes, and restores from those files on restart. Sessions larger than MEMNET_PERSIST_FULL_MAX_ROWS (default 20,000 rows) are skipped and rely on checkpoints. After each save, a session waits MEMNET_PERSIST_SAVE_GAP_FACTOR (default 99) times the duration of that save before its next save. This spacing limits the time spent saving one busy session to about 1% at the default. A value of 0 saves on every tick. A shutdown drain (SIGTERM or SIGINT) saves every changed session immediately. Operations and trade-offs are in docs/operations/live-persist.md.
Several agents on one session
Parallel workers need a shared server, not the in-process default. Access control (CapsPolicy ACL) is off until you run memnet session acl-enable. Neighbourhood reserves (memnet reserve, extend, and release) let one agent hold part of the graph for a time. memnet import-slice merges a bounded slice from a member session into the lead session. The operating rules are in docs/operations/multi-agent-sessions.md.
CLI and MCP reference
Run memnet --help, or memnet <command> --help, for the flags of each command. Help also needs a running server: without one, the CLI prints @ERR: serve_required|.... To print help without a server, set MEMNET_TEST_INLINE=1. That variable is for tests and local help only.
| Document | Contents |
|---|---|
docs/LLM-GUIDE.md |
Agent playbook, MCP tool table, and CLI quick reference |
parts/memnet-mcp/README.md |
MCP server tools, transports, and HTTP settings |
docs/grammar/gql-wire-profile.md |
GQL wire format for reads and writes |
docs/cap-contract.md |
Hard caps, refusals, and the exact error lines |
docs/operations/README.md |
Operations guides: safe upgrade, backup, request log, usage report, and product gateway |
docs/README.md |
Full documentation index |
Configuration
MemNet reads its settings from environment variables. Set server variables on the memnet serve process. .env.example lists them with comments.
| Variable | Default | Purpose |
|---|---|---|
MEMNET_IPC_SOCKET |
unset | Unix socket path for memnet serve --ipc and for CLI clients |
MEMNET_SERVE_HOST, MEMNET_SERVE_PORT |
127.0.0.1, 18765 |
TCP bind address of memnet serve |
MEMNET_SERVE_ALLOW_REMOTE |
unset | Set to 1 to allow a non-loopback bind |
MEMNET_SESSION_TTL_MINUTES |
60 |
Session TTL when --ttl is not given |
MEMNET_STATE_DIR |
~/.local/state/memnet |
Root for checkpoint, upgrade, and live persist files |
MEMNET_SAVE_ON_EXPIRE |
off | Save a session when its TTL ends. Needs MEMNET_EXPIRE_SNAPSHOT_DIR |
MEMNET_EXPIRE_SNAPSHOT_DIR |
unset | Directory for expire-time snapshots. session load --session <id> reads from it |
MEMNET_REQUEST_LOG |
unset | Write one JSON line per server request to this file |
MEMNET_PERSIST |
off |
full turns on live persist |
MEMNET_PERSIST_SAVE_GAP_FACTOR |
99 |
Wait between saves of one session, as a multiple of its last save time. 0 saves on every tick |
MEMNET_MCP_TRANSPORT |
in-process | tcp makes memnet-mcp use a running memnet serve |
An invalid persist value stops the server at start with @ERR: config_conflict|.... The other persist variables are in docs/operations/live-persist.md. The MCP HTTP variables are in parts/memnet-mcp/README.md.
Known limits
- One session lives on one server. Connecting several servers is open work (#47).
pin_mapoutput can be written out as GQL, but reading SysML files or edited pin maps back in is not built (#66).- MemNet has no search or RAG tool. The host runs its own search and commits locators with
mutate.
Contributing
Clone the repository and install it in editable mode with the development and MCP extras:
pip install -e ".[dev,mcp]"
pytest
ruff check parts/common/memnet parts/memnet-mcp/software ops/tip_access_portal tests
ruff format --check parts/common/memnet parts/memnet-mcp/software ops/tip_access_portal tests
The tests run in-process and need no server. CI runs the same checks on Python 3.11 and 3.12 (.github/workflows/ci.yml). Open pull requests against master. Write new docs in British English. Repository layout and contributor rules are in LAYOUT.md and AGENTS.md.
Licence
MemNet is released under the MIT licence. See LICENSE.
Metadata
Release files for memnet-llm 0.21.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| memnet_llm-0.21.1.tar.gz | 712.9 kB | Without provenance | Details for memnet_llm-0.21.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| memnet_llm-0.21.1-py3-none-any.whl | Python 3 | none | any | Details for memnet_llm-0.21.1-py3-none-any.whl |
Total release size: 1.0 MB
Release files / memnet_llm-0.21.1.tar.gz
| Download URL | memnet_llm-0.21.1.tar.gz |
|---|---|
| Size | 712.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1d86ee55f4ec13f02f5d9854c984978b804791fddac649f9d62bef9fe405f8e5
|
|
BLAKE2b-256 checksum How to use checksums |
505e89b524de54c42434d1352f18d8719339114a42d2dcf6521e8f0487ce7fd9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / memnet_llm-0.21.1-py3-none-any.whl
| Download URL | memnet_llm-0.21.1-py3-none-any.whl |
|---|---|
| Size | 291.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dab3a6957ab54e97b3955e1d217ca6cfc54fecaf8b6c19b4aff63b993487b3ca
|
|
BLAKE2b-256 checksum How to use checksums |
24bc5acd98c528544aa570e43dae68bb41006b116c2277c3c0eca830807eb228
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Security for memnet-llm 0.21.1
Provenance
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.