A Case File for Long Sessions
Why This Matters
In a long investigation, the important facts end up scattered across dozens of messages: the run id, the suspect commit, what has already been ruled out. When the conversation is summarised or trimmed to save tokens, some of those facts quietly disappear, and the agent starts checking the payment sandbox for the third time.
The case file
A case file is a small structured block of established facts, kept by your code, not by the model’s memory:
{
"run": "run-1099",
"failure": "t-031 checkout total",
"established": [
"payment-sandbox was healthy during the run (checked 14:10)",
"test passed on commit 7d1e, failed on 8f3c2a1"
],
"ruledOut": ["flaky: 0 failures in 20 runs", "environment: sandbox healthy"],
"openQuestions": ["Is the discount applied before or after tax in PricingService?"],
"nextStep": "read PricingService diff"
}
Update it after every step
After every tool result, your code (or a small, separate model call with a strict schema) updates the case file: add a fact, move a hypothesis to “ruled out”, close a question. Facts in the case file always have a source.
Send it with every request
The case file goes into every request, near the end, in its own tags:
<case_file>…</case_file>
Even if older messages are trimmed, the agent always knows what has been established and what not to repeat.
Summarise without losing facts
When the conversation gets long, you can summarise old turns. The rule: the summary may drop the reasoning, never the facts. Because the facts live in the case file, summarising the conversation is safe.
The progressive summarisation trap. Summarise a conversation, then later summarise the summary, and each round loses detail: t-003 failed 2 of 20 runs on commit a1b2c3, 14:02 becomes “t-003 is sometimes flaky”, then “some flaky tests”. Numbers, ids, dates and exact quotes go first, and they are exactly what the next decision needs. The fix is the case file: facts are kept verbatim in a separate block that is never summarised, only updated.
Start fresh from the case file
For a really long investigation, the cleanest move is often a new session that gets only the case file and the next step. It is the agent version of the status note in lesson 49: cheaper, faster and less confused than dragging 50 messages along.
Exercise
Add a case file to the root-cause investigator. Run it on a failure that needs at least six tool calls, trim the conversation to the last two exchanges halfway through, and check that it does not repeat a step already in “ruled out”.
Compare with solution/lesson-60-reliability, which covers lessons 54–60 (see docs/exercises.md, module 7).