Expand description
Long-term-memory wiring for crate::AgentLoop.
Two pieces, designed to be installed together:
-
MemoryGuide— at session start, callsMemory::recallwith the current task description and pushes the top-K matches intoctx.guidesas plain text. The model sees a “Relevant prior context” section in its system prompt before the very first model call. -
MemoryWriter— captures every assistant text turn (viaPostModel) and persists the last one as aMemoryEntrywhen the run finishes (TaskCompleted). This turns “this conversation produced an answer” into “future sessions can recall the answer”.
Both share an Arc<dyn Memory> so a single backend serves recall +
write. The trait is async; the writer hook uses tokio::spawn to commit
without blocking the loop.
§Wiring
ⓘ
let mem: Arc<dyn Memory> = Arc::new(FileMemory::open("~/.harness/mem.jsonl")?);
let loop_ = AgentLoop::new(model)
.with_guide(Arc::new(MemoryGuide::new(mem.clone()).with_top_k(5)))
.with_hook(Arc::new(MemoryWriter::new(mem)));Structs§
- Memory
Guide - Guide that recalls relevant prior memories and injects them into
ctx.guidesas aBlock::Textfor the model to see. - Memory
Synthesizer - Smarter alternative to
MemoryWriter— distil the session’s assistant turns into 1..=max_factsatomic durable facts using a cheap “synthesizer” model, instead of persisting the verbatim final answer. - Memory
Writer - Hook that writes the final assistant text of every successful run back into long-term memory.