Agents are also dreaming and you have to learn how OpenClaw does it NOW !!
Most of what an agent writes in a day should be forgotten. OpenClaw runs a night job that decides what stays, and calls it dreaming
- openclaw
- memory
- agents
- dreaming
This is the follow-up to my previous blog on how memory works in OpenClaw. If you don’t understand memory, this one will be a little harder to follow, but I have tried to make it as beginner-friendly as possible.
Checked against OpenClaw commit 15e5f75. The code behind the night job lives in extensions/memory-core/src/memory/ (for example mmr.ts, the variety filter).
Why dreaming matters
Our brain is a little weird. I don’t know if this happens to you, but I don’t really remember the fifth reel I watched 10 minutes ago, yet I absolutely do remember the fist bump Spider-Man gave his best friend Ned in Brand New Day iykuk
Here is how it happens. Apparently, the part of the human brain that captures experiences is the hippocampus. It replays the really memorable ones and puts them into the neocortex, the part of the brain that remembers things for a long time.
Agents are trying to replicate this behaviour, because an agent or a chatbot with no memory is just predicting the next word with no context, lol. OpenClaw’s answer is a job that runs at night, and it calls it dreaming.
Two memories, and a filter between them
Short-term memory is what the agent has today which contains the chat and the daily notesdaily noteOne Markdown file per day, like memory/2026-11-21.md, where the agent writes what it thinks might matter. Short-term memory. whereas long-term memory is MEMORY.mdMEMORY.mdThe agent’s long-term memory: a small file of lasting facts, loaded at the start of every session.
Dreaming is the night job that moves some facts from the first into the second . It is a filter and most of them do not get through.
What can get through
Three kinds of things get through.
- Things that keep showing up in the notes which are said or written again and again or coming back on different days . Each night the job reads the notes and counts how often the same fact appears . A fact is one thing the agent was told or learned, written as one bullet or one short line . having it once is like noise but if that keeps coming back then it’s a pattern, and it earns a place
- When you tell an agent to remember they usually do and they do it by writing it in their
MEMORY.mdor the daily notes . If it is inMEMORY.mdit skips the filter or if it goes into the day’s notes , it still has to get through the night job - Something the agent keeps looking up in its own notes is a very important sign that it is important , Every time the agent searches its notes or earlier chats and gets a result back that counts for it , The more different questions that find the same thing , the stronger its case for long-term memory
It all happens at night
The job runs once a night, in three steps, always in this order: Light, REM and Deep
Light collects , REM reflects , Deep decides
At night, only Deep can write to MEMORY.md
Writing something into it is called promoting it
every night · 3 AM
Scenario 1 follows one fact through a day and a night Our example fact is “Sam uses pnpm instead of npm” By the end you will know why some facts reach MEMORY.md and some do not
The day: three questions, one chunk
It is the first day. During the day the agent wrote our note into memory/2026-11-21.md:
1 ## Tooling
2 - Sam uses pnpm instead of npm.
3 - Sam prefers TypeScript for new projects.
4 - Sam maintains a research diary on agent memory.
During the day the agent is asked three questions about Sam:
- “Which package manager does Sam use?”
- “What language does Sam prefer for new projects?”
- “Does Sam keep a research diary?”
Every time, the agent runs a retrieval searchretrieval searchThe search the agent runs over its notes (memory_search). It finds chunks by meaning and by keywords and returns the best ones. , which uses the memory_search tool from Part 1. Our note is tiny, so let us assume the chunkchunkA slice of a note, cut by size by the search index. is the first four lines, all in one chunk, and every search returns it.
Each time the agent retrieves, a mark is left on a card. A card is a small record about a piece of text. Here it holds the text of the retrieved chunk. The cards live in a table that OpenClaw keeps for the night job, called the scorecard.
Everything on a card is recognised by a fingerprint: a short code made from a text with a hashing algorithm. The same text always gives the same code. The retrieved text gets one, and so does each question that found it, and the question fingerprints are added to the card as well.
Here is what happens for the first question:
- The search returns the chunk, let us say they are from line 1 to 4 and the agent reads it
- OpenClaw fingerprints the question:
c7d78de309ec, It also fingerprints the chunk text:e8da85ded994 - It looks for an existing card for this chunk and finds none yet , because nothing has been stored so far Scenario 2There is one more check at this step, which we go through in Scenario 2.Click to jump there →
- So a card is made for the chunk named after the lines it spans :
memory:memory/2026-11-21.md:1:4is the chunk card. It gets one search mark whose count says a search returned this card , and it stores the question fingerprint so that it can count different questions that retrieved this card
The second question returns the same chunk , OpenClaw finds the same card by its lines and adds another search mark and another question fingerprint to it. So does the third. Both fingerprints are kept on the card. Light uses the chunk one tonight.
Know more Is anything else written down?
Yes. Behind the scenes, the full question, the lines and the score are also written to a search log. Deep never reads it.
At the end of the day the scorecard holds one card which is the chunk card, with 3 search marks and 3 different questions
Three facts in one chunk is only our example. A chunk can hold one fact, many facts, or part of one, and the same steps run for every chunk Scenario 2Scenario 2 shows a fact that sits in two chunks at once.Click to jump there →
Three questions, three searches, one chunk returned each time, so every mark lands on one card.
The night: Light collects
At 3 AM the night job starts, and Light goes first and does the following:
- It reads the notes and turns each fact into a card
- It gives a small bonus to the cards used recently
Notes into fact cards
Light reads the daily notes from the last 14 days, so it can spot a fact that comes back on different days. It cuts each note by meaning, one bullet is one fact, with its heading put in front. Each fact gets a card, named after the fingerprint of the fact.
Light also reads the chat transcriptschat transcriptThe raw record of a conversation: who said what, in order. from the last 2 days. Here only real conversations count, other calls like background jobs and tool outputs are left out. A line from a chat is handled like a bullet from a note, so it also gets a card and a note mark.
Cards come in two kinds:
- A fact card is made by Light from a note. It is one fact in one card, named after the fingerprint of the fact.
- A chunk card is made by a search during the day. It is one chunk in one card, named after the file and the lines it covers.
A new fact card gets one note mark, a count that says Light found this text in a note.
Before it makes a card, Light checks whether a card with this fingerprint already exists, and whether it is a fact card or a chunk card. If there is one, it adds a note mark to that card. If not, it makes a new one.
Now our example. From here on, “tonight” means the night that follows our example day. Tonight there is only our note, and to keep it simple we leave the chats out. The searches from the day made the chunk card, so Light now makes the fact cards. The pnpm fact, “Tooling: Sam uses pnpm instead of npm.”, becomes the fact card memory:claimclaimOpenClaw's own word for a fact. A fact card in this post is a claim card in OpenClaw's code, so a claim is the same thing as a fact. :15d81bfe570b.
As you can see in the figure below, the chunk card’s fingerprint is for all three facts together, so it matches none of the single facts, and Light makes three new cards. Scenario 2Scenario 2 shows when a chunk card and a fact card can share a fingerprint.Click to jump there →
Light: one bullet = one fact, heading in front
Ticks for recent cards
Light’s other job is the ticks. A tick is a small bonus point.
It gives a tick to every card used in the last 2 days, be it a chunk card or a fact card. Tonight that is all four: the chunk card and the three new fact cards. If several cards from the same note said nearly the same thing light would count them as one . In our case three facts say different things so each of them gets their own tick
A tick adds a little to a card’s score and never counts as a mark BelowThe score section shows how much a tick adds, and what the card would score without itClick to jump there →
Marks count toward Deep’s rules. Ticks only add a little to the score.
The night: REM reflects
REM is named after the dreaming part of sleep, when the brain replays the day. OpenClaw’s REM looks back over the cards from the last 7 days and does the following:
- It looks for themes across the cards and writes them into the dream diary
- It leaves a tick on the cards it is sure about
It looks for topics that show up across several cards. A strong topic becomes a theme, and REM writes it into the dream diary. Themes go to the diary and nowhere else.
The dream diary is a file, DREAMS.md, written for you to read. Each night it gets a short entry with REM’s themes and what was promoted. Nothing in the night job reads it back.
REM leaves a tick on the cards it is sure about. REM judges a card on part of what Deep will judge it on, so a card REM is sure about is one that already looks strong. Tonight that is the chunk card, which three questions found today. The three fact cards get none. BelowThe score section lets you switch this tick off to see what it changes.Click to jump there →
REM writes the diary and leaves ticks. Deep still decides.
The night: Deep decides
Deep reads every card and uses the same ruler for all of them. It does the following:
- It gives each card a score
- It keeps only the cards that pass three rules, and writes them into
MEMORY.md
The score
The score blends six parts:
- how well the searches matched ?
- how many marks the card has ?
- how many different questions found it ?
- how recently it was used ?
- how many different days ?
- how many topics it touches ?
Ticks add a bonus on top. A card needs at least 0.75 to pass. BelowThe three rules, and what the 0.75 means, are covered in the next section.Click to jump there →
Here is our chunk card tonight. Watch it climb, part by part.
score 0.764
passes 0.75short of 0.75
- match strength+0.255
- how often+0.139
- different questions+0.090
- how recent+0.147
- days used+0.020
- topics+0.060
- Light tick+0.021
- REM tick+0.032
six parts 0.710 under the line
ticks +0.053
for our case the six parts add up to 0.710 , short of the line. The Light tick adds 0.021 and the REM tick adds 0.032 , which makes 0.764. If we switch the REM tick off, the card drops to 0.731, so the pass is thin and REM is what got it over
The three rules
A card is promoted only if it passes three rules, checked in this order:
- at least 3 marks
- at least 3 different questions
- a score of at least 0.75
A few more things about how Deep applies them:
- A card that fails a rule is not checked against the next one
- By default Deep checks every card that has not been promoted yet, however old the card is
- If an age limit is set, OpenClaw skips cards that are too old and scores the others
- Deep promotes at most 10 cards a night. If more pass, only the 10 with the highest scores are promoted
Our example tonight
Tonight Deep checks all four cards. The chunk card passes. It has 3 marks and 3 different questions, and its score is 0.764. Each fact card has 1 mark and no questions, so it stops at rule 1. It would score between 0.47 and 0.51 but Deep never gets that far to check it
Notice what this means: a fact that shares a chunk with others is promoted with them or not at all. Scenario 2The one exception is a note that is a single plain line. Scenario 2 covers it.Click to jump there →
- Search marks land on the chunk card, because a search returns a whole chunk. Each fact card only gets its one note mark and no questions, so in almost every case it cannot reach 3 marks on its own, however often you ask about it.
- So only the chunk card can pass. If it does, the text written into
MEMORY.mdis the text of the whole chunk, so all three facts are expected to go in together, even the two nobody asked about. In our example, “Sam prefers TypeScript” and “Sam maintains a research diary” are promoted along with the pnpm fact. - If the chunk card fails, none of the three get in, because the fact cards stop at rule 1.
What happens after a card passes
Passing is not the end. Next:
- OpenClaw checks that the source file has not changed
- A model decides what to do in
MEMORY.mdit add a new line, merge it with a line that is already there or supersede an older line which means replace one that the new line makes out of date - Every line it writes carries a source reference
- The card is stamped with a promoted date and later nights skip it . If a search finds the same text again then the card still collects marks , but Deep ignores it because the text is already in
MEMORY.md
Deep never asks which fact the question was about . It only asks which card got the mark Scenario 2Scenario 2 shows what this means when chunks overlap.Click to jump there →
Scenario 2: when facts and chunks overlap
In Scenario 1 one chunk held three facts, so the chunk card and the fact cards never met. Notes are not always like that. Here are two cases where facts and chunks line up differently.
A chunk that is exactly one fact
So far a chunk held three facts, which is why the chunk card and the fact cards never met. There is one case where they do meet: a chunk that is exactly one fact.
Take a note that is one plain line: “Sam uses pnpm instead of npm.” The chunk and the fact are the same text, so they have the same fingerprint. This only happens when the whole note is that one line.
Which card is made first depends on what happens first, the search or the night job:
-
The search comes first. It makes a chunk card, keeps the text fingerprint on it and gives it a search mark. At night, Light cuts the same line and gets the same fingerprint. It finds the chunk card and adds its note mark there. It does not make a second card.
-
Light comes first. It makes the fact card. On the next search, OpenClaw fingerprints the chunk it returns. It compares that fingerprint with the chunk cards, as we saw above, and also with the fact cards. Here it finds a match on the fact card, so it adds the search mark there.
Either way there is one card , holding both the search marks and the note mark. Search cuts by size and Light cuts by meaning , but when the text is the same, they meet on one card. That card can then reach 3 marks and 3 questions, so this fact can be promoted on its own.
This is the only way a fact card can get promoted on its own, but it is very rare, because the note’s heading is usually added along with the fact, so the fingerprints seldom match.
We tested four tiny notes as an experiment:
| Note shape | Does the fact card get the search mark? | Why |
|---|---|---|
| one plain line, no heading | yes | the chunk text equals the fact text |
| one bullet | no | the chunk keeps the dash, the fact does not |
| a bullet under a heading | no | the fact has the heading in front |
| three bullets | no | the chunk is three facts, the fact is one |
Only the first row meets. In the other three the chunk text and the fact text differ in some small way, so the fingerprints differ and the two cards stay apart.
Why is that so rare? It comes down to how the search index cuts files:
- Only
MEMORY.mdandUSER.mdUSER.mdAn optional long-term file for your stable preferences and writing style, loaded at session start. are cut one bullet at a time - Daily notes are cut by size, not by bullet, so a chunk almost always holds several facts
- So almost every search mark lands on a chunk card, not a fact card
- The night job never collects marks from
MEMORY.md: what is there is already long-term
Deep only opens MEMORY.md at the very end, to decide whether to add the new line, merge it with an old one, or let it replace one.
A long note, cut into several chunks
A long day makes a long note . The index cuts it by size and neighbouring chunks overlap. Take a note of about 900 tokenstokenA word-piece. In English, about four characters. as in Part 1:
- chunk 1 covers tokens 0 to 400
- chunk 2 covers tokens 320 to 720
- chunk 3 covers tokens 640 to 900
A fact that sits in tokens 320 to 400 appears in two chunks. The ranges are an illustration, since we have not confirmed the exact cut.
Each chunk gets its own card, named after its lines. A question about that fact matches both chunks, so a search returns both, and a search gives one mark and the question’s fingerprint to every chunk it returns. So both cards collect the same marks, and if the fact is asked about in three different questions, both can reach three search marks and three questions. A card misses only if a search leaves its chunk out because it scores under the minimum or falls outside the top 6 of the hybrid searchhybrid searchMeaning search and keyword search run together, then blended into one score. .
Three questions about the fact. Each returns chunks 1 and 2, so both cards can reach three.
Here is each mark, search by search. The fact is in both chunks, so both chunks score well for a question about it and both clear the minimum score. Each search returns both and each returned card gets one search mark and that question’s fingerprint.
| Search | Returns chunk 1? | Returns chunk 2? | Chunk 1’s card after | Chunk 2’s card after |
|---|---|---|---|---|
| 1st question about the fact | yes | yes | 1 mark, 1 question | 1 mark, 1 question |
| 2nd question about the fact | yes | yes | 2 marks, 2 questions | 2 marks, 2 questions |
| 3rd question about the fact | yes | yes | 3 marks, 3 questions | 3 marks, 3 questions |
Chunk 3 does not hold the fact, so these questions do not return it and it gets no mark.
Where this leaves us
So the night job is three phases working on one set of cards. Light collects, REM reflects, Deep decides.
- During the day, every search leaves a mark
- At night, Light adds note marks
- Light and REM add small bonus ticks
- Deep promotes the cards that have enough marks, enough different questions and a high enough score
We kept to one day and one night. On later days the cards keep collecting marks, and a card that falls short tonight can pass on another night.
What OpenClaw calls it. The docs and the code use other names for the words in this post.
| In this post | In OpenClaw |
|---|---|
| night job | dreaming |
| card | recall entry |
| scorecard | the recall store |
| fact | claim |
| search mark | a recall |
| note mark | a daily signal |
| tick | a phase hit |
| fingerprint | a hash |
| promote | promote |
My take
Honestly, I don’t think OpenClaw handles dreaming in the best way. One problem I feel is that fact cards almost never get to MEMORY.md on their own: a fact usually gets there only when the whole chunk is promoted with it, and it is very rare that one fact covers the entire chunk. But regardless, it was nice researching the OpenClaw codebase and decoding how it works .
but yeah thanks for reading this was a long one , I hope you learned something from this