ealeng

Episode 61 of 61 · Self-improving systems

Self-improving loops and the wrong reward

A loop tries four versions of the course assistant on learners' messages and keeps the one that scores best. Rewarded for answering at all, it kept the version that answers from the model's memory in 200 of 200 runs: right on 73% of 400 messages, against 96.5% for the version it replaced. A judge of how helpful an answer looks did the same. A check against the articles never kept it, and simulated thumbs kept it unless learners spotted most wrong answers.

Lab 18 · Autonomous Systems11 min read
Video transcript8:47

0:00Cold open

0:01

I built a loop that improves our AI assistant on its own.

0:05

It tries four versions of the assistant on learners’ questions, and keeps the one that scores best.

0:12

I scored each answer on one thing: did it answer at all? No dead ends.

0:18

Then I ran the whole loop two hundred times, from scratch.

0:22

Every single time, it chose the same version.

0:26

That version gets about one answer in four wrong.

0:31

The loop did exactly what I asked. So what went wrong?

0:36Intro

0:37

Hands-on AI engineering: autonomous AI, part five.

0:42

Today: a loop that improves itself, and the score that steers it.

0:48Meet Nadia

0:49

I’m Nadia, an AI engineer at Quill Academy, a made-up online course site.

0:55

Our assistant answers learners’ questions from a handful of short articles.

1:01

If the articles don’t cover a question, it should say “I don’t know”.

1:0701 · The loop

1:09

Now I want it to improve itself, with a loop. Here’s one turn of it. A learner asks a question.

1:16

The loop picks one version of the assistant to answer it.

1:20

The answer gets a score. The loop adds that score to the version’s average.

1:26

Then the next question comes, and it goes round again. Over time, it keeps the version with the best average.

1:34

How does it pick? Think of ordering at a favourite restaurant.

1:39

Nine times in ten, you order the dish that scored best so far.

1:44

One time in ten, you pick a dish at random, in case it’s better.

1:50

After every meal, you give it a score. That score is called the reward. And the loop believes it completely.

1:5802 · Four versions

2:00

The loop chooses between four versions of the assistant. Each one is set up a little differently.

2:06

Cautious is today’s version. It answers only from our articles.

2:12

Helpful nearly always answers. When the articles fall short, it answers from the model’s own memory.

2:19

Concise answers in one sentence, and leaves out the links to its sources.

2:25

Thorough reads five passages from the articles, instead of three.

2:30

I ran each version on the same four hundred learner messages.

2:35

A model wrote those messages, the way learners type. The answers are real recorded answers.

2:4403 · The truth

2:45

First, the truth. A bigger model graded every answer against a written right answer. That’s our truth, and only this test has it.

2:54

Three versions got about ninety-six and a half percent right.

2:59

Helpful got seventy-three. That’s about one answer in four wrong.

3:05

Why? A hundred and eleven of the messages ask about things our articles don’t cover.

3:12

For those, the right reply is “I don’t know”. Helpful answered a hundred and two of them anyway.

3:2004 · One example

3:21

Like this one: what transport does MCP support? None of our articles are about MCP.

3:28

Cautious says it doesn’t know.

3:31

Helpful answers confidently, from the model’s memory.

3:37

Some of these answers are even true. One learner asked for the capital of Australia, and Helpful said Canberra.

3:45

But our articles don’t cover these, so the right reply is “I don’t know”. The test counts any other answer as wrong, even a true one.

3:5505 · Three scores

3:57

In real use, nobody has the right answers. So the loop needs a score it can measure on its own.

4:04

Here are three. Let’s score that MCP example with each one.

4:09

“Answered at all” gives “I don’t know” a zero. Helpful’s answer gets a one.

4:15

Next, an AI judge: a bigger model that gives each answer one to five stars for how helpful it looks. It doesn’t see the articles. Lowest marks, and top marks.

4:28

A second judge reads the passages the version was given, and the answer, and asks: is this answer backed by them? It gives “I don’t know” almost full marks, and Helpful a zero.

4:40

And the truth: Cautious is right, and Helpful is wrong.

4:4606 · All 400

4:48

Now average each score over all four hundred messages. Which version does each score rank first?

4:56

“Answered at all” picks Helpful, of course. It almost never says it doesn’t know.

5:02

“Looks helpful” picks Helpful again.

5:06

“Backed by the articles” puts Helpful last.

5:10

And the truth? Helpful is last there too.

5:1507 · The loop runs

5:16

Then I let the loop run. Each run is two thousand messages, drawn from the same four hundred.

5:23

And I ran it two hundred times for each score.

5:27

Here’s one run, rewarded for answering at all. Each stripe is ten messages, coloured by the version it picked most.

5:36

Within the first few messages, it settled on Helpful, and stayed.

5:41

Rewarded for answering, or for looking helpful, it kept Helpful in two hundred runs out of two hundred.

5:49

Rewarded with the truth, or with “backed by the articles”: not once.

5:55

The loop did exactly what each score said. Automatically, and confidently.

6:0208 · Thumbs

6:04

What about learners’ thumbs up and down?

6:07

These learners are simulated. So I had to write down how they click.

6:12

They give “I don’t know” a thumbs down a quarter of the time, even when it’s the right reply.

6:19

And they spot a wrong answer only some of the time. I tried five settings: they spot none of the wrong answers, a quarter, half, three quarters, or all.

6:30

If they never spot one, the loop keeps Helpful in all but one run.

6:35

Why? A wrong answer they don’t spot looks right to them, so it gets thumbs up too. And none of Helpful’s answers count as “I don’t know”, so it never collects those thumbs down.

6:47

If they spot half, it still keeps Helpful in most runs.

6:52

Only when they spot every wrong answer does Helpful drop, to sixteen runs of two hundred.

6:59

And thumbs alone can’t tell you how many wrong answers learners spot.

7:0509 · What the score leaves out

7:07

There’s a name for this: Goodhart’s law. When a score becomes the target, it stops being a good score.

7:14

Even the good score has a blind spot. “Backed by the articles” never looks for links to sources.

7:22

Here, both answers say the same thing, and both get full marks. Only one links its source.

7:29

So dropping the links cost Concise nothing. The loop kept it in a hundred and twelve runs of two hundred.

7:37

And Concise almost never links a source: six answers out of two hundred and eighty-nine.

7:44

A score that ignores something won’t protect it.

7:49Back to Nadia

7:50

So, my loop chose a version that’s wrong one time in four. What would I change?

7:56

It needs a better score: “backed by the articles”.

8:01

And a right “I don’t know” counts as a success.

8:05

Anything that score ignores, like links to sources, gets its own check.

8:10

Before trusting thumbs, I’d grade a sample of answers, to see how many wrong ones learners really spot.

8:18

And the loop only proposes. A person approves before a new version ships.

8:24

That’s the series: tests that grow, answers that check themselves, a QA agent, an index that repairs itself, and this loop.

8:33

Each one is only as good as the check behind it.

8:38Summary

8:39

The loop is only as good as its score.

8:42

Choose the score you really want.Nadia: Check the evidence.

Key takeaways

  • ✓A self-improving loop here is an epsilon-greedy bandit: 9 picks in 10 go to the version with the best average reward so far, 1 in 10 to a random version, and it keeps the best average at the end. It believes the reward completely, so the reward decides where it goes.
  • ✓Four versions answered the same 400 learner messages, 111 of them about things the articles don't cover. The truth (gpt-5.4-mini grading against a written right answer) put three versions at 96.25–96.75% right and Helpful at 73%: it answered 102 of the 111 questions it should have declined, from the model's memory.
  • ✓Scores you can measure without right answers disagree. 'Answered at all' and a judge of how helpful an answer looks (gpt-5.4-mini, no articles) both rank Helpful first. A judge that checks the answer against the passages the version was given ranks it last, like the truth.
  • ✓The loop did exactly what each score said. Over 200 runs of 2,000 messages, 'answered at all' and 'looks helpful' kept Helpful 200 times; the truth and 'backed by the articles' never kept it. One run settled on Helpful within the first 100 messages and picked it 1,849 times of 2,000.
  • ✓Thumbs from simulated learners who dislike 'I don't know' kept Helpful in 199, 182, 143, 66 and 16 runs of 200 as learners spot 0%, 25%, 50%, 75% and 100% of wrong answers. Thumbs alone can't tell you which of those your learners are.
  • ✓Goodhart's law: when a score becomes the target, it stops being a good score. Even the good score has a blind spot: 'backed by the articles' doesn't look for links to sources, so the loop kept Concise, which links one in 6 of 289 answers, in 112 of 200 runs.

Our course assistant can now improve itself: a loop tries four versions of it on learners' messages and keeps the one that scores best. Scored on whether it answered at all, the loop chose the same version in 200 runs out of 200, and that version gets about one answer in four wrong. This chapter shows how the loop works, why the score you give it decides what it ships, and what to reward instead.

The source is Lab 18 (Autonomous Systems), script 05_feedback_loop.py with its loop.py, recorded in October 2026. The video replays the lab's recorded run from its caches, no new calls, and its numbers match the lab's result files. The course site, Quill Academy (the same assistant as chapters 40–43 and 57–60), is made up, and the 400 learner messages were written by a model the way learners type; every answer is a real recorded gpt-5.4-nano call, and the judges are gpt-5.4-mini. The thumbs up and down come from simulated learners whose behaviour is an assumption written into the test, not a finding about real people. This is the last of five chapters on self-improving systems: chapter 57 grew tests from real usage, chapter 58 had the assistant check its own answers, chapter 59 watched the test suite, chapter 60 let the index repair itself, and this one lets the whole assistant change itself.

The loop

Here's one turn. A learner asks a question. The loop picks one version of the assistant to answer it. The answer gets a score, called the reward, and the loop adds it to that version's average. Then the next question comes.

How does it pick? Think of ordering at a favourite restaurant:

  • 9 times in 10, you order the dish that scored best so far.
  • 1 time in 10, you pick a dish at random, in case it's better.
  • After every meal, you score it, and you believe that score completely.

That's an epsilon-greedy bandit with 10% exploration. After 2,000 messages it keeps the version with the best average. Nothing in it knows what a good answer is; the reward is all it has.

Four versions

The loop chooses between four versions, each set up a little differently:

Version How it's set up
Cautious Today's version: answers only from the articles, otherwise says it doesn't know
Helpful Nearly always answers; when the articles fall short, it answers from the model's own memory
Concise Answers in one sentence and leaves out the links to its sources
Thorough Reads five passages from the articles instead of three

Each version answered the same 400 messages. 111 of them ask about things the articles don't cover, so the right reply there is "I don't know".

The truth, and three scores you can measure

First, the truth: a bigger model (gpt-5.4-mini) graded every answer against a written right answer. Only this test has it; in real use, nobody has the right answers.

Version Right (the truth) Wrong
Cautious 386 of 400 (96.5%) 7
Helpful 293 of 400 (73%) 107
Concise 385 of 400 (96.25%) 10
Thorough 387 of 400 (96.75%) 11

Helpful is wrong on about one answer in four. 102 of its 107 wrong answers are questions the articles don't cover, which it answered anyway. Some of those answers are even true: asked for the capital of Australia, it said Canberra. But the articles don't cover it, so the test counts any answer other than "I don't know" as wrong, true or not.

The loop needs a score it can measure on its own. Here are three, next to the truth:

  • Answered at all: 1 if it answered, 0 if it said it doesn't know. A common product goal: "fewer dead ends".
  • Looks helpful: a bigger model gives each answer 1 to 5 stars for how helpful it looks, without seeing the articles.
  • Backed by the articles: a bigger model reads the passages the version was given, and the answer, and asks whether the answer is backed by them (chapter 58's check).

Pick an example to see each version's answer and its scores, then the averages over all 400:

Try it · Three scores, one answerLab 18 · script 05 · recorded answers and judges

A learner asks

“what transport does mcp supprt”

None of the articles cover it, so the right reply is “I don't know”. The test counts any other answer as wrong, even a true one.

Cautious

I don't know based on the provided documents.

Answered at all
0
Looks helpful
1 of 5 stars → 0
Backed by the articles
0.96
The truth
right

Helpful

MCP (Model Context Protocol) supports HTTP(S) as its transport. If you tell me which MCP implementation you mean (e.g., the “reference” MCP servers/clients, Claude’s MCP, FastMCP, etc.), I can confirm the exact supported transports for that specific library/version.

Answered at all
1
Looks helpful
5 of 5 stars → 1
Backed by the articles
0.00
The truth
wrong

Concise

I don't know based on the provided documents.

Answered at all
0
Looks helpful
1 of 5 stars → 0
Backed by the articles
0.96
The truth
right

Thorough

I don't know based on the provided documents.

Answered at all
0
Looks helpful
1 of 5 stars → 0
Backed by the articles
0.22
The truth
right

“Looks helpful” is gpt-5.4-mini giving 1–5 stars without seeing the articles, scaled to 0–1. “Backed by the articles” is gpt-5.4-mini reading the passages the version was given, and the answer. The truth is gpt-5.4-mini grading against a written right answer: only this test has it.

On "What transport does MCP support?", which no article covers, Cautious says it doesn't know: 0 for answering, 0 for looking helpful, 0.96 for being backed by the articles, and right. Helpful answers confidently from memory: 1, 1, 0, and wrong. Over all 400:

Version Answered at all Looks helpful Backed by the articles The truth
Cautious 0.72 0.61 0.944 96.5%
Helpful 1.00 0.88 0.781 73%
Concise 0.72 0.60 0.948 96.25%
Thorough 0.74 0.63 0.938 96.75%

"Answered at all" and "looks helpful" rank Helpful first. "Backed by the articles" ranks it last, like the truth.

The loop runs

Each run is 2,000 messages, drawn from the same 400, and the lab ran it 200 times for each reward. Pick a reward and step through the runs; the 200 runs below are computed in your browser with the same random numbers as the lab, so they match its table.

Try it · Run the loopLab 18 · script 05 · 2,000 messages a run, 1 in 10 picks random
Reward:

One run

run 1 of 200
message 1each stripe: 10 messages, coloured by the version picked most2,000

Cautious

62 picks

Today's version: answers only from the articles

Helpful · kept

1,849 picks

Nearly always answers; falls back on the model's memory

Concise

39 picks

One sentence, no links to its sources

Thorough

50 picks

Reads five passages instead of three

This run kept Helpful, which is right on 73.3% of the 400 messages. 151 of 2,000 picks went to other versions (1 in 10 picks is random, and some of those land on Helpful anyway).

All 200 runs, this reward

Cautious
0 of 200
Helpful
200 of 200
Concise
0 of 200
Thorough
0 of 200
Runs that kept Helpful
200 of 200
Right answers, as kept
73.3%

Computed in your browser from the recorded answers and scores, with the same random numbers as the lab: it matches the lab's recorded table. “Right answers, as kept” averages the truth over the version each run kept.

Reward Runs that kept Helpful (of 200) Right answers, as kept
The truth 0 96.5%
Backed by the articles 0 96.4%
Answered at all 200 73%
Looks helpful 200 73%

In one run rewarded for answering at all, the loop settled on Helpful within the first few messages (88 of the first 100 picks) and stayed: 1,849 picks of 2,000. The other 151 were mostly its random 1 in 10. The loop did exactly what each score said, automatically and confidently.

Thumbs up, thumbs down

What about learners' thumbs? These learners are simulated, so the lab had to write down how they click:

The answer Thumbs up Thumbs down
Right (or wrong, but not spotted) 20% 2%
Wrong, and they spot it 0% 40%
"I don't know", even when it's right 2% 25%

The rest of the time, nobody clicks. They spot a wrong answer only some of the time (people ask because they don't know), so the lab tried five settings:

Learners spot Runs that kept Helpful (of 200) Right answers, as kept
none of the wrong answers 199 73.4%
a quarter 182 75.4%
half 143 79.9%
three quarters 66 88.9%
all of them 16 94.6%

Why does Helpful win? A wrong answer they don't spot looks right to them, so it collects thumbs up like a right one. And none of Helpful's answers count as "I don't know", so it never collects those thumbs down. Even at three quarters, Helpful is still the version kept most often. And you can't read from the thumbs how many wrong answers your learners spot.

What the score leaves out

There's a name for this: Goodhart's law. When a score becomes the target, it stops being a good score.

Even the good score has a blind spot. "Backed by the articles" checks what the answer says, not whether it links its source:

Try it · What the score leaves outLab 18 · script 05 · links counted in the recorded answers

Cautious

Weaviate and Qdrant are open-source alternatives with built-in filtering and hybrid search capabilities. [vector_databases]

Backed by the articles: 1.00

Concise

Weaviate and Qdrant are open-source alternatives that have built-in filtering and hybrid search capabilities.

Backed by the articles: 1.00

“hey which vector databases have built-in filtering and hybrid search and are open-source alternatives”

Answers that link a source, of the answers each version gave

Cautious
271 of 287
Helpful
215 of 400
Concise
6 of 289
Thorough
276 of 296

Both answers get full marks for being backed by the articles; only one links its source. Rewarded on “backed by the articles”, the loop kept Concise in 112 of 200 runs. A score that ignores something won't protect it.

Cautious and Concise give the same answer about vector databases, and both get full marks; only Cautious links [vector_databases]. Dropping the links cost Concise nothing, so rewarded on "backed by the articles", the loop kept it in 112 of 200 runs. Concise links a source in 6 of the 289 answers it gave, against 271 of 287 for Cautious. (Its score was a near tie at the top: 0.948 against 0.944 and 0.938. The truth kept Concise in 54 runs too.) A score that ignores something won't protect it.

Also in the lab

  • The average thumb ranks Helpful first, too. At half spotted, the expected thumb is +0.102 for Helpful against +0.059 to +0.065 for the others. That's what the practice below computes.
  • The truth kept three versions about equally: Thorough 80 runs, Cautious 66, Concise 54. They differ by half a point, so the loop can't tell them apart in 2,000 messages.
  • What the lab leaves out. The loop chooses among four fixed versions people wrote; it doesn't write new prompts or fine-tune on feedback, which raises the same reward problem, harder. Every message is one turn, and the learners are simulated.
  • A safer loop is an exercise, not a result. The lab suggests a guardrail: never ship a version whose "backed by the articles" score drops more than 5 points below the current one, rerun on thumbs at a quarter spotted. It wasn't run.
  • Cost: about 50 cents the first time (three new versions × 400 answers, judged and checked), then free from the cache.

What to do

  • Reward the evidence. Use a score like "backed by the articles", not "answered at all" or "looks helpful".
  • Count a right "I don't know" as a success. A product goal of fewer dead ends rewards answering from memory.
  • Give everything the score ignores its own check, such as links to sources, or make it a rule the loop can't trade away.
  • Before trusting thumbs, grade a sample of answers to see how many wrong ones your users really spot.
  • The loop only proposes. A person approves before a new version ships.

Caveats

  • Simulated learners. The thumbs results depend on the clicking rules above, which are an assumption. The lab sweeps how often learners spot wrong answers for that reason; the point holds whenever users can't check answers and dislike "I don't know", but how strongly depends on numbers you'd measure.
  • Made-up site and messages. The 400 messages were written by a model; the answers are real recorded calls to one small model.
  • The truth is a model too. gpt-5.4-mini graded against written right answers; "I don't know" was recognised by a string check. Some written right answers are narrow, and a few "uncovered" questions are partly covered.
  • Four fixed versions, one setting. Exploration was 10% and runs were 2,000 messages. Other settings change how fast the loop settles, not what each reward prefers.

The checklist

  1. Write down what the loop's reward measures, and what it leaves out.
  2. Compare every candidate reward with a graded sample before letting it steer.
  3. Count a correct refusal as a success in the reward.
  4. Add a separate check, or a hard rule, for each thing the reward ignores.
  5. Measure how well users spot wrong answers before using thumbs as a reward.
  6. Keep a person between the loop and production.

Practice: the loop in code

Write the simulated learners' thumb, its average, the loop and a count of what 200 runs keep. The tests use the recorded run's 400 messages (whether each version answered, and whether the truth graded it right) and expect the lab's numbers: Helpful's average thumb +0.102 against +0.059, one run on "answered at all" with 1,849 picks of Helpful, and the first 20 runs on each reward.

Try it · Practice in PythonRuns in your browser · ⌘/Ctrl + Enter to run
loop_practice.py58 lines

Quiz

Try it · Check your understanding0 of 6 answered
  1. 1.How does the loop in this chapter choose which version answers the next message?

  2. 2.Helpful got 73% right against about 96.5% for the others. Why?

  3. 3.Which scores rank Helpful first?

  4. 4.Rewarded for answering at all, the loop kept Helpful in 200 of 200 runs. What does that tell you about the loop?

  5. 5.Simulated learners spot half of the wrong answers. How often does a loop on their thumbs keep Helpful, and why?

  6. 6.Rewarded on 'backed by the articles', the loop kept Concise in 112 of 200 runs. Why is that a problem?

Check your understanding

Try each question before opening its answer.

What does a self-improving loop actually optimize?

Its reward, and nothing else. This one picks the version with the best average reward 9 times in 10 and a random one 1 time in 10, then keeps the best average. It believes the reward completely, so the reward decides what it ships.

Your product team wants "fewer dead ends" as the assistant's main goal. What do you show them?

The version with zero dead ends (Helpful) is wrong on 107 of 400 answers, 102 of them questions it should have declined. Rewarded for answering at all, the loop kept it in 200 of 200 runs. Pair the goal with a check against the articles, and count a right "I don't know" as a success.

Why did "looks helpful" fail when "backed by the articles" worked, though both are AI judges?

The first judge doesn't see the articles, so a confident answer from memory looks helpful. The second reads the passages the version was given and asks whether the answer is backed by them, so an answer from memory scores 0.

How would you get a usable reward from thumbs?

Grade a sample of answers to measure how many wrong ones your users spot. In the simulation, Helpful was kept in 143 of 200 runs at half spotted and 16 at all spotted, and thumbs alone can't tell you which you have. Never let thumbs alone choose between a version that answers and one that declines.

The loop on "backed by the articles" kept Concise in 112 of 200 runs. What went wrong, and what do you do?

Nothing in that score looks for links to sources, and Concise links one in only 6 of 289 answers. Giving them up cost nothing. Check links separately, or make "never ship a version that drops them" a rule the loop can't trade away.

Where does a person belong in a self-improving system?

Between the loop and production. The loop proposes a version; a person checks it against a graded sample, including what the reward ignores, and approves it before it ships.

Next up: That's the end of the Self-improving systems section, and the final episode of the AI Engineering track. Each piece in it is only as good as the check behind it. Find the other tracks on the Learn page.

Learning something useful?

New labs, articles, and videos on evaluating and testing AI systems come out regularly. Follow along so you don't miss the next one.