Multi-turn conversation regression for agents

Study time
≈ 2 h (estimate)
Needs
L3-M05-L02
Updated
2026-11-04

Progress is saved in this browser only. No account, nothing is sent to a server.

Draft · reviewed by AI, not yet by a person. Content may change. English translation: AI-assisted, not human-reviewed.
On this page

Module: L3-M05 · Duration: ~110 minutes (estimate, including the independent exercise) · Previous: L02 (growing context) · Next: L04

1. Introduction

L02 found four ways a context change can lose instructions. Every time the team changes the budget, the trimming strategy, the summary prompt or the wording of replies, those failures can come back. L1-M06 taught regression testing for LLM applications: a fixed set of cases, an original version (the baseline), a comparison before release. This lesson applies that to multi-turn conversations: each case is a multi-turn script, checked at the turns that matter, and compared with the baseline check by check, not by the whole transcript.

Why does multi-turn need its own treatment? The paper "LLMs Get Lost In Multi-Turn Conversation" ran large-scale simulations and found that all the top LLMs tested performed significantly worse in multi-turn conversations than in single-turn ones, "with an average drop of 39% across six generation tasks"; when they take a wrong turn in a conversation, they "get lost and do not recover" [R1]. A single-turn test suite does not see that kind of failure. The product of the lesson: the lab's conversation regression suite (lab/conversation.py, six conversations, 12 checks), a gate that fails closed on missing or broken data, and the checks you write yourself for two new conversations in §9. §6.2 has a short note on long-term memory.

2. Learning objectives

  1. Explain why comparing a transcript verbatim (a "golden transcript") is brittle, and why per-turn checks are more robust. Read: §4.1. Practice: §8.2 (part C), §9 (TODO 1).
  2. Write a conversation spec with checks at the probe turns and validate the spec with validate_conversation. Read: §5.1.
  3. Compare a candidate version with the baseline using compare and read new_fail, fixed, still_fail, missing. Read: §5.2. Practice: §8.2 (parts A, B, D).
  4. Explain why the gate holds (HOLD) when a check is missing, added or duplicated, and why the baseline must be chosen deliberately. Read: §5.2, §6.1. Practice: §8.2 (part D), §8.3.
  5. Explain why a long-term memory test must read back in a new session and must include a case that corrects a value. Read: §6.2. Practice: §8.2 (part E).

3. Prerequisites and tools

  • L02 (the five strategies, lost_facts), L1-M05-L05 (the golden transcript of a chat agent, §4.3), L1-M06 (regression testing, baseline), L3-M04-L02 (why a matching mode that is too strict flags a correct agent). Code lab code-labs/l3-m05.
  • Terms kept apart. A version in the lab is a context configuration plus a reply wording style. A probe turn is a turn with checks. A golden transcript is like the golden file of L1-M05-L05 §4.3 (output a reviewer has accepted); here it is the verbatim record of every baseline reply, and a golden test compares verbatim. A check is a condition on the reply of one turn (which category the recommended book is in, which author it is not by, which string it contains).
  • The five versions v1 to v5 are simulated; their names do not correspond to any real product.

4. Concepts

4.1 Golden transcript or per-turn checks

The easiest way to regression-test a conversation is to record every reply of the original version and compare it verbatim with the new version. Anthropic's article classes code-based graders as fast, cheap, objective and reproducible, but "brittle to valid variations that don't match expected patterns exactly" [R2]. With a conversation, changing "I recommend" to "You might like" is enough to turn every recommendation turn red, even though the behaviour has not changed.

A per-turn check asks exactly what matters at that turn: "the recommended book is a science book", "not by Lan Huong", "the reply contains the student's name". Changing the wording does not turn the check red; changing the behaviour does. The cost: you have to think up checks for every probe turn, and a check that is too loose lets failures through. A golden transcript is still useful as a signal to read: a golden diff tells you which turns changed, so a reviewer can open them, not so they fail. L1-M05-L05 uses golden files to catch regressions in a short script; for multi-turn conversations, it should be a reading list, not a gate.

4.2 Fixed script or simulated user

The same Anthropic article says evals for conversational agents often need "a second LLM to simulate the user", and success can be multidimensional: was the problem solved (a state check), was it done in fewer than 10 turns (a transcript constraint), was the tone appropriate (an LLM rubric) [R2]. MT-Bench-101 builds a three-tier taxonomy of abilities with "4208 turns across 1388 multi-turn dialogues in 13 distinct tasks" to evaluate each multi-turn dialogue ability in detail [R3].

The lab's regression suite uses fixed scripts: the student's messages are written in advance. The reason: regression needs to be comparable between two versions. With a simulated user, turn 5 of the new version can differ from turn 5 of the old version because the simulated user reacts to a different reply, so a check tied to "turn 5" no longer means anything. Fixed scripts trade coverage for comparability. In practice the two approaches complement each other: fixed scripts for the release gate, a simulated user to discover new failures, then the failure found becomes a fixed script.

5. Technical deep dive

5.1 Conversation specs, check kinds, and run_suite

A spec (data/conversations.json) is {id, student, title, turns}; each turn has text and can have checks and new_session: true (open a new session for the same student before that turn). Six check kinds, each reading only the reply of its own turn:

Kind value Passes when
recommends a list of book ids the first book id in the reply is in the list
not_by an author the reply has a book id, and that book is not by this author
category a book category the reply has a book id in this category
contains / not_contains a string the string is / is not in the reply
equals the verbatim reply exact match (a golden check, deliberately brittle)

One important rule: a reply with no book id fails recommends, not_by and category. "I have no book that fits your rules." is not "successfully avoided Lan Huong".

validate_conversation(conv, seen_ids) returns error codes: BAD_ID, DUPLICATE_ID (when a set seen_ids is passed across the suite), BAD_STUDENT, NO_TURNS, BAD_TURN (no text, an unknown key such as check instead of checks, or new_session that is not a bool), BAD_CHECK (unknown kind, missing value, unknown book id, unknown author, unknown book category, a contains string that is only whitespace) and NO_CHECK (the conversation has no probe turn). run_suite(convs, version) refuses to run (raises ValueError) if the version name is unknown, a spec is broken or two specs share an id, then returns one result per check with the key <conversation>/t<turn>/<check index>; for example c01/t8/1 is the second check at turn 8 of c01. Turns count from 1, check indexes from 0; in Python, turns[8] is turn 9. Each result also records check, the check's fingerprint (kind and value), so compare can see that a check was edited.

5.2 compare and the gate

compare(base, cand) compares two run_suite results by key and returns:

  • new_fail: passed in the baseline, failed in the candidate. This is a regression.
  • fixed: failed in the baseline, passed in the candidate.
  • still_fail: failed in both. A known failure, not a regression.
  • missing / extra: a key on one side but not the other; duplicate: a key repeated on one side.
  • changed_check: a key on both sides but with different check fingerprints: the spec was edited between the two runs, so the two results do not measure the same thing.
  • malformed: a result entry that is not a dict with a string key and a bool ok (for example ok is the string "False"); compare never raises.
  • passed: the number of checks that passed in both.

gate(cmp) returns HOLD when there is a new_fail, missing, extra, duplicate, changed_check or malformed, when there is no shared key (an empty suite is not a pass), or when cmp is broken (not a dict, a missing key, a list field that is not a list, passed not an int); otherwise READY_FOR_REVIEW. The gate does not hold because of still_fail: the baseline already failed that check (c06, the assistant does not understand the sentence "I do not like books by...", a known failure in every version), so it is listed for review but does not block the release. A check missing from the new run is never treated as a pass: a run that stopped halfway, or a spec with a check deleted, looks exactly like "no regression" if the gate only counts new_fail.

golden_diff(t_base, t_cand) returns the turn numbers whose reply differs verbatim, including turns present on only one side (a shorter transcript is a difference, not a pass).

6. QA perspective

6.1 The baseline is a choice

Part B of the demo (§8.2) compares every candidate with v1. §8.3 shows what happens when the baseline is wrong: comparing v4 with v2 (a version that has regressed), the gate reports READY_FOR_REVIEW with four fixed checks, even though v4 still fails the differently phrased rule in c03. That failure is in still_fail because v2 fails it too. Comparing with a baseline only answers "better or worse than that version", not "is it correct".

Consequences for regression suite design:

  • Record the baseline and why it was chosen, and read still_fail every time: it is the list of failures you are accepting.
  • Every failure found becomes a case. The softened negation failure (L02) needs a case with an author to avoid and a book of a different category by that author, so the reply changes when the rule is lost; the keyword pinning failure needs a differently phrased case (c03).
  • Put checks at probe turns, not at every turn. The turn "Tell me about B004." needs no check; the turn "Recommend a book." after ten turns does.
  • Checks must pass on a reworded version. v3 only changes the wording; a correct set of checks passes completely on v3. If your suite is red on v3, it is checking the wording, not the behaviour.
  • Run the regression suite at several context budgets. v2 and v4 differ from v1 only in the context configuration; the configuration is exactly what changes most often between versions.

6.2 Note: long-term memory

This module gives long-term memory only a short note because the skill is rarely asked for in tester job postings today. Long-term memory lives across sessions; its failures show in the next session, not in the session that wrote it. LangGraph describes a store that keeps long-term memory under a namespace such as (<user_id>, "memories") [R4]; that key is what L04 will test. The lab's case c05 records class 4B, corrects it to 4C, then opens a new session and asks again. With the stale_memory variant (the correction is answered but the memory keeps the first value), the new session answers 4B. If you remove new_session from turn 3, the same variant answers 4C because the assistant reads the correction in the current session's history: a failure that is invisible if the test does not open a new session (the test test_long_term_memory_correction_across_sessions). Two rules for memory tests: always read back in a new session, and always include a case that corrects a value.

7. Real-world scenarios

Scenario 1 (fictional): "Everything is red after a change of tone". The team rewrites the replies to sound friendlier. Their golden test suite goes red on a whole batch of turns. After two days of going through every diff, they find no bug. The tester moves the suite to per-turn checks; the rewrite passes them all, and the golden diff is kept as a list of "turns to read" in review.

Scenario 2 (fictional): "The gate is green, the bug is still there". Last month's release had a regression that was found late, and it became the new baseline. This month's fix passes the gate with many fixed checks. A student still reports that the assistant recommends books by an excluded author when they say it in other words. That case was in still_fail from the start. The team changes the process: the baseline must be a reviewed version, and still_fail is read at every release.

8. Hands-on tutorial

8.1 Setup

As in L01 §8.1.

8.2 Run the demo

python -m lab.demo l03

Output (copied from a real run on Python 3.14.6 and 3.12.3, Linux, 2026-11-04; both versions gave identical output). Every version and conversation is simulated:

A. the suite: 6 conversations, 12 checks; failed checks per version
   v1: ['c06/t3/1']
   v2: ['c01/t8/0', 'c01/t8/1', 'c01/t9/0', 'c02/t8/0', 'c03/t7/1', 'c06/t3/1']
   v3: ['c06/t3/1']
   v4: ['c03/t7/1', 'c06/t3/1']
   v5: ['c01/t8/1', 'c03/t7/1', 'c06/t3/1']
B. compare each candidate with the baseline v1, and the gate
   v2: new_fail=['c01/t8/0', 'c01/t8/1', 'c01/t9/0', 'c02/t8/0', 'c03/t7/1'] still_fail=['c06/t3/1'] passed=6 gate=HOLD
   v3: new_fail=[] still_fail=['c06/t3/1'] passed=11 gate=READY_FOR_REVIEW
   v4: new_fail=['c03/t7/1'] still_fail=['c06/t3/1'] passed=10 gate=HOLD
   v5: new_fail=['c01/t8/1', 'c03/t7/1'] still_fail=['c06/t3/1'] passed=9 gate=HOLD
C. golden transcripts: turns whose reply text differs from v1
   v3: c01=[8, 9] c02=[8] c03=[7] c04=[] c05=[] c06=[3]
   v4: c01=[] c02=[] c03=[7] c04=[] c05=[] c06=[]
D. the gate on a broken comparison
   one check missing: HOLD
   one check doubled: HOLD
   not a dict: HOLD
   no check at all: HOLD
   v2 run on weakened checks (same keys): new_fail=[] changed_check=12 gate=HOLD
E. long-term memory (c05): session 1 remembers 4B, corrects to 4C; session 2 asks
   correct: Your class is 4C.
   stale_memory: Your class is 4B.

Reading the output: part A: v1 (faithful summary, budget 200) fails only the known failure in c06. v2 (keep_system, budget 140) fails five checks. v4 (pin_rules) fails only the differently phrased rule in c03; v5 (summary with softened negation) fails two not_by checks. v3 only changes the wording, so it passes like v1. Part B: the three candidates with regressions are held; v3 goes to review. Part C: the golden diff flags five turns of v3 even though it has no regression, and only one turn of v4 even though v4 has a real regression: golden measures "is it different", not "is it wrong". Part D: a missing check, a doubled check, a broken result, a suite with no checks at all, and a run on a spec with weakened checks (same keys, new_fail empty but 12 changed_check) all give HOLD. Part E: §6.2.

8.3 Try it yourself

Save this as try_l03.py in the lab's root folder (next to lab/), run python try_l03.py, then delete the file:

import copy

from lab import conversation as C

convs = C.load_conversations()
strict = copy.deepcopy(convs)
strict[0]["turns"][8]["checks"].append({"kind": "equals", "value": "Your name is Binh."})
cmp = C.compare(C.run_suite(strict, "v1"), C.run_suite(strict, "v3"))
print(cmp["new_fail"], C.gate(cmp))
cmp = C.compare(C.run_suite(convs, "v2"), C.run_suite(convs, "v4"))
print(cmp["new_fail"], cmp["fixed"], C.gate(cmp))

Output (Python 3.14.6 and 3.12.3, Linux, identical):

['c01/t9/1'] HOLD
[] ['c01/t8/0', 'c01/t8/1', 'c01/t9/0', 'c02/t8/0'] READY_FOR_REVIEW

Reading: line 1: adding an equals check to turn 9 of c01 gives v3 a "regression" (the sentence "You told me your name is Binh." differs verbatim) and the gate holds a version that has no bug. Line 2: comparing v4 with the baseline v2, the gate reports READY_FOR_REVIEW; the c03 failure of v4 is hidden in still_fail (§6.1).

8.4 Run the lesson's tests

python -m pytest tests/test_l03_regression.py -v

Result: 33 passed. Read test_compare_and_gate, test_the_gate_holds_on_a_broken_comparison and test_check_kinds (with the line "no book is not a pass").

8.5 Troubleshooting

Symptom Cause Fix
ValueError: spec ...: ['DUPLICATE_ID'] Two specs share an id Change the id; result keys depend on the id
ValueError: malformed check A broken check was passed straight to evaluate Run validate_conversation first
The gate is HOLD even though new_fail is empty There is a missing, extra or duplicate Read those three lists; a missing check is not a pass
The checks are red on v3 The checks are testing the wording Replace equals or contains "I recommend" with category, not_by, recommends

9. Independent exercise

Problem: Two new conversations without checks (exercises/ex_suite_l03.json): x31 (S0315, two rules, one borrow, asks for the name) and x32 (S0107, one rule, one correction, then two questions in a new session).

Requirements: complete exercises/test_l03_regression.py:

  1. TODO 1: GOLDEN: for each conversation, the turns a golden test would flag when comparing v1 with v3.
  2. TODO 2: CHECKS: at least one check on each probe turn in PROBE_TURNS, no equals, such that the whole suite passes on v1 and v3, the gate holds (HOLD) when comparing v1 with v2, with v4 and with v5, and at each probe turn at least one check fails on the reply of each broken version in BROKEN (a check that passes on every reply is not accepted).

Test data: exercises/ex_suite_l03.json.

Deliverable: the two variables above, in the file exercises/test_l03_regression.py itself.

Acceptance criteria: python -m pytest exercises/test_l03_regression.py passes (2 tests). The tests insert your checks into the spec, run all five versions, then rerun each probe turn under the versions in BROKEN.

Hints: run run_conversation for each conversation with each version and put the replies side by side before writing checks. For turn 9 of x32, ask: which kind of state (L01) is the rule from the previous session? For TODO 1, do not infer from a general rule like "every recommendation and name question": run golden_diff and read each turn that differs.

10. Knowledge check

0/12 done · Results are kept in this browser only.

P02 · True or false

With the stale_memory variant, removing new_session from turn 3 of c05 (asking for the class again in the same session) still makes the contains 4C check of that turn fail.

P04 · Select all that apply

Select every case that makes gate(compare(base, cand)) return HOLD.

P05 · Put in order

Put the steps of a conversation regression check before release in order.

  1. Read still_fail and the golden diff, then a person decides
  2. Compare with compare and read the gate: new_fail, missing, extra, duplicate
  3. Run run_suite for the chosen baseline (a broken spec or a duplicate id makes it raise)
  4. Choose as the baseline a version that has been reviewed, and record why it was chosen
  5. Run run_suite for the candidate on the same set of specs

P06 · Match

Match each simulated version to its behaviour on the lab's regression suite.

P07 · Spot the bug

A team writes a shorter release gate than the lab's. Find the bug.

def gate(cmp):
    return "HOLD" if cmp["new_fail"] else "READY_FOR_REVIEW"

P09 · Essay

Write two to four sentences explaining why the lab's regression suite uses fixed scripts instead of a simulated user, and when a simulated user is still useful.

P10 · True or false

The reply "I have no book that fits your rules." fails the check {"kind": "not_by", "value": "Lan Huong"}.

P11 · Apply now

Run on your machine, no API key needed, no model called. Every result is simulated. Create try_l03p.py in the folder code-labs/l3-m05 (next to lab/) with the content below, run PYTHONDONTWRITEBYTECODE=1 python try_l03p.py, then delete the file:

from lab import conversation as C

convs = C.load_conversations()
v4, v5 = C.run_suite(convs, "v4"), C.run_suite(convs, "v5")
cmp = C.compare(v4, v5)
print(cmp["new_fail"], cmp["fixed"], cmp["still_fail"], C.gate(cmp))
cmp = C.compare(v5, v4)
print(cmp["new_fail"], cmp["fixed"], C.gate(cmp))
Checklist

P12 · Recall

Lesson: L1-M06-L03

According to L1-M06-L03 (§4.4), which case is not a reason to rebuild the baseline?

11. Summary

  • Concepts: multi-turn conversation regression [R1][R3]; golden transcripts are brittle, per-turn checks are robust [R2]; fixed scripts are comparable, a simulated user can explore; the baseline is a choice; long-term memory is tested in the next session [R4].
  • Skills: write specs with checks at probe turns; run run_suite, compare, gate; read still_fail; use the golden diff as a reading list.
  • Traps: comparing verbatim; treating a missing check as a pass; a baseline that has regressed; testing memory within the same session.
  • Now you can: build a conversation regression suite with a gate that fails closed on missing or broken data, and explain every time the gate holds.

12. References

ID Title Publisher URL Accessed Relevance
R1 LLMs Get Lost In Multi-Turn Conversation (arXiv 2505.06120) arXiv (Laban et al.) https://arxiv.org/abs/2505.06120 2026-11-04 Performance drops by 39% on average when moving to multiple turns; once off track, models do not recover
R2 Demystifying evals for AI agents Anthropic https://www.anthropic.com/research/demystifying-evals-for-ai-agents 2026-11-04 Code-based graders are brittle to valid variations; simulated users; multidimensional success
R3 MT-Bench-101: A Fine-Grained Benchmark for Evaluating Large Language Models in Multi-Turn Dialogues (arXiv 2402.14762) arXiv (Bai et al.) https://arxiv.org/abs/2402.14762 2026-11-04 4208 turns, 1388 dialogues, 13 tasks
R4 Stores LangChain (LangGraph documentation) https://docs.langchain.com/oss/python/langgraph/stores 2026-11-04 Long-term memory named by the namespace (<user_id>, "memories")

Glossary (English ↔ Tiếng Việt)

English Tiếng Việt
Conversation regression suite Bộ hồi quy hội thoại: các kịch bản nhiều lượt cố định với check ở lượt dò
Golden transcript Transcript vàng: bản ghi nguyên văn câu trả lời của baseline, so nguyên văn (golden file của L1-M05-L05 cho cả hội thoại)
Probe turn Lượt dò: lượt có check
New fail / fixed / still fail Trượt mới (hồi quy) / đã sửa / vẫn trượt (lỗi đã biết)
Simulated user Người dùng mô phỏng: một mô hình đóng vai người dùng
Stale memory Bộ nhớ cũ: lời sửa không thay giá trị đã lưu