Skip to content
The AI Agent Factory

31.2 Two loops over one memory

Approved by
Panaversity ·
9 min read

In everyday life. A restaurant kitchen cooks all evening. Nobody stops service to rewrite the recipes. After closing, the head chef reads the night's orders and the plates that came back, and sees that three tables sent back the same dish as too salty. The next morning she changes the recipe card, tastes the new version, and only then puts it on the line. The cooks work the night; the chef improves the recipes the next morning, from many nights at once.

What you will learn. What the task loop and the dreaming loop each do, and why they share one memory but never write to it in the same way. You practise it in Lab 31, Task 2.

Why it matters. If the worker that does the job also has to keep its memory tidy, it splits its attention, and it can only see one day. Two loops give each job its own time and its own view.

What does each loop do?

The task loop does the work. It is the loop you built in 23.16, now with a memory. It runs often, every weekday morning for each company. It reads the published memory at the start, does the triage, and may leave small notes in a scratch folder of its own. Writing a note in the middle of a task is called writing in band.

The dreaming loop improves the memory. It runs on its own schedule, less often, here once a week. It reads the memory and many task sessions at once, and proposes changes. It works out of band: outside any task, with its own budget. A dream is the same kind of loop as the task loop. Its task is the memory itself.

Task loopDreaming loop
RunsEvery weekday, per companyOnce a week, or after a set number of sessions
ReadsOne published memory version, and that day's invoicesThe memory, plus up to a hundred past sessions
WritesSmall notes, in its own scratch folderProposals, in a separate folder. Never the published memory
SeesOne sessionPatterns across sessions, and across companies
Its budgetThe run's, $0.50Its own

Why not let the task loop keep its own memory?

Two limits, both from the talk.1 First, a worker that must finish the triage and also tend its memory splits its budget between them. There is no good rule for how much to give each. Second, a session can see only itself. Monday's session cannot know that the worker asked Luis about the same kind of NA- document on Wednesday and the next Monday too. A pattern that shows up only across many runs needs a job that reads many runs.

What kinds of loop are there?

Anthropic's loops article sorts loops by what the person hands off.2 The four kinds are new here. They build on loop engineering, from 23.16, and on the clock and the event as the two ways work starts, from 9.2. Read here, they show where dreaming sits:

LoopStarts withStops whenThe person hands offIn Claude Code
Turn-basedA person's requestThe worker judges it done, or needs more contextThe checkThe default loop, and skills that check the work
Goal-basedA request with a test for doneThe test passes, or a cap on tries is reachedThe stop/goal, where a separate model checks the test
Time-basedA scheduleSomeone cancels it, or the work runs outThe trigger/loop on your machine, /schedule in the cloud
ProactiveAn event or a schedule, with no person presentEach task at its goal; it runs until turned offThe request itselfAll of these, with auto mode

Each step down the table removes one more thing the person must do while the work happens. The article's proactive example runs every hour and reads a feedback channel. For each bug, it tries three fixes in parallel, each in its own copy of the code, and a judge chooses among them.

The morning triage is time-based. The dreaming loop is time-based too, and its "request" is "improve the memory".

The four loop kinds as a chain of boxes stepping down to the right, each naming what the person hands off: turn-based hands off the check, goal-based the stop, time-based the trigger, and proactive the request itself. The time-based box is highlighted. Two arrows lead from it to two boxes below: the morning triage, every weekday, and the dreaming loop, once a week, both started by a schedule. Below: the same kind of loop, with a different task.

Figure 31.3. Dreaming is not a new kind of loop. It is a time-based loop whose task is the memory.

Do the three sources agree?

Yes. The loops article, the talk and the always-on article each describe one part of the same system. The chapter's reference page compares them, concern by concern.

Check yourself

Question 1 / 2

0 answered

Where does the dreaming loop write its proposals?

  1. Learning while you sleep: Beyond memory to dreaming (Lamis Mukta, Anthropic, AI Native DevCon London, June 2026).↑
  2. Loop engineering: Getting started with loops (Delba de Oliveira and Michael Segner, Claude, 30 June 2026).↑
Owner
Panaversity