# Chapter 31. Self-Improving AI Workers: Memory, Dreaming and Governed Learning (/building-ai-workers/self-improving-ai-workers/overview)

---
type: Document
title: "Chapter 31. Self-Improving AI Workers: Memory, Dreaming and Governed Learning"
description: "Give the hosted worker a memory, let a second loop review its runs and propose lessons, and let a lesson in only after evidence, a regression test and the right approval."
status: stable
order: 331
ksor:
  owner: team:panaversity
  audience: [ public ]
  approval:
    by: process:panaversity
    at: 2026-11-25T09:40:33Z
chapter: "31"
part: III
expert_status: co-build
objectives: [] # by design: the chapter is beyond the exams and holds no exam objective (DEC-33); its learning outcome is stated in the overview
word_budget: 19500 # the editor-in-chief kept the full length on 24 November 2026; the plan's pointer was 4,000 (DEC-61)
prerequisites: [ "21", "22", "23" ]
build_step: "Brightline's AP worker learns from a month of runs: a flag tool, a dreaming pass that writes to a separate folder, a regression run over a golden set, tiered approval in an approvals table, a published read-only memory version, and a rollback"
artifact: "brightline-ap with memory/ as versioned folders, scripts/dream, scripts/regress and scripts/publish, docs/candidates/, and docs/promotion-log.md"
field_guides: []
delta_entries: []
concepts: [ "31.1", "31.2", "31.3", "31.4", "31.5", "31.6", "31.7", "31.8", "31.9", "31.10", "31.11", "31.12", "31.13" ]
last_verified: 2026-11-24
generated:
  at: 2026-11-25T09:40:33Z
  by: process:panaversity
trust_tier: unverified
build_id: sha256:0decb5023f044061076dd533dd5b490739d442d95c609ce2fff5ad3af880174c
dirty: true
ksor_version: 0.0.60
---

## 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](../hosted-agents/loops-check-feedback-and-stop.md): 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.](img/chapter-31-two-loops.png)

*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](../mcp-apps/overview.md)).
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](../../from-skills-to-income/overview.md)).
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](../../ai-worker-paradigm/the-architecture-in-one-picture/overview.md) placed memory in the worker's architecture, with one test: memory is continuity, never authority ([4.3](../../ai-worker-paradigm/the-architecture-in-one-picture/memory-remembers.md)). [Chapter 8](../../managing-ai-workers/context-memory-knowledge-and-state/overview.md) said what memory may keep, and audited it by hand ([8.2](../../managing-ai-workers/context-memory-knowledge-and-state/context-window.md)). [Chapter 11](../../managing-ai-workers/when-the-worker-goes-wrong/overview.md) moved a repeated fix into the worker's setup, and called that move promotion ([11.3](../../managing-ai-workers/when-the-worker-goes-wrong/three-levers.md)). 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](../business-data-and-retrieval/overview.md), 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](from-proposal-to-trusted-lesson.md) and [31.7](who-approves-tiers-by-risk.md).

## 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)`.

| Word | Meaning |
| --- | --- |
| Context | What a worker knows about its company and its work that is not in the model: preferences, rules, past mistakes |
| Memory | Files the worker reads and writes, kept between runs. Memory is never proof: it is a note about what was true |
| Memory note | One file of memory, such as `notes/cedar-ridge/credit-memos.md` |
| In band, out of band | In band means inside a task's own session. Out of band means in a separate job, outside any task |
| Dreaming | An out-of-band job that reads many past sessions and the current memory, and proposes changes to memory |
| Candidate | A lesson someone proposed, before it is checked. A dream, a worker's flag or a person can propose one |
| Golden set | A fixed list of test cases, each with the answer a person checked, used to test a change |
| Regression test | Running the golden set again after a change, to find anything that used to pass and now fails |
| Promotion | Moving a candidate into trusted memory, after it passes every check |
| Published version | A copy of the memory that no run can change, with a number, such as v4. A run reads one version from start to end |
| Tier | How much checking a candidate needs before it is published: automatic, or a person |
| Transcript | The saved record of one session: its messages, tool calls and results. Dreams read transcripts |
| Injected context | Text loaded into every run, such as `instructions.md` and `index.md` |
| Harness | The software around the model that runs its loop, calls its tools and manages what it sees |
| Credit memo | A document from a supplier that reduces what you owe, for example after a return |
| EDI | Electronic Data Interchange: a standard way for companies' systems to send each other invoices and orders |
| Always-on worker | A worker that sleeps between events, wakes when something happens or a timer fires, does its work and reports back |
| Digital FTE | A worker that holds a role in an organization, as a full-time employee would |
| Governed record | An 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](reference.md).

## 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.md) A smarter model is not a better worker
- [31.2](two-loops-over-one-memory.md) Two loops over one memory
- [31.3](memory-in-four-layers.md) Memory in four layers
- [31.4](making-memory-safe.md) Making memory safe

*Part B. Learning. Then Sitting 2.*

- [31.5](dreaming-a-second-loop.md) Dreaming: a second loop
- [31.6](from-proposal-to-trusted-lesson.md) From proposal to trusted lesson
- [31.7](who-approves-tiers-by-risk.md) Who approves: tiers by risk
- [31.8](memory-never-overrides-policy.md) Memory never overrides policy

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

- [31.9](the-always-on-worker.md) The always-on worker
- [31.10](build-it-in-order-and-count-the-cost.md) Build it in order, and count the cost
- [31.11](from-agent-to-ai-worker.md) From agent to AI worker

*Going further.*

- [31.12](what-can-go-wrong.md) What can go wrong
- [31.13](how-todays-tools-realize-it.md) 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.](img/chapter-31-sources-timeline.png)

*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).

- Delba de Oliveira and Michael Segner, [Loop engineering: Getting started with loops](https://claude.com/resources/articles/getting-started-with-loops), Claude, June 30, 2026.
- Lamis Mukta, [Learning while you sleep: Beyond memory to dreaming](https://www.youtube.com/watch?v=tTcxVv8HHNw), a talk at AI Native DevCon London, June 2026.
- William Hu, [Building always-on agents](https://claude.com/resources/articles/building-always-on-agents), Claude Platform, November 13, 2026.

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