Station 6 · Agent Memory
An agent's context window is a small, disappearing whiteboard — it fills up and wipes clean every session. Memory is how the agent keeps hold of what it did five steps ago, and who you were last week.
What you'll walk away with
Concept 1
The LLM only "sees" what's inside its context window — the block of text (the prompt) it reads before answering. That window is limited and it resets. Nothing is remembered automatically.
Your working memory holds a phone number just long enough to dial it — then it's gone. That's the context window. A notebook is where you write things down so you can flip back to them days later. An agent needs both: the fast whiteboard and the notebook it can reach for when the whiteboard runs out of space.
Concept 2
The cleanest way to split agent memory is by where it lives: inside the current prompt, or stored somewhere outside it.
The current conversation — everything sitting in the context window right now. Instant to use, but limited in size and gone when the session ends.
Saved outside the model — a vector database, a SQL table, or a custom store. Nearly unlimited, survives across sessions, and is pulled back into the window only when relevant.
The key move is retrieval: long-term memory doesn't live in the prompt, so the agent must search its store, find the relevant piece, and paste it into the context window before answering. That "search and paste it back in" step is exactly the RAG pattern you met with embeddings in Station 2.
Concept 3
Long-term memory comes in two flavors, borrowed from how psychologists describe human memory.
Specific events that happened. "Last Tuesday you asked me to book a flight to Denver." Time-stamped, personal, story-shaped.
General facts the agent has learned or been told. "You're vegetarian." "Your company uses Python." No date attached — just true things.
Memory turns a stateless model into something that feels like it knows you. Episodic memory lets it say "last time we tried X…"; semantic memory lets it skip questions it already has the answer to. Both are just text the agent retrieves and drops back into the context window.
Concept 4
A store isn't magic. Real agents lean on four techniques to keep memory useful without blowing past the context limit.
Concept 5
Here's the whole loop as pseudocode. Watch the token spans on the right — that's how much of the limited context window each step consumes.
# --- SESSION 1: the agent learns something and stores it --- remember("User is vegetarian and lives in Austin.") # → embed to a vector, save in the store [~12 tokens, lives OUTSIDE the window] # ...days later, brand-new session, context window is empty again... # --- SESSION 2: user asks something related --- user = "Find me a good dinner spot for tonight." [~9 tokens] Thought → "What do I already know about this user?" Action → recall(user) # search the store Observe → "User is vegetarian and lives in Austin." [~12 tokens pulled BACK in] Answer → "Here are 3 vegetarian spots in Austin..." # prompt sent to the model = system + user + recalled memory # total ≈ 33 tokens — tiny, because we retrieved only what mattered
A bad agent carries every past conversation in its backpack (the prompt) until it can't lift it. A good agent works like a librarian: the archive is huge and off to the side, and when you ask a question they walk over, pull the one book you need, and bring it to the desk. Retrieval beats hoarding.
Checkpoint
Your agent needs to recall a user preference from a chat three weeks ago. Where does that live, and how does it get used?
The context window reset weeks ago, so the preference can't still be "in" it. It only survives if it was saved to long-term memory outside the model. To use it, the agent searches that store (RAG), finds the match, and drops it back into the current prompt — the store-then-retrieve loop.
See it yourself — 5 minutes
Open an AI tool that has a memory feature (ChatGPT's "Memory", or Claude with projects/instructions) and probe it:
Recap. The context window is short-term memory — fast, small, and wiped every session. Long-term memory lives outside the model in a vector DB, SQL, or profile store, split into episodic (events) and semantic (facts). Agents keep it usable with RAG retrieval, user profiles, summarization, and forgetting — always the same move: store outside, retrieve the relevant bit, paste it back into the window. Next, we zoom out to how these pieces get wired together.