Task statement 5.1 · Context management and reliability
Manage conversation context to preserve critical information across long interactions
A customer opens a billing dispute and a late-delivery complaint in the same chat, and the conversation runs to thirty turns. By turn 26 the early turns have been replaced by a summary to save space. The summary says "around $200", so the agent now acts on a rounded amount instead of the $212.40 it agreed in turn 4.
share
Three wrong answers recur, and each treats a long conversation as a size problem. A bigger context window only delays summarisation, and accuracy and recall still degrade as the token count grows. Summarising more often loses exact values sooner. An instruction to "remember the agreed amount" points at a value that has already been summarised away. What works is structural: your code takes the exact facts out of the history and sends them in a block of their own.
Start hereThree terms this section leans on
- transactional fact
- A value the next action depends on exactly: an amount, a date, an order number, a status. "About $200" is not a transactional fact. "$212.40" is.
- position effect
- A change in how reliably the model uses information depending on where it sits in a long input. "Lost in the middle" is the one the guide names.
- upstream / downstream agent
- In a chain of agents, an upstream agent produces output that a downstream agent reads. Here the subagents that investigate each issue are upstream of the agent that writes the reply.
The mechanism, one long conversation
The Messages API is stateless, so every request your code sends carries the whole conversation: the system prompt, the tool definitions and every earlier message, including each tool result. The history is therefore the agent's only memory of the case, and every tool result in it is re-sent on every later turn. When it nears its budget, older turns are replaced by a summary, which keeps the gist and drops the specifics that process_refund needs.
- Turn 4: the agent agrees a refund of $212.40 plus a 10% goodwill credit, paid to the original card by 11 March.
- Turns 5–25: eight
lookup_ordercalls each append about forty fields, when the return decision uses five. - Near the budget, turns 1–20 and the lookups made in them are replaced by a summary: "a partial refund of around $200 was discussed".
- Turn 26: the agent reads the summary and calls
process_refundwith 200.00. - The fix: your code trims each result before appending it, and copies the four turn-4 facts into a case facts block at the top of every prompt. The summary can stay vague, because the agent reads the amount from the block.
Interactive · the prompt your code sends at turn 26
Choose how your code manages the conversation, and see which refund amount the agent sends at turn 26.
Full results fill the history fast, so turns 1–20 are summarised, together with the five lookups made in them. The amount agreed in turn 4 survives only as "around $200".
Trimming slows the growth, so summarisation starts six turns later. Turn 4 is still inside the summary, so the amount is still vague. Trimming alone does not protect exact values.
The summary is just as vague, and it no longer matters. The case facts block holds $212.40 and the other three turn-4 facts, and it was never part of what got summarised.
KnowledgeTwo losses that are not about summarising
Two more losses have nothing to do with summarising. The first is lost in the middle: models reliably process information at the beginning and end of a long input, but may omit findings from middle sections. When the agent combines three subagent results into one long input, the second issue sits in the middle, so it is the one most likely to be missing from the reply. The second is an incomplete history. Suppose your code sends only the last four turns to save tokens, and at turn 27 the customer writes "Yes, go ahead with that." The model has no turn in which "that" was proposed, so it guesses or asks again. Passing the complete conversation history in every request keeps the conversation coherent, and its size is managed by trimming and summarising, never by silently dropping turns.
SkillA case facts block for a multi-issue session
Your code writes this block from tool results and confirmed customer statements. It is a separate context layer: the history grows by appending, but this block is replaced whole on every request, so nothing in it is summarised. One entry per issue, with its order ID, amount and status, stops a second complaint blurring the first one's amount.
<!-- rebuilt by your code every turn · never summarised --> <case_facts> customer_id: C-48213 # verified by get_customer, turn 2 issue_1: order 7731-A · duplicate charge · refund $212.40 + 10% goodwill credit · agreed turn 4 · by 11 Mar · approved issue_2: order 7790-C · late delivery · status: investigating customer_expectation: "refund to my original card, not store credit" </case_facts>
SkillTrim the result before it accumulates
Trimming means your code keeps only the fields the task needs before a tool result is appended.
Forty fields, re-sent every turn
{ "order_id": "7731-A", "status": "delivered",
"amount": 212.40, "delivered_at": "2026-03-01",
"warehouse_bin": "B-14-3", "carrier_hub": "SYD2",
"sku_weight_g": 840, "gift_wrap": false,
… 32 more fields }Result: eight lookups add about 19,000 tokens of warehouse detail, and the conversation reaches summarisation sooner.
Only the return-relevant fields
{ "order_id": "7731-A", "status": "delivered",
"amount": 212.40, "delivered_at": "2026-03-01",
"return_window_ends": "2026-03-31" }Result: the same decision from five fields, and the early turns stay verbatim for longer.
SkillCombined inputs and upstream agents
When the agent investigates three issues with three subagents, it combines their results into one input before writing the reply. Put a key-findings summary at the beginning of that input and organise the detailed results under explicit section headers, so every issue appears in the reliably used opening.
## Key findings (read first)
- 7731-A: duplicate charge confirmed; refund $212.40 approved
- 7790-C: carrier delay of 6 days; within late-delivery credit policy
- 7802-B: no fault found; delivered and signed for
## Issue 1 · order 7731-A · duplicate charge
…
What each subagent returns matters as much. Require it to include metadata in its structured output: the date of the evidence, the source location, and the methodological context, meaning how the finding was reached. The reply agent needs them to combine findings accurately, for example to prefer a 9 March delivery scan over a 2 March estimate. When the downstream agent has a limited context budget, also change the upstream agents to return structured data, such as key facts, citations and a relevance score, instead of verbose content and reasoning chains.
About 1,400 tokens per issue
"I began with the order record. The
promised date looked like early March,
so I checked the carrier feed …
probably about a week late."Result: three narratives fill the reply agent's budget, with no date or source.
About 80 tokens per issue
{ "issue": "7790-C",
"key_fact": "6 days late (carrier)",
"citation": "carrier_events #88412",
"date": "2026-03-09",
"method": "promised vs first scan",
"relevance": 0.9 }Result: all three findings fit, and each carries its date, source and method.
What the platform automates. Context editing can clear the oldest tool results once the prompt passes a threshold, and server-side compaction can replace older turns with a summary Claude writes (checked 2026-10-01). Neither API feature is in the exam guide, which names only Claude Code's /compact (5.4). All of them still remove material from the history, so an exact value the next action depends on belongs in a block your code controls.
- Summaries turn amounts, percentages, dates and customer expectations into vague phrases, so copy them out of the history first.
- Tool results are history too. Trim each one before it is appended, because every field is re-sent on every later turn.
- Lead a combined input with key findings under headers, and have upstream agents return facts with dates, sources and relevance instead of their reasoning.