{"slug": "agent-memory-that-forgets-and-distorts-on-purpose", "title": "Agent memory that forgets and distorts on purpose", "summary": "SelMem, an open-source Rust project by jbsalles, introduces selective reconstructive memory for large language models, enabling two instances to diverge by forgetting, gilding, and anchoring a particular past. The system, which runs with zero Cargo crates on Rust 1.75 and uses SQLite or flat files for persistence, aims for non-average, path-dependent continuation rather than maximizing coverage. The project includes a whitepaper and parameters document, and supports LLM backends such as OpenAI's gpt-4o-mini and local Ollama models.", "body_md": "Selective reconstructive memory for an LLM entity.\n\nAn LLM maps context to the next token. A stack of unmodified facts maximises coverage, not deviation: more evidence, same average path. SelMem sculpts a particular past — forgotten, gilded, anchored — so two instances can diverge. The aim is a non-average, path-dependent continuation, not a taller log. Selection, reconstruction, sleep, identity.\n\n**Manifest:** [WHITEPAPER.md](/jbsalles/Selmem/blob/main/WHITEPAPER.md)\n**Knobs:** [PARAMETERS.md](/jbsalles/Selmem/blob/main/PARAMETERS.md) — exploratory, not fitted.\n\nZero crates. Rust 1.75. SQLite via system `libsqlite3`.\n\n```\nsrc/\n  core/       model, profile, store\n  encode/     intake, scoring, embed, affect, identity\n  recall/     retrieve, narrator, http\n  dream/      night, drift, singularite\n  persist/    file, sqlite\n  net/        api, httpx, ui\n  engine.rs   the loop\n  bin/        selmemd, selmem-chat\nexperience → interpret → identity paint → gate\n        ↓                         ↑\n   lived book + sealed archive    |\n        ↓                         |\n remember / speak (meaning can move)\n        ↓\n      sleep\n weather · rewrite · merge · extinguish\n motif → belief → trait → who_am_i\n        ↓\n   next experience is already colored\n```\n\nThe model never sees the archive. Only gist, core, schema, affect, fidelity, mood, living axioms.\n\nClaire and Silas are not characters. They are two sensitivities (`tender` / `austere`) on the same corpus. After nights they are not the same past.\n\nZero Cargo crates. Persistence is a vault, not the memory: the organ lives in RAM (`MemoryStore`); on `save` it is dumped, on `open` it is reloaded. The model never talks to the vault.\n\nTwo backends, same `Snapshot` (`profile`, `mood`, `store`):\n\n| Path | Backend | \n|---|---|\n| `.db` /`.sqlite` /`.sqlite3` | system `libsqlite3` (prepared statements,`BEGIN IMMEDIATE` ) | \n| anything else | flat `SELMEM1` file | \n\nIDs are `{prefix}_{pid}_{n}`. The counter is raised on load for both backends. Dropped events leave no archive. Orphans are pruned on sleep and SQLite load.\n\nLink is dynamic. If `ld` cannot find `-lsqlite3` (no `-dev` package):\n\n```\nmkdir -p /tmp/selmem-libs\nln -sfn /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 /tmp/selmem-libs/libsqlite3.so\nexport RUSTFLAGS=\"-L /tmp/selmem-libs\"\n```\n\n`./run.sh` does that when needed, then execs `cargo`.\n\n```\n./run.sh test\n./run.sh run --release --example compare\n./run.sh run --release --example llm_night\n./run.sh run --release --bin selmemd -- --help\n```\n\nRust only. No Python suite.\n\n| What | Where | \n|---|---|\n| Narrative scenes (edit these) | `tests/cases/*.json` | \n| JSON runner | `tests/scenes.rs` | \n| Physiology — decay, anchors, SQLite, Ebbinghaus | `tests/engine.rs` | \n\n```\n./run.sh test\n./run.sh test --test scenes\n./run.sh run --release --bin selmemd -- \\\n  --bind 0.0.0.0:7420 \\\n  --path claire.db \\\n  --name Claire \\\n  --profile tender \\\n  --token secret \\\n  --llm https://api.openai.com/v1/chat/completions \\\n  --model gpt-4o-mini \\\n  --api-key \"$SELMEM_API_KEY\"\n```\n\nUI: `http://IP:7420/` — paste the token at the top, talk.\n\nLocal Ollama: `--llm http://127.0.0.1:11434/v1/chat/completions --model llama3`\n\nBehind nginx:\n\n```\nlocation / { proxy_pass http://127.0.0.1:7420; proxy_read_timeout 90s; }\nexport SELMEM_LLM=https://api.openai.com/v1/chat/completions\nexport SELMEM_MODEL=gpt-4o-mini\nexport SELMEM_API_KEY=sk-...\nexport SELMEM_EMBED=https://api.openai.com/v1/embeddings\nexport SELMEM_TOKEN=secret\n```\n\nNo endpoint: `RuleNarrator` + hashed vectors. The organ still runs.\n\nOne thread per connection. `/health` and `/` do not take the memory lock. `/turn` is serialized on the organ (one writer). Auth is `Authorization: Bearer` only — not `?token=`.\n\n| Method | Route | Role | \n|---|---|---|\n| GET | `/health` | liveness (no token, no lock) | \n| GET | `/who` | living axioms (trait > belief > motif) | \n| GET | `/lineage?schema=` | history of a belief | \n| GET | `/mood` | mood | \n| GET | `/audit?id=` | sealed verbatim (human debug) | \n| POST | `/live` | encode | \n| POST | `/remember` | reconstruct | \n| POST | `/speak` | embodied reply | \n| POST | `/turn` | live + reply | \n| POST | `/sleep` | consolidate | \n| POST | `/save` | flush | \n\n- Two books: lived narrative / archive. The model never reads the second.\n- Two channels: `self` is sculpted,`world` is not.\n- Forgetting by default. Encoding threshold.\n- Unlabelled events get lexical affect (FR+EN), then identity, then optional LLM `interpret` on the live sentence.\n- Living axioms color the next encoding before the gate.\n- Cherished memories embellish. Recalled disgust amplifies. Neglected disgust extinguishes.\n- Recall can shift *meaning* (valence under current mood), not only wording.\n- Nearby episodes fuse into myth. Heavy anchors do not merge.\n- Axioms climb: 2 traces → motif, 3+ → belief, aligned beliefs → trait. Lineage stays.\n- Two profiles on the same corpus diverge. Fingerprint uses founders, traits, contradictions.\n- Proxy for originality: reconstruction sticks less than the unmodified log; clones are not interchangeable; `world` facts survive (`originality_is_path_dependent_not_a_taller_log` ).\n- Persistence: `.db` (SQLite) or`.selmem` (flat file).\n\n``` js\nlet mut mem = SelectiveMemory::open(\"claire.db\", EntityProfile::tender(\"Claire\"))?;\nmem.live_with(input);\nlet recalled = mem.remember(\"that evening\");\nlet _ = mem.speak(\"do you remember?\");\nmem.sleep();\nmem.who_am_i();\nmem.lineage(\"loyalty\");\nsingularity_distance(&fingerprint(&a), &fingerprint(&b));\n```\n\nNot RAG. Not a vector database. Not a personality in a system prompt.\n\nNot a neocortex and not a brain. An executive–autobiographical loop around a next-token transducer.\n\nNo local neural encoder ships in-tree: pass `--embed` if you have one.", "url": "https://wpnews.pro/news/agent-memory-that-forgets-and-distorts-on-purpose", "canonical_source": "https://github.com/jbsalles/Selmem", "published_at": "2026-09-07 07:50:48+00:00", "updated_at": "2026-09-07 07:57:11.667492+00:00", "lang": "en", "topics": ["artificial-intelligence", "large-language-models", "ai-research", "ai-tools"], "entities": ["SelMem", "jbsalles", "Rust", "SQLite", "OpenAI", "gpt-4o-mini", "Ollama", "llama3"], "alternates": {"html": "https://wpnews.pro/news/agent-memory-that-forgets-and-distorts-on-purpose", "markdown": "https://wpnews.pro/news/agent-memory-that-forgets-and-distorts-on-purpose.md", "text": "https://wpnews.pro/news/agent-memory-that-forgets-and-distorts-on-purpose.txt", "jsonld": "https://wpnews.pro/news/agent-memory-that-forgets-and-distorts-on-purpose.jsonld"}}