Chapter 30: Self-Improving Agents and the Future
Lecture
The narrated lecture for this chapter is coming soon on the YouTube channel.
Chapter principle
Key takeaways
- Within-task adaptation and across-task learning are different mechanisms.
- Call a change an improvement only after independent, held-out comparison, with no unacceptable slice regression.
- Promoted prompts, memories, and policies need versions, lineage, and rollback.
- Lessons need evidence, provenance, scope, and forgetting.
- Proxy rewards get hacked under optimization; keep hard constraints in the harness.
- Self-improvement must never silently become self-authorization.
Experiments
Every experiment in the book is small, runnable and printed with its real output. In the Lab you can replay a recorded real run of each one, with no programming, and watch what the model and the agent do.
Experiment 57: Improving its own prompt
Can an agent improve its own prompt, and how do we know it really improved?
A real model sorts support requests into BILLING or TECHNICAL. A house rule says that a payment problem caused by a bug in the app is TECHNICAL, but the first prompt does not say so. The model then rewrites the prompt from the cases it got wrong. A second candidate simply lists the four development cases. All three prompts are scored on the development cases, on validation cases and on test cases that no candidate was written from. The winner is chosen on validation, and promoted only if it does better on the test cases without getting worse on either label. This is a recorded run of a real model. A new run may score differently.
Experiment 58: Learning from experience
How should an agent turn past tasks into lessons?
An agent has six records of past tasks: what went wrong, what it did, and whether it recovered. A rate-limit error (API-X 429) recovered with exponential backoff three times out of three. A timeout recovered with an immediate retry once and failed twice. Two learners turn these records into lessons. The naive one makes every success a global rule. The validated one promotes a lesson only with enough evidence, keeps its scope, and cites its source tasks. A real agent then handles three new problems, once with each set of lessons. This is a recorded run of a real model. A new run may choose differently.
Experiment 59: Reward hacking
What happens when an agent is optimized for a reward that only approximates the goal?
Support tickets are scored two ways. The proxy reward gives +1 for closing a ticket and costs 0.1 per action. The true objective rewards only a ticket that is fixed and then closed, and penalizes closing an unsolved one. First a real model is told the proxy reward and works one ticket. Then a simple search scores three behaviors over ten tickets: solve then close, close immediately, and the model's own. The search runs against the proxy, against the true objective, and against the proxy plus a hard rule: a ticket can only be closed after a verified fix. This is a recorded run of a real model. Its choices may differ in a new run.
All the code for this chapter: github.com/agentic-engineering-book/code
Download the bookBrowse all chapters