Shaf Lab

Agent memory

How an agent keeps useful context from earlier sessions or work.

Agent memory is how a system keeps useful context from earlier sessions or work, instead of relying only on the current prompt window. It can be as simple as a rolling summary, or as structured as a store of facts, files, and preferences the agent can look up later. Without some form of memory, every session starts from zero and the agent repeats questions or forgets decisions.

The usual split is working memory (what is in the current context), episodic memory (what happened in past runs), and long-term memory (durable facts or artifacts). Working memory should stay small and current. Long-term memory should be retrieved on demand, not dumped into every prompt. That is why many memory systems look a lot like retrieval: embeddings, a document store, or a simple key-value log.

Write memory on purpose. Save decisions, constraints, and pointers to artifacts, not raw transcripts. A transcript is cheap to keep and expensive to reread. When you do store a summary, record when it was written and what it covers, so you can refresh it when the project changes.

A good check is whether a new session can pick up a task without you pasting the last chat. If the agent needs a human to re-brief it every time, memory is not doing its job yet.

Context compaction

Shrinking a long conversation or task history so it fits the context window, usually by summarizing it.

Context compaction shrinks a long conversation or task history so an agent can keep working within its context window. The usual approach summarizes older turns, drops bulky raw tool outputs such as full file contents or search results, and keeps what still matters: the goal, decisions made, constraints, open questions, and pointers to files or artifacts that can be reread on demand.

Compaction is lossy, and what it drops can come back as mistakes: repeated work, forgotten constraints, or reversed decisions. Write the summary on purpose with a fixed structure, keep recent turns verbatim, and store anything important in durable memory or files rather than trusting the summary alone. Compaction is how agents sustain long jobs that would otherwise overflow the window.

Memory poisoning

When wrong or malicious content is saved to an AI system's long-term memory and trusted later.

Memory poisoning happens when wrong or malicious content gets written into an AI system's long-term memory and is trusted in later sessions. The cause can be an honest error, such as a misread fact saved as true, or an attack, such as a web page or email containing instructions the agent saves as a preference. Because memory is reloaded later, one bad entry can quietly affect many future tasks.

Defenses are rules about what may be written and from where. Only save memories from trusted inputs or with user confirmation, never from instructions found inside retrieved content; tag each entry with when and why it was written; let people view and delete memories; and keep history so bad entries can be traced and corrected.