19 min read

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.

  1. 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
  2. When you tell an agent to remember they usually do and they do it by writing it in their MEMORY.md or the daily notes . If it is in MEMORY.md it skips the filter or if it goes into the day’s notes , it still has to get through the night job
  3. 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

1 Light collects reads the notes, makes fact cards, ticks recent cards Light collectsPhase 1. It reads the recent daily notes and chats, turns each fact into a card, and gives a tick to every card used in the last 2 days.
2 REM reflects writes the dream diary, ticks cards it is sure about REM reflectsPhase 2. It looks back over the last 7 days, writes themes into the dream diary for you, and ticks the cards it is sure about.
3 Deep decides scores every card, applies three rules Deep decidesPhase 3. It scores every card and promotes the ones that pass three rules. The only phase that writes to MEMORY.md.
long-term MEMORY.md the cards that pass PromotedWriting a card’s text into MEMORY.md is called promoting it.
HoverTap a part to read it in plain words.
Figure 1 The night job in three phases, always in this order. Only Deep writes to MEMORY.md.

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:

  1. The search returns the chunk, let us say they are from line 1 to 4 and the agent reads it
  2. OpenClaw fingerprints the question: c7d78de309ec , It also fingerprints the chunk text: e8da85ded994
  3. 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 →
  4. So a card is made for the chunk named after the lines it spans : memory:memory/2026-11-21.md:1:4 is 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 →

chunk card memory:memory/2026-11-21.md:1:4 the whole note, lines 1 to 4 (three facts) 3 3 chunk cardMade by the first search. Three searches returned this chunk, so it has 3 search marks and 3 question fingerprints (c7d78de309ec and two more).
no fact cards yet: Light makes them tonight Not yetSearches only make chunk cards. Fact cards come from Light, at night.

Three questions, three searches, one chunk returned each time, so every mark lands on one card.

HoverTap a part to read it in plain words.
Figure 2 The scorecard at the end of the day: one chunk card holds every mark.

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 →

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.

Light: one bullet = one fact, heading in front

Tooling: Sam uses pnpm instead of npm. fingerprint 15d81bfe570b card memory:claim:15d81bfe570b exists? no new fact card 1 note mark The pnpm factLight fingerprints the fact text and looks for a card with that name. There is none, so it makes one with a note mark.
Tooling: Sam prefers TypeScript for new projects. fingerprint 100e35a4f522 card memory:claim:100e35a4f522 exists? no new fact card 1 note mark The TypeScript factLight fingerprints the fact text and looks for a card with that name. There is none, so it makes one with a note mark.
Tooling: Sam maintains a research diary on agent memory. fingerprint 922e6f678c81 card memory:claim:922e6f678c81 exists? no new fact card 1 note mark The research diary factLight fingerprints the fact text and looks for a card with that name. There is none, so it makes one with a note mark.
if a card already exists Light adds one note mark to it instead, fact card or chunk card. A matchThis is how a fact that comes back on another day collects more note marks on the same card.
HoverTap a part to read it in plain words.
Figure 3 Light cuts the note by meaning: one bullet is one fact, with its heading put in front. Each fact becomes a card named after its fingerprint.

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 →

chunk card memory:memory/2026-11-21.md:1:4 the whole note, lines 1 to 4 (three facts) 3 0 3 Light chunk cardThe chunk card from the day. Light did not add a note mark (its text is three facts, which matches no single fact), but it ticked it.
fact card memory:claim:15d81bfe570b Tooling: Sam uses pnpm instead of npm. 0 1 0 Light fact cardMade by Light tonight from the pnpm bullet. One note mark, no searches yet, and a Light tick.
fact card memory:claim:100e35a4f522 Tooling: Sam prefers TypeScript for new projects. 0 1 0 Light fact cardMade by Light tonight from the TypeScript bullet. One note mark, no searches yet, and a Light tick.
fact card memory:claim:922e6f678c81 Tooling: Sam maintains a research diary on agent memory. 0 1 0 Light fact cardMade by Light tonight from the research diary bullet. One note mark, no searches yet, and a Light tick.

Marks count toward Deep’s rules. Ticks only add a little to the score.

HoverTap a part to read it in plain words.
Figure 4 The scorecard after Light: three new fact cards, and a Light tick on every card.

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.255How well the searches matched. Our three searches matched strongly, so this part is near its top. Most it can add: 0.30.
how often · +0.139How many marks the card has. Three is enough to pass the rules, but far from the top of this part. Most it can add: 0.24.
different questions · +0.090How many different questions found the card. Three different questions, so a good share. Most it can add: 0.15.
how recent · +0.147How recently the card was used. It was used today, so this part is almost full. Most it can add: 0.15.
days used · +0.020On how many different days the card was used. Only one day so far, so this part is small. Most it can add: 0.10.
topics · +0.060How many topics the card touches. The chunk holds three facts, so it touches plenty. Most it can add: 0.06.
Light tick · +0.021Light used the card in the last 2 days, so it gave it a tick. Most it can add: 0.06.
REM tick · +0.032REM was sure about the card, so it gave it a tick. Most it can add: 0.09.
  1. match strength+0.255
  2. how often+0.139
  3. different questions+0.090
  4. how recent+0.147
  5. days used+0.020
  6. topics+0.060
  7. Light tick+0.021
  8. REM tick+0.032

six parts 0.710 under the line

ticks +0.053

HoverTap a part to read it in plain words.
Figure 5 The chunk card’s score tonight. The six parts alone fall short of 0.75; the two ticks carry it over.

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

chunk cardmemory:memory/2026-11-21.md:1:4 3 marks 3 questions 0.764 promoted chunk cardPasses all three rules, so its text is promoted. All three facts go with it.
fact card · pnpmmemory:claim:15d81bfe570b 1 mark not checked not checked not promoted fact card · pnpmOne note mark and no questions, so it stops at rule 1. Its score would be 0.47 to 0.51, but Deep never gets that far.
fact card · TypeScriptmemory:claim:100e35a4f522 1 mark not checked not checked not promoted fact card · TypeScriptOne note mark and no questions, so it stops at rule 1. Its score would be 0.47 to 0.51, but Deep never gets that far.
fact card · research diarymemory:claim:922e6f678c81 1 mark not checked not checked not promoted fact card · research diaryOne note mark and no questions, so it stops at rule 1. Its score would be 0.47 to 0.51, but Deep never gets that far.
HoverTap a part to read it in plain words.
Figure 6 Tonight’s four cards against the three rules, checked in order.

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.md is 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.md it 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 shapeDoes the fact card get the search mark?Why
one plain line, no headingyesthe chunk text equals the fact text
one bulletnothe chunk keeps the dash, the fact does not
a bullet under a headingnothe fact has the heading in front
three bulletsnothe 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.md and USER.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. .

a long daily note · about 900 tokens
chunk 1 · 0 to 400 Chunk 1Tokens 0 to 400. Its last 80 tokens hold the fact.
chunk 2 · 320 to 720 Chunk 2Tokens 320 to 720. It starts by repeating the last 80 tokens of chunk 1, so it holds the fact too.
chunk 3 · 640 to 900 Chunk 3Tokens 640 to 900. The fact is not in it, so a question about the fact does not return it.
chunk 1’s card 3 search marks · 3 questions Chunk 1’s cardEach of the three searches returned chunk 1, so each one added a search mark and its question fingerprint.
chunk 2’s card 3 search marks · 3 questions Chunk 2’s cardThe same three searches returned chunk 2 as well, so it collected the same marks.
chunk 3’s card no marks Chunk 3Never returned by these questions, so it gets no mark.

Three questions about the fact. Each returns chunks 1 and 2, so both cards can reach three.

HoverTap a part to read it in plain words.
Figure 7 One fact in an overlap. Every question about it returns both chunks, so both chunk cards collect every mark. The token ranges are an illustration.

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.

SearchReturns chunk 1?Returns chunk 2?Chunk 1’s card afterChunk 2’s card after
1st question about the factyesyes1 mark, 1 question1 mark, 1 question
2nd question about the factyesyes2 marks, 2 questions2 marks, 2 questions
3rd question about the factyesyes3 marks, 3 questions3 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 postIn OpenClaw
night jobdreaming
cardrecall entry
scorecardthe recall store
factclaim
search marka recall
note marka daily signal
ticka phase hit
fingerprinta hash
promotepromote

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