Corpus Agentis
The field book to agent ecosystems
The field book to agent ecosystems
Memory · Harvest

How memory is written & ingested

The write pipeline. Raw conversation in, durable memory out: extract candidates (multi-pass), verify them, classify into a schema, dedup by content-address and supersede stale values: before anything is persisted. Each pattern is sourced to a framework doc, a first-party engineering post, or an arXiv paper.

Content-Addressed ID + Dedup

Write
Hash (e.g. SHA-256 of session+role+content) becomes the row id; INSERT OR IGNORE silently skips duplicates: re-ingesting a conversation is idempotent.
Trade-off
Exact-duplicate only, near-duplicate paraphrases still slip through.
Cloudflare Agent Memory

Multi-Pass Extraction

Write
A full pass chunks the conversation (concurrent) for broad coverage; a detail pass runs overlapping windows to catch concrete values (names, prices, versions); results merge.
Trade-off
Multiple LLM passes per conversation, extraction cost scales with length.
Cloudflare Agent Memory

Verification Gate

Write
Before commit, run entity / temporal / relational / support checks on each candidate memory → pass, correct, or drop.
Trade-off
A weak gate lets hallucinated or unsupported "facts" into permanent memory.
Cloudflare Agent Memory · Scalarity admission pipeline

Classification Routing

Write
Classify each memory into its schema (fact / event / instruction / task) and route storage + indexing accordingly: e.g. tasks stay out of the vector index.
Trade-off
Mis-classification sends a memory to the wrong index and retrieval path.
Cloudflare Agent Memory

Write-Time Fact Extraction (ADD/UPDATE/DELETE)

Write
An LLM extracts atomic facts on write and reconciles vs. existing memory as ADD / UPDATE / DELETE / NOOP.
Trade-off
Extra LLM call per write; extraction or conflict-resolution errors corrupt the store.
Mem0 · LangMem (memory managers)

Supersession (version chains)

Write
A new memory with the same key supersedes the old via a forward-pointer version chain rather than deleting it; superseded vectors are pruned in parallel with new upserts.
Trade-off
Version chains grow unbounded without compaction; stale pointers if pruning lags.
Cloudflare Agent Memory · Mem0

Summarization / Compaction

Both
Roll older conversation history into a running summary to stay within the context window.
Trade-off
Lossy, fine-grained detail is irrecoverably discarded into the summary.
MemGPT (recursive summary) · LangChain summary memory · Claude compaction

Reflection / Self-Edit

Write
The agent reflects on past experience and rewrites its own memory blocks or system prompt.
Trade-off
Compounding drift, bad self-edits propagate and degrade future behaviour.
LangMem (prompt optimizer) · Letta (self-editing) · Generative Agents

Lifecycle Hooks (pre / post-message)

Both
Read/write memory at fixed points in the agent loop: before prompt assembly, after the response.
Trade-off
Hot-path writes add per-turn latency; rigid trigger points can fire at the wrong time.
LangMem (hot-path) · LangGraph store hooks
Field notes

Extract, verify, classify, dedup, supersede: the write pipeline

Harvest is the write path: what gets remembered, when, and in what form. It is the least-specified part of most agent stacks and the one that quietly determines everything downstream.

Show more

Write too much and retrieval drowns in noise; write too little and the agent has no continuity. The approaches that hold up extract structured facts at the end of a run rather than storing raw transcripts, because a log is cheap to keep and expensive to search.

From the corpus, curated by Brandon Chaplin
Common questions
How does an agent decide what to remember?

An extraction step reads the conversation and pulls out the parts worth keeping as separate facts, instead of storing the whole transcript. Each candidate is checked, given a type, and only then written. Everything else is dropped or left in the raw log.

Should I store the whole conversation or just extracted facts?

Both, for different jobs. Raw transcripts are cheap to keep and useful when debugging, but noisy and expensive to search. Extracted facts are what the agent actually retrieves. Most stacks keep the log and index the facts.

When should memories be written, during the conversation or after?

After the turn, or at the end of the run. Extracting mid-turn adds latency to the reply the user is waiting for. Running it after the response, or as a background job, keeps the conversation fast and lets the extractor see the whole exchange.

How do you stop duplicate memories piling up?

Derive each record's id from a hash of its content, so writing the same thing twice does nothing. That catches exact repeats only. Near-duplicates worded differently need a separate pass that compares meaning and then merges or replaces.

What happens when a new memory contradicts an old one?

The write step should settle it rather than store both. The usual approach is to look up existing memories on the same subject first, then explicitly add, update or delete. If contradictions are allowed to accumulate, retrieval returns both and the model picks one at random.

When should a conversation be summarised?

Once the history grows longer than is useful to keep word for word. Older messages fold into a short summary that stays in context while the raw turns move to storage. It keeps the gist inside the context window at the cost of detail you cannot recover.

Next in the learning path