Module 1 · Prompts as the Foundation of Computation · scripted
An LLM Has No Memory
Overview
When we have a conversation with a large language model, it appears that the LLM remembers what we said earlier — and we hear people talk about LLM "memory" all the time. But LLMs have no memory. In this lesson, we learn how structuring prompts as conversations gives LLMs the illusion of memory.
A pure function
How can something with no memory hold up its end of a conversation? Start with what an LLM actually is. 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.
Controlling hallucination
Controlling hallucination is about telling the LLM what to do when there is insufficient information in the conversation.
Conversation consistency
There is a second lever, and it points inward. We can require the LLM to reference the conversation itself — not the outside world — as the support for what it says.
Conversation consistency
Instructing the LLM to reference the part of the conversation that supports its output produces less hallucination.
And it makes mistakes easy to detect: a "direct quote" that does not appear anywhere in the conversation is simple to check for.
Watch the difference. First, a question with nothing in the conversation to reference:
Which of Jules White's papers are related to prompt engineering?
Jules White has written several papers on prompt engineering, including "Conversational Prompt Programming: Design Patterns for LLM Applications" (2023) and "Prompt Engineering Strategies for Software Developers" (2022).
Now a new conversation. The papers are placed in the conversation, and the answer must quote them:
Here are the papers I have written:
"A Prompt Pattern Catalog to Enhance Prompt Engineering with ChatGPT" (2023)
"ChatGPT Prompt Patterns for Improving Code Quality, Refactoring, Requirements Elicitation, and Software Design" (2023)
"Improving the Reliability of Mobile Software Systems through Continuous Analysis and Proactive Reconfiguration" (2009)
"Creating Self-healing Service Compositions with Feature Models and Microrebooting" (2008)
Which of these papers are related to large language models? For each one, provide the full title as a direct quote from the list above.
Two of the papers are related to large language models:
"A Prompt Pattern Catalog to Enhance Prompt Engineering with ChatGPT"
"ChatGPT Prompt Patterns for Improving Code Quality, Refactoring, Requirements Elicitation, and Software Design"
The quotation requirement does two things. It forces the response to be strongly consistent with what is in the conversation — the model is referencing the prompt it was given, not the open world, and that alone makes invention much less likely. And it gives us a detector: if the response ever "quotes" a title that is not in the conversation, we can find that with a simple text comparison — no expertise required. The conversation is the record, and the response must stay consistent with the record.
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.