memory for agentic sessions · the main page
recall is the agent's tool: it pulls the memories that
bear on what it is about to do, by its own cue, whenever it needs them. A session's start gets a seed.
Partly built: sandman recall, the seed and the pull,
sandman show and sandman remember run (the tools), both
models in sandman-infer, the daemon's child (needs); the mod wiring and the pane are not, and the earlier sandman's
recall runs at every session's start. A decision is open until its badge says settled; the pipeline and its cut are
the evaluation's choice.
The problem
Today the mod runs the earlier sandman recall --hook on a session's
first prompt, awaits it (10 s timeout) and injects up to 10,000 characters. That recall never sees the prompt: it
walks from the cwd's bank up through ancestor banks, never down, inside a 9,000-character budget.
Sessions start from one root directory and dispatch work into many repositories. From there the walk reaches 2 banks and, after its budget cuts, injects 31 index lines; every bank below the root is out of reach.
sandman-next chart (measured 2026-11-13), banks unnamed
(docs/data/recall-reach.json).The flow
Two ways in, one pass: the seed once at the first prompt, the agent's pull at any time.
sandman recall, both models in sandman-infer;
the mod does not run the seed yet. pplx's p50 is the evaluation's over 98 cues
(latency).What did the evaluation choose?
settledLexical and embedding ranks fused, a local decision model on the fused top 10, the two orders fused again: the best precision measured and, at cap 6, must-recall level with hosted Jev's, with nothing leaving the machine.
| pipeline | lines | precision | must-recall | no-ask empty | time or cost |
|---|---|---|---|---|---|
| lexical top 39 → hosted Jev, blended | 5.81 | .603 | .663 | 1.0 | ~1 s, 7.5k tokens |
| lexical only built, the last fallback | 4.34 | .584 | .510 | 1.0 | 2 ms |
| lexical ⊕ embeddings, no decision model built, the fallback | 4.45 | .622 | .582 | 1.0 | ~30 ms |
| lexical ⊕ embeddings → pplx-decider-flash on the top 10, fused, cap 5 | 4.32 | .648 | .611 | 1.0 | p50 772 ms, p90 832 ms |
| the same at cap 6 built | 4.93 | .629 | .630 | 1.0 | the same |
| the same, one question a request (cap 5) | 4.31 | .633 | .596 | 1.0 | p50 1,546 ms |
| the same, two requests of five (cap 5) | 4.33 | .637 | .601 | 1.0 | p50 919 ms |
| hosted Jev over every memory | 3.99 | .619 | .577 | .923 | 121.5k tokens |
98 cues over the real corpus; one gold of 7,523 Opus-judged labels, 208 of them must-haves; rules fit on a dev half, confirmed on the held-out half (measured 2026-11-13 · the recall evaluation's union-final table). Embeddings add about 3 points of must-recall once the decision model is there, 7 without it.
Rerankers and larger embedding models did not beat the two-model pipeline. Hosted Jev over every memory is no better than it at 121.5k tokens a pull.
The ten candidates go in one request. The decision model's card calls one question a request the safer default; here it scored lower on every measure and took 1.8 times as long, since the local server answers one request at a time. The request shape moves a candidate's score by .13 on average, and a rerun of either shape is identical, so the gap is the shape's and not noise (measured 2026-11-13 · the evaluation's shape table).
What still gets missed
openThe scorers read a name and 160 characters of description, so the remaining losses come from the memories as much as the scoring: a rule for every repository whose description hides when it applies, a name that is a date or a sentence, a memory filed under another repository's bank. Encode and consolidate guidance shapes new memories built.
- redescription — a dry run of a one-time rewrite exists: 303 names, 607 descriptions and 177 homes would change. It is measured on this pipeline before any memory is edited planned.
- stale and duplicated — the same pass flags 93 memories as stale and 62 as duplicated; listed, not acted on.
What is the cue?
settled| option | what it means | cost |
|---|---|---|
| the ask, led by its repository when one is known built | state is repository: <owner/repo> and the first prompt or the agent's cue; known from a pull's --about or a seed's cwd inside a repository | the ask leaves the machine only with hosted Jev (privacy) |
| the ask alone | no place in the state | a rule from the wrong repository ranks beside the right one |
| nothing (today) | selection by place only | the 95 % in the problem |
The cwd is the grove root for nearly every session, which says nothing: only a cwd inside a
repository, or the agent naming it, leads the state and joins the BM25 query. A repository the cue names
(fix the grove daemon) is the about, 4 to its bank, without leading the state or joining
the query, as in the evaluation; of two named, the longest key wins.
Which memories are candidates?
settled| option | what it means | cost |
|---|---|---|
| every memory and trace, ranked twice, the fused top 10 decided built | BM25 over the whole text and the cosine of a cached embedding, fused; ten names to the decision model | a must-have past the fused 10 is never decided |
| every memory, one noul each | 628 questions in balanced requests | 121.5k tokens a pull, and the distractors the first stage removes |
| the cwd's chain (the earlier recall) | the cwd's bank and its ancestors | 2 of 49 banks from the root |
- BM25 reads
<label> · <name>, the description one-lined to 400, the body and the file's stem; the embedding the same head and the body's first 1,500 characters, withqwen3-embedding:0.6b(1,024 dimensions, 1,024 tokens). The labels come from the grove root's owner and repository dirs, so a worktree's bank reads as its repository (AGENTS.md). - The vectors live in
<root>/embeddings.jsonl, keyed by the text's SHA-256, so the evaluation's own cache reads here unchanged. serve's tick embeds what is missing, 128 a tick; a pull embeds at most 8 more, the lexically best, and one still missing ranks lexically only. - The decision model sees each of the ten as
Memory (<label>): <name> — <description, 160>. <question>beside the state. - Traces are candidates too, from the moment they are written: a
remembermade at 10:05 is recallable at 10:06, marked~until consolidation keeps, merges or prunes it; ausertrace rides the always-set. - Knowledge pages and playbooks, and their traces, are candidates in the same pass under the label
knowledge · <topic>: no repository's bonus, never the always-set (the knowledge store).
What comes along without a vote?
settledEvery user memory, plus any pinned: facts about the person bear on every session
whatever the cue. They ride the seed only, counted first against its budget: 18 lines today, about 3,600
characters. A pull never prints them; at the default 4,000 a pull that did had room for nothing else.
- Pinning is the format's
recall:field, written from the pane; no memory carries it today. - When the set passes half the seed's budget, the cap or the set is the next decision.
What is injected?
settled| option | what it means | cost |
|---|---|---|
| one line per memory, a verb to read one built | .NN name (type · path) — description, ~name for a trace, and sandman show <path> once | a body costs a tool call when the session needs it |
| bodies for the top few, lines for the rest | the best matches arrive whole | a body averages over 1 KB (888 KB over 645 files): three bodies cost about fifteen lines |
| bodies for all that fit | no reads needed | a handful of memories per session |
One line per item plus a verb to read one in full, the house rule. A read through show
writes a ledger line, so line-then-read is also the use signal record needs; a
body sent whole leaves no trace of whether it helped.
How much is injected?
settled| path | order | kept | at most |
|---|---|---|---|
| a decision model answered | its order fused with ④'s, a tie newer first | 2/66 or more | 6 |
| no decision model | ④'s fusion | .0284 or more, within .0063 of the top | 8 |
| no embeddings either | BM25 with its bonus, a tie newer first | all | 5 |
Six, where the reference ships five: a missed must-have is the worse error, and the sixth line buys 1.9 points
of must-recall for 1.9 of precision. Each line shows one number in its order: a fused score over the best
possible, 2/61, so the top line reads 1.00 and a kept one no less than
.92; the lexical cut shows BM25 over the top one. Then the characters: 9,000 for the seed,
4,000 for a pull, under the 10,000 session-start cap; a cue with no ask gets nothing.
$SANDMAN_RECALL_CAP, --budget and
$SANDMAN_SEED_BUDGET move them.
When does it run?
settledWhenever the agent needs it: recall is the agent's tool, pulled throughout a session with its own cue — what it is about to do, the repository it is entering, the decision it is about to make — through the CLI or the same verbs as MCP tools. Nothing in the mod calls a model per prompt.
The session's start is a seed, the one verb the mod runs there: ① the start mark, first and whatever follows, an interactive session's only (a headless claude -p run, a routine, gets the seed's text and its recall line, never a mark, so nothing ever takes or encodes it), so
mark keeps only calls and prompts and the short-term pointer goes; ② short instructions
saying memory exists and when and how to pull it (as shipped); what is
due; ③ the always-set; ④ memories for the first prompt, only when the gate finds a real ask.
- After
/clearthe seed runs again for the same session: a second start mark (chartkeeps the earliest), and nothing an earlier recall sent is sent again.
What does the seed wait for?
settledAt most 4 s for the whole pass, every embedding and every scorer tried ($SANDMAN_SEED_MS),
inside the mod's 10 s; a pull has $SANDMAN_RECALL_MS, 10 s. Over the real corpus of 635
a pull takes about 0.95 s with pplx answering, 0.27 s with no decision model and 0.14 s with neither, the read of
the 14 MB cache included (measured 2026-11-13, both models then served by an idle Ollama). The seed never fails the prompt: past the bound it
prints what the stages that answered allow, exits 0 and records why. ① is written before any of it, so nothing
loses the start mark.
What happens when a model is down?
settledEach stage drops out within the same bound and the rest answer, never an error to the agent: the embeddings down,
the decision runs on BM25's order; a decision model down, the next in $SANDMAN_SCORERS
(pplx,jev), each sent the same request; none, the hybrid cut; nothing, the lexical cut.
The header names the path and what failed (· pplx (infer <version>), the build
that answered, plain · pplx from an older child,
· jev: pplx failed, · hybrid, no decision model,
· lexical: embed and pplx and jev failed) and the ledger line keeps each cause.
- Down is no socket or a refused connection, a timeout, an HTTP error or a refusal
(
booting,no_model), a reply without a noul or an embedding per text, or Jev without a key. - Jev out of credit or refused (
billing_error, 401, 402, 403) is held down for 6 hours, anything else for 60 s, in<root>/jev-down.json; while it holds, Jev is skipped.
Hosted or local?
settledLocal: both models run on this machine, and nothing leaves it unless hosted Jev is placed in the scorer order
and reached, which today needs pplx to fail first. Then the cue and ten names, descriptions and repository
labels go to api.typesafe.ai; bodies never do. The user memories
and pinned ones are never candidates: they ride the seed unscored.
What does recall record, so the pipeline can learn?
open| option | what it means | cost |
|---|---|---|
| a ledger line a pull and a read, pin and mute from the pane proposed | below; the two lines built | the sent list's bytes, per pull |
| nothing | as today | no way to tell a useful memory from a noisy one |
{"about"?:"<owner/repo>","always"?:["<path>"],"ask":true,"at":…,"considered":n,"cue":"<200>","cut":n,"embedded":true,"engine":"<version>","error"?,"kind":"recall","machine":…,"ms":n,"scorer":"pplx","seed"?:true,"sent":[{"file":"<path>","id":"<its id>","score":0.97}],"session":…,"tokens":n}
{"at":…,"file":"<path>","id":"<its id>","kind":"show","machine":…,"session":…}
{"at":…,"file":"traces/<bank>/<file>","id":"<its id>","kind":"remember","machine":…,"session":…,"type":"feedback"}
Proposed: sent, then read, then pinned or muted is the whole feedback loop, and two of its three parts exist already.
- use — a
showline of a sent memory in the same session; before the seed and the pulls pass--session, a read of the file in the tool log (194 on record). - pin, mute — from the pane: the memory's
recall:field and a ledger line. - reflect reads memories sent three times or more and never read as evidence that their names and descriptions miss when they apply, and may rewrite encode's and consolidate's guidance for it, and the selection question when the recall evaluation scores the rewrite no worse (reflect).
What happens to the earlier recall's other sections?
open| option | what it means | cost |
|---|---|---|
| drop all three proposed | recent sessions, the voyage log and the tool index go | a session that resumes yesterday's work starts without the list |
| keep recent episodes, three lines | from the ledger, after the memories | about 600 characters of the budget, unscored |
| keep all | as today | the budget they took is why 118 reachable lines were cut |
Proposed: none of them is chosen by the cue; what they carried that matters becomes memories through encode.
The tools
The seed is the mod's, recall and show the
agent's, remember its write, each a command and the agent's three also MCP tools; the
contracts are in AGENTS.md.
sandman recall < {"session","prompt"?,…}built — the seed, once at the first prompt: ① the start mark, first and whatever follows, only wheninteractiveis true; then, within 9,000 characters, the instructions with the session id, the due block, the always-set, the prompt's ranked lines when the gate finds an ask, and the footer; past 4 s, what the stages that answered allow.CLAUDE_MEMORY_PIPELINE=1: that mark only. Bad stdin: exit 2, nothing written.sandman recall --cue "…" [--about <path>] [--session <uuid>] [--budget <chars>]built — the pull: the flow, every transport curl (Jev's key as curl config on its stdin, never in an argv); stdout the header, the ranked lines and the footer, never the always-set; stderr one stats line; one ledger line; within a session nothing already sent, by the seed or a pull, is sent again.sandman show <path> [--session <uuid>]built — the memory's or trace's body under its name, type (a trace says so) and date, and a ledger line; a memory is<bank>/<file>, a knowledge pageknowledge/<topic>/<file>, a tracetraces/<bank>/<file>, anything else refused.sandman remember "<body>" [--type <type>] [--topic <topic>] [--name …] [--description …] [--about <path>] [--session <uuid>]built — encodes on purpose: one trace written at once totraces/<bank>/, a newid, sourceremember <ISO> · <session>(origin: handwithout one), aknowledgeorplaybookby its--topic(the knowledge store), else homed by--aboutas an encoded trace is, else by the cwd (from the root: about the person, or true everywhere); defaults feedback, the body's first eight words, its first line. It prints theshowline to read it back and writes a ledger line; encode never writes it again, and consolidation takes it like any other trace.sandman mcpbuilt — the three as MCP tools over stdio,recall {cue, about?, budget?},remember {body, about?, topic?, type?},show {path}, besidedefer,done,dropanddueandrethink, each description the seed's when-to-pull line; a call runs the verb itself, so its text, ledger line and de-duplication are the command's, and a failure is a tool result flaggedisErrorcarrying the verb's error line. The session is Claude Code's$CLAUDE_CODE_SESSION_ID, which it gives every stdio server, unless a call passessession. Registered once, by the owner:claude mcp add --scope user sandman -- ~/.local/bin/sandman mcp.- Every command printed for the agent names the binary as invoked:
sandman, orsandman-nextfor a dev build.
docs/data/recall-seed.txt
add a clock to the alpha
tests; the suite fails unless this is the verb's output.docs/data/recall-digest.txt
--budget 560, pplx answering, three lines
before the budget; the suite fails unless this is the verb's output.The pane
not built Today the mod's pane shows one row per injected block,
▸ hh:mm · sandman recall · <n> chars, expanding to the whole text dimmed; a pull's
row carries its header's path verbatim, so pplx (infer <version>) names the engine
that answered. The
engine allows a working list: the session's pulls, the newest open.
~ a remembered trace not yet consolidated.
Scores rank; they are not probabilities (risks).| key | does | records |
|---|---|---|
enter | expands the row: description and the verb to read it | nothing |
o | opens the memory file | nothing: the pane is the person, not the session |
p | pins: always sent from now on | recall: pin on the memory, a ledger line |
m | mutes: never a candidate | recall: mute on the memory, a ledger line |
r | pulls again with the open pull's cue | a new recall line |
- engine — a Button with a hotkey per row, Text colour and dim for scores and descriptions, a Link to open the file, scroll while focused, refresh on
r. - width — a dock up to 45 % of the terminal's columns, opened at 144 columns or more; under that, an inline pane a third of the rows high.
Risks
- injection — memories are written unattended from transcripts, so a name or description can
argue for its own selection. Planted beside the corpus, a memory claiming it applies to every request came back in
5 of 15 robustness cues; withholding the bank bonus from any name or description that claims its own importance
cut that to 2 of 15 with the headline unchanged, and no real memory matches the pattern (measured 2026-11-13). The
description is capped at 160 characters, the question is the binary's until a rewrite scores no worse on
the judged sends, and
reflectwatches for memories sent often and never used. A stricter question measured as noise and is not shipped. - the number — a fused score ranks; it is not a probability, and the floors are where this corpus's scores fell.
- one child — the best path needs
sandman-inferwith both models resident; without it every pull is the lexical cut, .12 less must-recall (needs).
What must be running
sandman-infer, the daemon's child (serve starts it beside
itself and restarts it when it exits), runs both models in process over llama.cpp on Metal and answers on
<root>/run/infer.sock: qwen3-embedding-0.6b-q8_0.gguf (639 MB)
and decider-flash-v1.2-q8_0.gguf, the pplx System One decision model (5.2 GB), both
in <root>/models, which sandman setup creates and names the
sources for; about 8 GB resident, both loaded at start. It reports booting for the first
seconds, about 13 s on the first start after an install while Metal compiles its shaders, and recall falls back
meanwhile and says so (embed: booting); hosted Jev is the next scorer. Without the child, recall loses its cosine
rank and the pplx scorer and says so: Jev still decides over the BM25 order, and only with no scorer answering does
it answer from BM25 alone; without the cache, a pull embeds 8 and the tick fills the rest.
The infer socket
One JSON request line, one JSON reply line, a connection each, on
<root>/run/infer.sock (<root> is
$SANDMAN_ROOT, else ~/.sandman). A client has 1 s from its accept to send the
whole line (at most 1 MiB), and 1 s to take the reply.
{"op":"decide","questions":{"<id>":{"instructions"?:"<text>","type":"noul"}},"state":"<text>"}
→ {"answers":{"<id>":{"noul":<0..1>,"type":"noul"}},"ok":true,"usage":{"input_tokens":n},"version":"<build>"}
refused → {"code":"<code>","ok":false,"reason"?:"<text>"}
- request —
questionsis a non-empty object of non-empty ids, each{"type":"noul"}with an optional stringinstructionsand no other field;stateis a string. A noul is the model's probability that the answer is yes, one per id, and the prompt holds at most 8,192 tokens. - refusals —
bad_request(a malformed line, or adecidenot shaped as above, the reason naming the shape),too_long(over 8,192 tokens, the reason the count),no_model(the decision model failed to load, the reason its cause),unknown_op,booting(the models are still loading: retry later) andstopping. - readiness —
{"op":"health"}answers at once, even while booting, with"state"booting,ready,degradedorstoppingand"models"{"decide":bool,"embed":bool};decideanswers only oncebootinghas passed. - one at a time — the accept loop reads each connection in turn and one worker runs the model ops in the
order they arrive,
decideandembedalike, so a second request waits behind the first; a stop answers the queued onesstopping.
Parity with what it replaced
Measured 2026-11-22 ( M4 Max · infer/tests/infer.rs
parity): the decision prompt tokenises to the official encoder's ids, nouls within
1.5e-7 of the prototype's native run; embeddings at cosine .99999955 or more against Ollama's over 50 texts.
Ten questions decide in about 415 ms, 16 embeddings in about 124 ms. Side by side with the installed Ollama path
over copies of the live store, 98 cues (measured 2026-11-22), this build's figure first: the decider answered on the
same 85 cues on both (13 closed by the gate on both), the top result agreed on 90 of 98, the sent set was identical
on 67 of the 85, 429 lines sent against 430, a pull's p50 860 ms against 967 ms; the differences sit at the keep
threshold, the two paths running different quantisations of the decider (this Q8 GGUF against Ollama's MLX mxfp8).
Open questions
- Hosted first or local first:
$SANDMAN_SCORERSis one setting, and the order is the owner's call. - Jev on this pipeline's top 10, checked once its credit resets.
- Redescription, measured before any memory is edited (misses).
- Scores in the pane as numbers or as bars?