While learning about AI agent architecture, one idea cleared up a lot for me: agent memory isn't one thing. It's four, and they all end up as text in the model's context window, which is why people mix them up.
The two questions that separate them are who writes it, and how long does it live?
I'll use the WhatsApp lead qualification agent I built as the example.
1. Working context is everything the model sees on one single call: instructions, recent messages, tool results, retrieved text. It's rebuilt every time and gone when the call ends.
2. Session state is the conversation so far, saved under a thread ID. When a lead says "I want a 2-bed flat", it's remembered here for the rest of the chat. Your code decides the thread ID (a phone number works well for WhatsApp), so the agent can pick up the same conversation later.
3. Long-term memory is what the agent decides to keep across conversations, like "moving in March" or "budget around X". The agent writes it itself, at runtime.
4. Knowledge (RAG) is reference material like a cancellation policy or property details. Your team writes it, a pipeline indexes it, and the agent only reads it.
So the difference between memory and RAG is simple. With RAG, your pipeline writes and the agent reads. With memory, the agent writes and the agent reads.
Two things to plan for before going live:
Threads get expensive. The model doesn't remember anything on its own. Every reply sends the whole saved conversation again, so a long thread costs more and responds slower with every message. In testing it feels cheap because chats are short. In production, with many leads chatting on and off for weeks, it adds up. Limiting how many past messages are loaded, and saving key facts (budget, preferences) separately, keeps the cost steady.
Long-term memory is a write path. If the agent reads something untrusted, like an email or a web page, and "remembers" an instruction from it, that instruction can come back in every future conversation. Save where each memory came from and when, scope it per user, and let users see and delete what's stored.
My takeaway: before handing an agent to a client, ask "what happens to this after three months of running?" If the answer is "the thread just keeps growing", fix that first.
Which of these four have you used in your own builds? And have you hit the growing-thread problem yet? Tell me in the comments.