Skip to content
Fernando Bandeira

Agent Memory

Agent memory carries project quirks, pitfalls and decisions across sessions.

Agent memory is information stored across sessions and made available when an agent needs it again. A project quirk, a pitfall or an earlier decision can live in files, a database or a managed store. Djinn uses a database-backed knowledge base of linked notes as one implementation, a Zettelkasten for agents.

  • Why it matters:
    • Without it, every agent run starts from zero and rediscovers the same landmines. This is the agent equivalent of a team with no documentation and total handover loss on every task.
    • The structure matters as much as the storage: linked, atomic notes (searched by embedding, walked as a graph, assembled into context) mirror exactly the fleeting → permanent flow of a Zettelkasten: extraction after the work, dense linking, retrieval when relevant.
    • Retrieval is the hard half: Djinn’s own backlog shows notes are worthless if they don’t reach the agent’s prompt at the right moment (the “memory materialization gap”, where notes existed but never got injected into the K8s worker’s context).

The lifecycle

Regardless of what they store, full memory systems follow the same cycle. They capture information, consolidate it, retrieve it, insert it into context and eventually reduce or stop using it. Each system’s trust model specifies who can change what at each stage. The systems differ in how they run each stage, and each stage has a characteristic failure mode.

  • 1. Capture. Get knowledge out of the transcript while it’s cheap. A finished task’s transcript contains everything the agent learned, buried in noise. Hoping it stays reusable raw is the same mistake as never promoting fleeting notes: extract after the task, deliberately, rather than hoping the transcript is reusable. Djinn extracts three typed notes per run: cases (problem + solution), patterns (reusable methods), pitfalls (error + resolution). Budget the extraction step: cheap models, deduplication, and distinguishing “failed to extract” from “nothing to extract” all showed up as real reliability work in Djinn. The characteristic failure is silent: a 1024-token output cap once truncated the extraction JSON mid-array and dropped every note. The memory system looked alive while learning nothing. (deja-vu is the honest null hypothesis for this whole stage: skip extraction, index the raw transcripts lexically, and see how far ~12ms grep-speed search gets you.)

  • 2. Consolidate. Keep one note per concept. Without a check for an existing note, extraction creates a near-duplicate each time the same problem recurs. Searches then return several versions of the same note. Djinn runs a novelty judge that enriches the existing note instead of creating a sibling. Consolidation is also where storage design bites: it needs an atomic transaction (canonical note, provenance rows, and the active → superseded flip of its 3 to 8 source notes commit together or not at all), which is exactly what a DB buys. Files with a derived index (basic-memory, letta’s git-tracked MemFS) buy the opposite goods: diffability, human editability, Obsidian as a client. And once several agents write memory concurrently, everyone reaches for git semantics anyway: merge, history, rollback.

  • 3. Retrieve. Systems share a basic method and differ in which other signals they use. Dense vectors + lexical search fused by reciprocal rank fusion is used by systems including hindsight (4 retrievers + a cross-encoder) and Djinn (6 signals). What separates systems is the extra signals joining the fusion: recency, graph hops, task affinity, file scope validated against the git tree. How they use confidence also differs: Djinn found that multiplying score by raw confidence “annihilates” results, and bounded it to a [0.75, 1.25] tilt over a hard 0.3 eligibility floor. Confidence should tilt ranking, never gate it.

  • 4. Inject notes when the agent needs them. A perfect retrieval that arrives at the wrong moment is a miss (that’s the materialization gap above). Five distinct injection moments recur across systems: at session start; on an explicit tool call; transparently wrapped around every LLM call; just-in-time at the risky action; and pushed by the store when relevance changes (muninndb’s semantic triggers, without polling). Djinn inserts its pitfall block on the first write because static session-start injection “misses the highest-leverage moment — the instant the agent first modifies a file”. Whatever the moment, the injection is budgeted with typed drop reasons and fails open: unbounded memory is context rot with extra steps.

  • 5. Forget. Demote notes and retain their contents. A store that only grows retrieves worse every week; a store that deletes destroys provenance. Keep statuses reversible (active / archived / deprecated / superseded), compute decay at query time from access recency where possible (muninndb’s ACT-R activation, which computes forgetting without background writes), or decay confidence below the injection floor in a background tick. Summaries should be lossy in context but lossless on disk (beads restores full detail from git). The one hard boundary: automated decay must be structurally unable to touch hand-written notes. Djinn’s decay SQL only matches the three extracted types, never an ADR.

  • Trust. Update confidence only on evidence about the note’s truth. Extracted notes enter at confidence 0.5 vs 1.0 for human-written; automation may enrich uncertain notes but never rewrites above 0.8. The subtle rule: only signals about a note’s truth (user confirmation, contradiction, staleness) may move confidence, never usage. Djinn removed the constant that raised confidence when two notes were retrieved together. The rule increased confidence in the weaker note and made it more likely to be inserted into a prompt. That made it more likely that the system would retrieve the two notes together again. (muninndb runs Hebbian co-activation deliberately, but on the association channel, never the confidence channel.)

How to apply

  • Scope notes (per project, per topic) so injection can be matched to the task at hand instead of dumping everything.
  • Design the lifecycle stages against their failure modes above: silent extraction death, duplicate drift, confidence gating, wrong-moment injection, unbounded growth, self-confirming usage loops.
  • Gate memory changes behind deterministic replay with explicit non-regression criteria (recall must not drop, injected payload must not grow). Never let a passing replay stand in for an effectiveness claim.

Directions in the references

The references split on what is stored (raw transcript / extracted fact / graph / file tree / work item), who curates it (pipeline / the agent itself / decay dynamics / a human with ACLs), and when it enters context (queried / pushed / primed at run boundaries).

  • hindsight. It distinguishes three memory types: World facts, its own Experiences and derived Mental Models, with Reflect as an explicit, scheduled operation that manufactures new knowledge from old; recall runs vector + BM25 + graph + temporal in parallel, fused by RRF. github
  • muninndb. It implements memory dynamics in the engine: Ebbinghaus decay, Hebbian edges emerging from co-activation (never schema-declared), Bayesian confidence lowered by contradiction. It also inverts control flow: semantic triggers push recall when relevance changes. github
  • OpenViking. It presents context as a navigable filesystem: viking:// URI tree, every node carrying .abstract (~100 tok) / .overview (~2k) / full-content tiers, directory-recursive retrieval that drills down instead of returning orphan chunks so the retrieval trajectory can be visualized and debugged. github
  • TencentDB-Agent-Memory. It treats memory as a governed asset economy: L0 conversation → L1 atoms → L2 scenario → L3 persona distillation, four asset kinds (chat, skills, wiki, code graph) in one registry, ACL-bound to agents as an equippable loadout. Sharing is an explicit act, not a default leak. github
  • letta-code. The agent is its memory: self-editing memory blocks, sleep-time “dreaming” that reorganizes memory off the request path, and MemFS putting the whole context under git so it can be compared, reverted and moved. Continual learning, versus everyone else’s retrieval. github
  • beads. It uses issue tracking as memory: a dependency DAG whose primary query is bd ready (the readiness frontier, or memory that computes what to do next), hash IDs so parallel agents never collide, semantic compaction of closed work. github
  • basic-memory. Typed observations + typed wikilinks in human-editable Markdown, SQLite as a derived index. The file is the memory. Both human and LLM read/write it. github
  • deja-vu. It tests the null hypothesis without extraction or embeddings. It indexes the transcripts your agent runtimes already write (across runtimes, retroactive over months of history, credentials redacted at index time) and searches them lexically in ~12ms. github
  • Counterpoints: codebase-memory-mcp (the memory an agent most needs is a pre-computed structural graph of the code, not the conversation), cognee (session cache vs permanent graph two-speed memory, whole stack on one Postgres, github), graymatter (four composable write paths, one being the LLM reflecting on its own memory mid-session; losing a write is fine because consolidation repairs the store, github), warren (memory as a git-tracked directory primed in and reaped out at run boundaries, github), Context-Engineering (the citation hub: context as C = A(c₁…cₙ), github).