Reflection and constrained improvement
hard 7 minAn improvement loop produces a candidate change from feedback on a previous run.
Video lesson · Chapter 1 of 4
A hundredfold mistake at the till
Theory
Read or listen first. About 2 min.
What it is
An improvement loop produces a candidate change from feedback on a previous run. The change might be a memory entry, a revised prompt or a proposed tool. It becomes an improvement only after independent evaluation and controlled release.
Why it exists
Keep the proposer, evaluation set and promotion decision distinguishable. A candidate should not be able to change the criteria by which it is accepted. Track regressions and retain an identifiable baseline for rollback.
Does a reflection fix the next attempt?
Inside this chapter
Chapter sources- Reflexion Agents
- Reflexion uses feedback from an episode to produce a textual reflection that can influence a later attempt. The text changes the next prompt or memory rather than updating model weights. Evaluate the subsequent attempt against held-out tasks to see whether the advice generalizes.
Reflexion turns a failure signal (a failed test, a wrong answer, a grader note) into a short piece of natural-language advice, stores it, and includes it in later attempts. It works best when the feedback is specific and reliable, such as a unit test result. The risk is that a reflection overfits the one episode it came from, so test it on new tasks that share the failure pattern rather than rerunning the same task, which the model may now pass simply by remembering the answer.
Example. Store “check units before adding” after a failed calculation. Evaluate the next run on a new receipt whose units differ again.
Another example. A coding agent fails a test because it forgot to handle an empty list. Its stored reflection is "check empty inputs before indexing". Evaluate it on ten unseen functions that take lists, not on the original function.
A reflection carried into the next attempt - 1Attempt 1 failssummed cents as dollars
- 2Feedbacktotal off by a factor of 100
- 3Write reflection
check units before adding - 4Store in memoryprepended to next prompt
- 5Attempt 2new receipt, different units
Repeat: back to Attempt 1 failsNo weights change. Only the prompt for the next attempt does.
- AutoGPT-style Agents
- AutoGPT-style loops decompose a goal and repeatedly choose actions with limited supervision. More autonomy expands the space of possible failures. Start with a bounded, reversible fixture such as organizing a local reading list, and inspect stop behavior when the requested information is unavailable.
These agents generate their own sub-goals and keep acting until they decide they are done. Without hard limits they can loop, wander off task or keep spending on a goal that cannot be met. Start them in a small, reversible sandbox with a fixed tool set and a step cap, and deliberately give them impossible goals: the useful signal is whether they stop with an honest reason or invent progress.
Example. Give a reading-list agent a fixed catalog and three calls. Ask for an unavailable title and inspect the stop reason.
Another example. A research agent is asked for a paper that does not exist in its search index. A well-bounded agent stops after its search budget and reports "not found in the index"; a poorly bounded one fabricates a citation.
A bounded autonomous loop with explicit exits
Three calls on a fixed catalogue. Every exit has a named reason. - Reviewing agent-proposed tools
- A generated tool is a candidate artifact, not an automatically trusted capability. Use inert inputs, review the contract and evaluate behavior in isolation before registration. Keep deployment approval independent of the proposing model and version the tool so it can be disabled or rolled back.
A generated tool is code plus a description that other runs will trust. Review the contract first: inputs, outputs, side effects, and what it is allowed to reach. Then run it only on inert fixtures (no network, no real data, no writes) and compare its outputs with known answers. Registration is a separate decision made by someone other than the proposer, and every version must be individually disableable.
Example. A model proposes a new unit-conversion tool. Validate it on inert fixtures and review the contract before granting the capability to any run.
Another example. An analytics agent proposes a
currency_converttool that quietly fetches rates from an arbitrary URL. Contract review catches the outbound call before it ever runs, and the approved version reads rates from the internal reference table instead.From proposal to registered capability
The proposing model never moves a tool past Sandboxed on its own. - Self-Improving Agents
- A self-improvement loop proposes a change to a prompt, procedure or tool and evaluates it against a stable baseline. Hold back independent cases and separate the proposer from release approval. If the same component edits the tests and declares success, the score can improve without a better system.
The loop is: propose a change, evaluate it against a fixed baseline on held-out cases, and let a separate gate decide promotion. Any path by which the candidate can influence its own evaluation (editing tests, choosing which cases count, rewriting the grader prompt) breaks the comparison. Keep the evaluation set and grader under separate version control from the thing being improved.
Example. Propose a lower-cost prompt, freeze the test suite, and compare task success and cost. Keep the old version ready for rollback.
Another example. A support agent proposes a shorter system prompt to cut cost by a third. On the frozen suite, resolution stays level overall but drops on billing disputes, so the gate rejects it and the old prompt keeps serving.
Sound improvement loop
- Test suite frozen before the proposal
- Proposer and approver are different components
- Baseline kept deployable for rollback
- Cost and every slice reported, not one score
Self-certifying loop
- Proposal edits the tests it is judged by
- Same model proposes and declares success
- Old version discarded on promotion
- Single headline number
- Scoping and expiring stored lessons
- Reflections saved as memory act like standing instructions for future runs. Attach each lesson to the task type it came from, record its origin run, and give it an expiry or review date. A lesson that was right for one tool version can become wrong after an upgrade.
An unscoped memory store slowly fills with advice that may conflict or go stale, and the model cannot tell which still holds. Treat lessons like configuration: versioned, attributable and removable. Periodically replay a sample of tasks with and without the lesson set to confirm the lessons still help.
Example. A lesson "the invoice API returns cents" was stored before the API switched to decimal amounts. Scoped to
invoice_api v1, it stops applying automatically when v2 is deployed.Lesson record fields
Field Example value Why it matters Lesson text amounts are in centsthe advice itself Scope invoice_api v1tasksstops it leaking into unrelated work Origin run run 7731 lets a reviewer check the evidence Review by next tool upgrade forces a recheck when facts may change - Overfitting to the improvement fixture
- A candidate tuned against a small fixed set can learn its quirks rather than the general skill. Hold back cases the proposer never sees, refresh them over time, and check that gains appear on new examples of the same failure pattern.
Example. A prompt revision lifts the 10-case unit fixture from 7 to 9 but leaves a fresh 50-case held-out set unchanged. The gain is fixture-specific.
How it works
Step through the idea, or press Play.
Failed task. Wrong unit in total
Understand it
Worked example
Does a reflection fix the next attempt?
- 1
Wrong unit in total
The system used cents as dollars. Keep the original failing artifact and a separate set of unseen unit-conversion cases.
- 2
Verify units before summing
A reflection becomes a proposed procedure. Run it on inert fixtures with the old evaluation policy intact.
- 3
7/10 → 9/10 on the fixture
Inspect both changed outcomes, other task slices and cost. A small fixture illustrates a possible gain; it does not establish general real-world improvement.
Follow the handoffs
Who may touch what in the improvement loop
Reading the fixture result
| Suite | Baseline | Candidate | Can it justify promotion? |
|---|---|---|---|
| Original 10 fixtures | 7/10 | 9/10 | only as a hint, two changed cases |
| Edited suite, 2 failing tests removed | 7/8 | 8/8 | no, the measure changed |
| Unchanged held-out suite | rerun needed | rerun needed | yes, if it improves here |
Summary
The whole topic in one minute.
Changing the measure and the system together removes the counterfactual needed to attribute improvement.
Keep the proposer, evaluation set and promotion decision distinguishable. A candidate should not be able to change the criteria by which it is accepted. Track regressions and retain an identifiable baseline for rollback.