Session state is not memory

Lesson 4 of 5 in Sessions and Streaming: The Conversation Plumbing.

“Our agent has memory — we keep the thread.” No, you have a transcript.

Session state and memory are different layers with different lifetimes, different owners, and different failure modes. A transcript is an append-only record of what happened, sorted by time, complete by definition. Memory is a curated store of what turned out to be worth keeping, retrieved by relevance, lossy on purpose. One is a log; the other is an editorial decision.

The confusion has a cost, and it is measured in dollars and wrong answers. Replay a 40-turn transcript into every context window and you pay for 40 turns of tokens on every single call, you bury the current question under stale detail, and at turn 200 you hit the wall regardless of how large the window is. Meanwhile the one fact that actually mattered — the customer is on the enterprise plan — is on turn 3, competing for attention with 197 turns of noise.

The state stack, by lifetime

  1. Long-term memory — lives across every session — curated

    Facts, preferences, and distilled conclusions written out of sessions and retrieved into them. Not automatic: something must decide what is worth extracting, how to index it, when it goes stale, and how to correct it. Deleting a session does not delete what was copied here — which is a privacy question with teeth. See context engineering and the retrieval machinery that usually implements it.

  2. Session / conversation state — lives as long as the interaction — durable, ordered, append-only

    The transcript: messages, tool calls, tool outputs, in order. Survives process restarts and reconnects because it lives in a database — yours or the platform’s. This is the layer subject to retention policies, deletion requests, and residency rules, because it is where the raw conversation actually sits.

  3. Run state — lives for one execution — transient, addressable

    Status, steps, pending tool calls, usage totals for a single execution of the loop. Addressable by run id, which is what makes cancellation, approval, and reconnection possible. When the run reaches a terminal status this layer is finished; only its outputs graduate into the transcript.

  4. Connection state — lives for one socket — disposable by design

    The SSE stream or WebSocket, its buffers, and your last-seen cursor. Assume it dies constantly: mobile networks, proxy timeouts, deploys, closed laptops. Nothing that matters may live only here — the moment it does, a dropped socket becomes data loss.

Read the stack downward and each layer’s job is obvious: memory decides what is worth knowing, the session records what was said, the run tracks what is happening, the connection carries what is arriving. Read it upward and you get the design rule: never let information exist only in a layer shorter-lived than its importance.

The practical version for context engineering: what you send the model on turn 41 should not be “the transcript” by default. It is a constructed context — the system prompt, retrieved memory, a summary of the older transcript, and the recent turns verbatim. The transcript is the raw material you construct from, not the thing you paste.

Myth: “The platform stores my thread, so my agent has memory”

Thread storage gives you durability and reconnection, not recall. It replays everything, in order, forever — the opposite of what memory does. Recall requires extraction, indexing, retrieval by relevance, and staleness handling. Notice that platforms tend to ship both and keep them separate: a durable conversation history is one product surface, a memory or state store is another.

Myth: “Bigger context windows make this a non-problem”

Bigger windows change the failure mode from an error to a bill plus a quality regression. You still pay per token on every call, latency still grows with input size, and relevant facts still get diluted by irrelevant ones. A million-token window is a reason to be thoughtful about what you put in it, not permission to stop thinking.

Myth: “Deleting the session deletes the data”

Only for that layer. Facts extracted into long-term memory, embeddings written to a vector index, events in your durable log, spans in your observability backend, and platform-side copies all persist independently. If you promise a user erasure, you owe them a deletion path through every layer of this pyramid — and you cannot write that path if you do not know which copies exist.

Myth: “Session state and memory can share one store, it is all just history”

They have opposite access patterns. Session state is read whole, in order, by one session id — an append-only log. Memory is read by similarity or key, across sessions, with updates and corrections. Merging them produces a store that is slow for one job and wrong for the other, and it makes per-user deletion far harder than it needed to be.

Interactive flashcard deck.

Interactive checkpoint quiz (2 questions) — open this page in a browser to take it.