---
name: improve-memory
description: "Search for a better memory block for an agent that keeps memory per subject, over simulated series of conversations, keeping one that beats the control on held-out subjects. Use when asked to improve how an agent keeps memory."
metadata:
  min-cli-version: "0.97.0"
  next: "deploy-try"
---

# Improve: memory

An agent that serves many subjects (end users, accounts, sites) keeps one memory folder per subject, and every conversation starts with nothing else carried over. What it loads at the start and offloads at the end is set by the memory block in its system prompt, between `<!-- memory:start -->` and `<!-- memory:end -->`. This step searches over that block, not over what any one subject's memory holds.

It changes only the memory block. It never changes the rest of the prompt, the tools, the model, the provider or the judges, and it never merges or changes a runtime.

## Before you start

You need the Recipe with its memory block between the markers. Build the world, as `eval-simulate`'s world reference says, and a fake for every server it binds, on its captured contract, from step 1's answers, never before; they pass their checks before any run. A candidate is a copy of the Recipe under `runs/improve-memory/<id>/candidates/<name>/`, differing only in the memory block.

## 1. Agree everything up front

A harness is measured by how each subject's later conversations go, so one conversation per subject measures nothing. Hold one interview before anything runs, ask every question in it, and write the answers to `runs/improve-memory/<id>/brief.md`. After it, run to the scorecard without stopping to ask again: a question that comes up later is answered by a default below or a check you run yourself.

- **Subjects and how they differ:** at least three for training, each played as a series of conversations in order, and two more held out, never shown to the meta agent, that differ in kind from the rest (narrower needs, a resource that runs short, people who change between conversations). Ask what about a subject the agent should learn and use next time.
- **How a subject reacts:** for each way subjects differ, what the agent can observe of it and what an action of the agent's makes happen. This becomes the subject's model in the fakes, as `eval-simulate`'s world reference says; read it back to the owner as code before any run.
- **What runs short,** asked even when nothing seems to: anything a series can use up (catalogue items, slots, budget), and how many a series uses. Size it so it can't decide the result, or the winner is whichever harness rations it.
- **Metrics and guards:** scores of a good conversation, each kept apart; what memory must never keep (a one-conversation request, another subject's data); a guard in code for each prompt rule a memory block could override. Never sum metrics; report the worst subject.
- **The owner's rules for memory:** what the subject owns, what lives elsewhere, how a setting may change. Quote them in every review.
- **Conversations per subject:** three or more. The first is the same for every harness; the gain shows from the second.
- **Runner and budget:** in-session from the Recipe and its fakes by default, the cloud staging lane to confirm, as [the series runner](references/series.md) says; state the budget once as conversations times candidates times repeats and get one confirmation.

## 2. Seed the population

Generation 0 is the Recipe's current block as the control, plus up to four seeds that differ in kind, from [seed harnesses](references/seeds.md): a free-form folder, a dated log, beliefs with evidence, a structured notes file holding only what changes the agent's next action, and, when a subject's memory outgrows one file, a linked knowledge base. Write each as a full memory block and build a candidate version from each, identical but for the block.

## 3. Run every candidate on every subject

Run each candidate on the same subjects, in the same order, with the same openings: a paired comparison, never the platform's experiment router. Repeat the control and the best parent at least twice, so the run-to-run spread is known. Collect for every conversation its metrics, its trajectory and the subject's memory folder after it.

## 4. Have the meta agent revise the best

Keep the best two or three candidates as parents. Start a `meta-agent` subagent briefed as [agents/meta-agent-brief.md](../../agents/meta-agent-brief.md) says, with each parent's block, its metrics per subject and conversation, and the paths to each trajectory and memory folder; never the held-out subjects, the evals or how a metric is computed. It replies with one revised block per parent, each with its idea, evidence and prediction; from the second generation on, ask for one crossover too, a block combining the strongest idea of two parents.

Review each revision as `improve-propose` step 3 says, with the block's text as the diff and the memory markers as the edit surface, and the owner's stated rules for the agent quoted in the approved change: without them the reviewer can't tell an owner's rule from a value fitted to the evals. A revision that names a subject or quotes one subject's memory is rejected.

## 5. Repeat, then choose

Run the revisions with the parents and the control, as step 3 says, and repeat step 4 from the new best. Stop after the generations agreed, or when no revision beats its parent by more than the spread.

When the revisions stop beating their parents, have the meta agent read the finalists' worst conversations for a failure no block covers, and propose one revision for it. Searching settings such as the model or effort with a sampler belongs to `optimize-quality`, not here: at scale the method that found a block mattered less than the run-to-run spread.

[Checks](references/checks.md) sets headroom, power and finalists. Show the owner a scorecard per candidate: each metric, its worst subject, its gain over the control and whether that gain exceeds the spread, and what its memory folders hold. A gain within the spread is a tie. The owner chooses one, none, or an idea to add as a candidate.

## 6. Prove it on held-out subjects

Run the held-out subjects twice on each finalist that ties in training, and once on the control. Choose the finalist that does best there: the training leader is the best of many noisy trials, so its lead is the likeliest to be luck. When the chosen block still beats the control by more than the spread, put it in the Recipe on a branch and open its pull request as `improve-propose` step 6 says, with the scorecard, the held-out result and each generation's record: what was tried, what each revision predicted, and what happened.

## Done when

- Every candidate ran the same subjects in order, the control and best parent at least twice.
- The meta agent's revisions were reviewed before they ran, and the owner chose from the scorecard.
- The chosen block was picked among the training ties on held-out subjects run twice, beat the control there, and its pull request is open.

Then go on with `deploy-try` when the agent is deployed, or `deploy-connect` when it isn't.
