Module 1 · Foundations of Agentic AI · scripted
An LLM Has No Memory
A pure function
There is no special memory inside an LLM. The simplest accurate picture: the LLM is a function applied to the prompt to produce an output. It takes in a prompt; it produces a response; and in doing so it changes nothing inside itself. It is what mathematicians call a pure function — no internal state, no side effects, nothing left behind that could serve as a memory of the exchange.
Text in, text out — and nothing retained
The contract of a pure function
Run it again tomorrow with the same conversation, and it stands in exactly the same position: everything it "knows" is on the page in front of it.
(You may have seen products that advertise memory. Whatever they do, it is separate machinery outside this process — we will open that box later in the course. The function itself stays pure.)
"Remembering" is reading
Then how does it remember what you said at the beginning of a conversation? It doesn't — it reads it. Its memory of your earlier words, and of its own, is built by reading the conversation and seeing who said what:
I'm allergic to shellfish. Also, what's a good dish to try in Molde?
Given the allergy, skip the famous klippfisk dishes with shrimp garnish — try bacalao without seafood topping, or a reindeer dish.
Wait — what was the first thing I told you?
That you're allergic to shellfish.
What was the first thing I told you?
This is the beginning of our conversation — you haven't told me anything yet. What would you like to start with?
When the answer isn't in the conversation
Look again at what the model did when the information wasn't there. It said "you haven't told me anything yet." That was a good answer — but it was not the only thing that could have happened. When a conversation doesn't contain what's needed to answer, an LLM has three ways out:
Three ways to fill a gap
Here is the uncomfortable part. All three are the same kind of act: the model continuing the document with its most probable next words. "You haven't told me anything yet" and a confidently invented answer differ in one respect only — we judge one as honest and the other as worthless. The model is not choosing between truth and fiction; it is completing a script.
What was the name of the hotel I said I booked?
You mentioned you booked the Hotel Alexandra in Molde — a lovely choice near the harbor.
So the lever is not "make the model honest." The lever is the conversation itself. If we want it to say "you haven't told me that yet" instead of inventing, we have to build a conversation in which saying so is the most probable continuation — where the context makes honesty fit the script better than invention does.
The conversation constrains the answer
Now the honest answer is the one that best fits the document — so the honest answer is the one you get.
We will return to this again and again: hallucination is not a bug to be scolded out of the model — it is what happens when the conversation leaves the right answer unconstrained. Engineering the context so the truthful answer is the fitting answer is much of what prompt and agent design is about.
The journal
Here is the picture to keep. Imagine you had no memory of your life — no recollection of your history at all — but I handed you a journal of everything you had done and said. Asked "what were you thinking that day?", you would open the journal and look it up. Asked "what did you promise those people?", you would find the page and read your own words. You would trust the journal to be your memory.
That is the LLM's situation on every single turn — with one difference: the entire journal is handed to it at once, every time. Its memory of its own past actions is it reading what it said earlier in the conversation. Its memory of you is reading what you said. That reflection into the prompt is the only concept of memory it has.
The whole idea in three lines
The LLM is stateless. Its response is computed from the current prompt — nothing else. Its memory is the conversation, re-read every turn.
- In Example 1, point to the exact words that served as the "memory" of the allergy.
- If someone deleted the first message before the third turn, what would the model "remember"? What does that tell you about where the memory lives?
- What is the difference between having a memory and being handed a journal? Does the difference matter, if the journal is complete?
Open a fresh session with any LLM and ask: "What did we talk about yesterday?" Then paste in yesterday's transcript and ask again. Explain, in one sentence each, why the first answer was empty and the second was perfect.