Skip to content
The AI Agent Factory

Chapter 31. Self-Improving AI Workers: Memory, Dreaming and Governed Learning

Approved by
Panaversity ·
25 min read

The point

Every AI worker makes mistakes. A good one does not make the same mistake twice. A worker with no way to carry a lesson from one run to the next repeats yesterday's errors, and a person fixes each one by hand. This chapter, the capstone of Part III, closes that gap. It brings together what the part built, from skills and connectors to evaluation and guardrails, and adds the one thing they leave out: your worker learns from its own past runs. And no lesson reaches it until the lesson has been tested and approved.

Why a smarter model does not fix this. Each new Claude model reasons better than the last. But it does not know your company. It does not know that Cedar Ridge's biggest supplier writes its credits on a form of its own. It does not know that Brightline's office-supply vendor sends every invoice twice. And it does not know that the worker made the same mistake on Monday, Wednesday and the next Monday. That knowledge is context, and it is separate from how intelligent the model is. A worker that keeps no context makes every mistake again, however good its model.

A self-improving AI worker carries what it learns from one run to the next. It gets better at its job over weeks, without a person rewriting its instructions after every miss. This chapter builds one, in three layers:

  1. A loop that keeps it working. You built this in 23.16: the morning triage starts on a schedule, is checked by code and stops by itself.
  2. A memory that carries lessons between runs: plain Markdown files, in versions.
  3. A second loop, called dreaming, that reads many past runs at once and proposes better memory. A proposal is not yet a lesson. It becomes one only after evidence, a test and the right approval.

Around those three layers, a worker that holds a job needs two more things: a defined role, and records it can trust over its own notes. The chapter ends with them.

Memory that lasts also lasts when it is wrong. One bad note can be read by every later run, and by every worker that shares the memory. So most of this chapter is about the gate between "the worker noticed something" and "every run now relies on it". The gate has a name in this book: the promotion protocol.

Let the worker remember. Never let it trust a lesson nobody has tested.

Two loops side by side, sharing one memory in the middle. On the left, the task loop: a trigger starts a run, the worker reads memory, does the morning triage, and leaves small notes. It runs every weekday. On the right, the dreaming loop: once a week it reads the memory and many past sessions, and proposes changes. Between the dreaming loop and the memory sits a gate with four steps: evidence, a check against policy, a regression test, approval. Only changes that pass the gate reach the memory as a new version. Below: one memory, two loops; the task loop uses it, the dreaming loop proposes, the gate decides.

Figure 31.1. The task loop does the work. The dreaming loop improves the memory. Nothing reaches the memory without passing the gate.

Where this chapter fits

This is Part III's capstone. You built the worker's skills and connector in Chapters 16 to 20. You built its loop on two APIs and two SDKs in Chapters 21 and 22. Then, in Chapter 23, you hosted it as a product with its own loop. This chapter stands on Chapter 23. Three ideas it uses have their own chapters later in this part: golden sets in Chapter 24, prompt injection in Chapter 28, and the cost of model calls in Chapter 29. What this chapter teaches is how a worker learns: its memory, the dream that proposes lessons, and the gate a lesson must pass before any run relies on it. A hosted worker that repeats its mistakes is still a worker someone has to watch. This chapter closes the part with the one thing the others leave out: a worker that gets better at its job by itself, safely.

When you finish Part III, you can:

  1. Build interactive connectors with MCP Apps (Chapter 20).
  2. Build an AI worker that improves itself, safely: this chapter.
  3. Work as a Forward Deployed Engineer: build, host and improve a worker inside a client's company (From Skills to Income).
  4. Take PCDV-F, the book's Developer exam at the end of this part, and then Anthropic's CCDV-F.

It also builds what Parts I and II taught you to manage by hand. Chapter 4 placed memory in the worker's architecture, with one test: memory is continuity, never authority (4.3). Chapter 8 said what memory may keep, and audited it by hand (8.2). Chapter 11 moved a repeated fix into the worker's setup, and called that move promotion (11.3). Here the worker notices and proposes, and the same promotion becomes a protocol.

It uses what Part III has built, and simple substitutes for the rest. Chapter 23's worker had only read tools. This chapter's worker can also mark an invoice ready to pay and apply a credit, and every approval is a row in an approvals table, a plain file in the lab (approvals.csv). Chapter 28 builds that table properly. Memory is a folder of files in the worker's repository. A lesson that should hold for a whole company goes into that company's policy documents, which you met in Chapter 19, and never straight into memory. Part V gives each of these its governed form.

The last part of the chapter looks ahead. It shows the always-on worker, which Part IV builds as a durable system, and the governed records, which Part V builds. It also shows how today's products and other labs realize the design.

Why it matters

This story is invented, but each failure in it is real and common. A logistics company in Rotterdam gave its customer-service worker a memory, and let it write notes freely. Within a month, one customer had complained twice that deliveries came late on Fridays. The worker wrote a note: "Friday deliveries are unreliable; offer customers a Thursday slot." The note was loaded into every session. For six weeks, every worker in the company steered customers away from Friday. Nobody had decided that. It was a guess from two conversations, and the real cause, one driver's schedule, had been fixed in the second week.

Three things were missing. Nobody separated what was seen (two complaints) from the cause the worker guessed. Nobody tested the note on the cases that already worked. And a note that changed what every worker told every customer went in with no person's approval. This chapter fixes all three, in 31.6 and 31.7.

Words this chapter uses

The words of Chapter 23 keep their meaning: session, run, the morning triage, the portal, list_open_invoices, search_policy, a cited policy line, written as (file.md:N).

WordMeaning
ContextWhat a worker knows about its company and its work that is not in the model: preferences, rules, past mistakes
MemoryFiles the worker reads and writes, kept between runs. Memory is never proof: it is a note about what was true
Memory noteOne file of memory, such as notes/cedar-ridge/credit-memos.md
In band, out of bandIn band means inside a task's own session. Out of band means in a separate job, outside any task
DreamingAn out-of-band job that reads many past sessions and the current memory, and proposes changes to memory
CandidateA lesson someone proposed, before it is checked. A dream, a worker's flag or a person can propose one
Golden setA fixed list of test cases, each with the answer a person checked, used to test a change
Regression testRunning the golden set again after a change, to find anything that used to pass and now fails
PromotionMoving a candidate into trusted memory, after it passes every check
Published versionA copy of the memory that no run can change, with a number, such as v4. A run reads one version from start to end
TierHow much checking a candidate needs before it is published: automatic, or a person
TranscriptThe saved record of one session: its messages, tool calls and results. Dreams read transcripts
Injected contextText loaded into every run, such as instructions.md and index.md
HarnessThe software around the model that runs its loop, calls its tools and manages what it sees
Credit memoA document from a supplier that reduces what you owe, for example after a return
EDIElectronic Data Interchange: a standard way for companies' systems to send each other invoices and orders
Always-on workerA worker that sleeps between events, wakes when something happens or a timer fires, does its work and reports back
Digital FTEA worker that holds a role in an organization, as a full-time employee would
Governed recordAn official record with clear rules for who may change it, how changes are approved, and a log of what happened

Other technical words, such as hash, sandbox, webhook and token, are explained in the full list on the chapter's reference page.

What you will build

Where you are. At the end of Chapter 23, the AP worker runs inside Brightline's portal for two companies. At Brightline itself, Ana Morales is the AP analyst. At Cedar Ridge Supply, Luis Moreno is the AP lead. Every weekday at 7:10, New York time, it runs the morning triage for each company, and code checks the report before it is posted. It works. It also reads a small memory: notes that Ana and Luis approved on Monday, September 28, published as version 3 (v3). Nothing improved those notes after that. For two weeks in October, the worker repeated three mistakes, and a person corrected each one by hand, again and again. A fourth, worse mistake sat in its memory.

What you build instead. As in Chapter 23, coding agents write every file, and you decide, predict and approve.

  1. Memory as versioned folders. Each run reads one published version, read-only, and writes small notes to a scratch folder of its own.
  2. A flag tool. The worker reports a gap in what it knows at the moment it meets it. A flag is a report, not a change.
  3. A dreaming pass over ten recorded sessions, which writes its proposals to a separate folder and never touches the published memory.
  4. A promotion pipeline: each candidate gets its evidence, a check against the policy, a regression run over a golden set of 16 cases, a tier, and an approval row. Then it is published as a new version.
  5. A rollback, when a published lesson breaks a case the golden set did not have.
  6. The worker on the job: a job definition, an inbox that wakes the worker for each event, and a count of what it costs.

By the end of this chapter, you can build and test a worker that keeps what it learns between runs. It admits a new lesson only after four things: evidence, a check against policy, a regression test and the right approval. Everything else in the chapter, from the always-on worker to the governed records and today's tools, supports that one outcome.

In the lab, that outcome breaks into six things you can show:

  1. Sort a worker's memory into layers, and find the notes that belong in a policy or a tool instead (Task 1).
  2. Make every run read one published version that it cannot change (Task 2).
  3. Let the worker report a gap, and run a dream that proposes lessons but never writes them (Tasks 3 and 4).
  4. Count each lesson's evidence, check it against policy, and test it on the golden set (Tasks 5 to 7).
  5. Place each lesson in a tier, publish it with the right approval, and roll back a version that fails (Tasks 7 and 8).
  6. Put the worker on the job: write its job definition, let events wake it without doing anything twice, and count what it costs (Tasks 10 to 12).

In this chapter

Part A. Memory. Then Sitting 1.

  • 31.1 A smarter model is not a better worker
  • 31.2 Two loops over one memory
  • 31.3 Memory in four layers
  • 31.4 Making memory safe

Part B. Learning. Then Sitting 2.

  • 31.5 Dreaming: a second loop
  • 31.6 From proposal to trusted lesson
  • 31.7 Who approves: tiers by risk
  • 31.8 Memory never overrides policy

Part C. The always-on worker and its job. Then Sitting 3.

  • 31.9 The always-on worker
  • 31.10 Build it in order, and count the cost
  • 31.11 From agent to AI worker

Going further.

  • 31.12 What can go wrong
  • 31.13 How today's tools realize it

The chapter's reference page goes deeper. It shows how to test the whole design, and a complete stack on Claude, Cloudflare and Neon, with the full port to OpenAI. It also shows how other labs arrived at the same design, and lists every word the chapter uses.

What this chapter is built on

This chapter is built on published sources. Each page cites the ones it uses, at the point it uses them. The figure shows them in time order.

A time line from September 2025 to November 2026, one row per source. Anthropic's guidance on context engineering, Agent Skills and long-running harnesses comes first, in late 2025, with OpenAI's self-evolving agents recipe on November 4. Anthropic's guide to evals for agents follows on January 9, 2026, then OpenAI's Frontier and harness engineering posts in February. Claude's product launches come next: Managed Agents on April 8, with the Scaling Managed Agents post, routines in Claude Code on April 14, Managed Agents memory on April 23 and dreaming in research preview on May 19. The three core sources come after them: Mukta's dreaming talk in June (day not given), the loops article on June 30 and the always-on agents article on November 13. Later rows show a critique in The New Stack on August 12, Warp's self-improving agents on August 26, OpenAI's Agents API and dots in September, Anthropic's memory research in November, and LangChain's knowledge factory on November 21.

Figure 31.2. The sources behind this chapter, in time order. The products came first: the three core sources describe a design that was already shipping.

The three core sources. The chapter's main claim comes from reading these three together (31.2).

The full list of sources, with links, is on the chapter's reference page. Products change quickly, so check a product fact against its source before you rely on it.

Owner
Panaversity