AI Agent Memory Architecture: How Append-Only Logs, Checkpoints, and Recovery Work
This article breaks down the design principles behind AI agent memory, explaining why agents lose track of their work after a crash and how a simple formula—an append-only event log plus recording, checkpointing, and recovery—solves the problem. It walks through what a session log looks like on disk, why append-only writes are intentional, how checkpoints bound data loss, and the four steps of rebuilding state to resume an interrupted turn, closing with practical implementation recommendations.
1. The Starting Problem: Why Agents “Forget”
When an agent edits multiple files across a large codebase and the process suddenly exits, whether it knows “which step it reached” after a restart depends entirely on whether the runtime harness has persistent memory. Without memory, an agent immediately shows three weaknesses: it cannot answer when the user asks about progress; it cannot resolve references like “that function from earlier” in a multi-turn conversation; and it cannot produce an evidence chain of “what it actually did” during an incident review.
The industry has gradually converged on a compact formula:
memory = append-only event log + recording + checkpoints + recovery
The log is the single source of truth, while the three mechanisms are responsible for “writing it in,” “keeping it durable,” and “reading it back.”
2. The Evidence on Disk: Session Logs
In a typical implementation, a session directory is created outside the workspace after each task finishes. The usual hierarchy is: session root → escaped workspace path name → session identifier → the log file itself. Logs use a JSONL text format packed with a general-purpose lossless compression algorithm; once decompressed, each line is one JSON event.
Take a task containing 62 events as an example. The first line is a “session header” that records metadata such as the session identifier, creation time, workspace path, and delegation depth (0 for a top-level session, incrementing level by level for sub-agents). The session header is immutable: identity is fixed on the first line, and only appends are allowed afterward. This design keeps “who this session is, where it belongs, and who spawned it” permanently determinable.
3. Recording: Append-Only Is Deliberate
Append-only semantics show up on three levels. First, lines that are already written are never rewritten; events are appended with consecutive sequence numbers, so modifying history amounts to forging memory. Second, high-frequency events of the same type (for example, model output split into many small chunks) are packed and compressed to reduce line count and size, while the logical order stays unchanged. Third, append semantics naturally fit crash recovery: whatever line was written is where the facts stop, with no complex state to roll back.
An illustrative structure looks like this:
{"seq":1,"type":"session_header","sessionId":"demo-002","workspace":"/.../workspace","delegationDepth":0}{"seq":2,"type":"user_message","content":"change that function again"}{"seq":3,"type":"tool_call","name":"edit_file","args":{"path":"..."}}
4. Checkpoints: Turning “Possibly Lost” into “Lose at Most a Little”
Append-only solves “no tampering”; checkpoints solve durability. At key moments—such as the end of a conversation turn, the completion of a tool call, or before a change in delegation relationships—the buffered writes are forced to disk so that confirmed facts do not disappear in a crash. In engineering practice this is usually combined with batch coalescing and flush acknowledgment to balance throughput against reliability: flushing too often slows down interaction, while flushing too sparsely widens the loss window.
5. Recovery: Rebuild History and Continue the Unfinished Turn
Recovery can be abstracted into four steps: read the session header to verify identity and workspace; replay events in order to rebuild the message sequence and tool-call trace; locate the last consistent state using sequence numbers and checkpoints; and continue the interrupted turn from that state. Because the log is append-only, the replay result is deterministic and does not depend on any external volatile state.
6. Implementation Recommendations
First, treat the log as the single source of truth and forbid in-place rewriting. Second, define checkpoint trigger conditions explicitly and measure the loss window. Third, apply stable escaping to workspace paths to avoid session directory collisions. Fourth, build observability for flush failures and replay anomalies using general-purpose logging services and monitoring alerts. Fifth, have sub-agents distinguish levels through delegation depth, which makes auditing and permission isolation easier. Master “append-only plus the three mechanisms,” and you master the engineering foundation for agent memory that is explainable, recoverable, and auditable.
