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.

Why it's tested

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.

  1. Turn 4: the agent agrees a refund of $212.40 plus a 10% goodwill credit, paid to the original card by 11 March.
  2. Turns 5–25: eight lookup_order calls each append about forty fields, when the return decision uses five.
  3. 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".
  4. Turn 26: the agent reads the summary and calls process_refund with 200.00.
  5. 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

The prompt assembled for turn 26, read top to bottom: system prompt, an optional case facts block, then the conversation history, which holds a summary of the early turns and the recent turns verbatim, with the order lookup results inside those turns. Below it, the refund call the agent makes, a meter of tool-result tokens appended, and which of the four facts agreed in turn 4 are exact in the prompt. PROMPT FOR TURN 26 · IN THE ORDER CLAUDE READS IT SYSTEM PROMPT + 4 TOOL DEFINITIONS The same on every turn. CASE FACTS BLOCK · WRITTEN BY YOUR CODE, OUTSIDE THE HISTORY — not used — order 7731-A · refund $212.40 + 10% credit · agreed turn 4 · by 11 Mar · to the original card CONVERSATION HISTORY · EVERY MESSAGE, TOOL RESULTS INCLUDED · RE-SENT EACH TURN SUMMARY OF TURNS 1–20 · 5 LOOKUP RESULTS FOLDED IN SUMMARY OF TURNS 1–14 · 3 LOOKUP RESULTS FOLDED IN “…the customer disputed a charge; a partial refund of around $200 was discussed…” TURNS 21–25, VERBATIM TURNS 15–25, VERBATIM “It’s been a week. Where is my refund?” + 3 lookup_order results, 40 fields each: order_id, status, amount, warehouse_bin, carrier_hub, … 35 more + 5 lookup_order results, 5 fields each: order_id, status, amount, delivered_at, return_window_ends sent to Claude as one request THE AGENT'S NEXT TOOL CALL process_refund(order_id: "7731-A", amount: 200.00) process_refund(order_id: "7731-A", amount: 212.40) WRONG AMOUNT MATCHES WHAT WAS AGREED TOOL-RESULT TOKENS APPENDED BY TURN 25 19,200 2,400 TURN-4 FACTS EXACT IN THIS PROMPT $212.40 10% credit by 11 Mar original card Illustrative token counts: about 2,400 per full order record, about 300 per trimmed one.

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.

Time reads downward: the prompt as assembled, then the call it produces. Tool results are part of the history, so lookups made in summarised turns are summarised with them. The case facts block sits outside the history and near the start of the input, which models use more reliably than the middle.

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.

Ask one question: will a later action need this exact value? Yes → it goes in the case facts block, outside the summarised history, rebuilt by your code every turn. No → it can stay in the history and be summarised with everything else.

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.

Appended as returned

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.

Trimmed by your code

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.

Upstream returns its reasoning

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.

Upstream returns structured data

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.

Takeaway
  • 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.

check yourself

0 / 3 answered

A customer raises four issues. Each is investigated by a subagent that returns about 2,500 tokens of narrative reasoning ending in a conclusion. The agent that writes the reply has about 6,000 tokens for findings, so the fourth result is cut off. Every statement in the reply must name the order record it rests on.Which change best fits all four findings into the budget while preserving the record behind each statement?

Select one.

To save tokens, your client sends Claude only the system prompt and the last six turns. In a 22-turn session about two orders, the customer says "Yes, apply that to the second one", and the agent asks which offer and which order they mean. The 15% discount offered in turn 5 appears nowhere in the request.Which TWO changes most directly restore coherence without letting the request grow without limit?

Select two.

The reply agent receives findings for five issues, joined in the order the subagents finished: about 30,000 tokens, well within its context budget. Across 200 sessions, issues placed third or fourth are left out of the reply four times as often as the first or last issue.What is the most effective first change?

Select one.

sources

  1. Claude Platform Docs, "Using the Messages API" — "The Messages API is stateless, which means that you always send the full conversational history to the API."
  2. Claude Platform Docs, "Context windows" — every message in messages, including tool results, counts toward the window, and context rot: accuracy and recall degrade as the token count grows.
  3. Claude Platform Docs, "Prompting best practices: long context prompting" — long inputs near the top and the query at the end, and each document wrapped with its source and other metadata.
  4. Claude Platform Docs, "Context editing" — the clear_tool_uses_20250919 strategy clears the oldest tool results and leaves a placeholder.
  5. Claude Platform Docs, "Compaction overview" — compaction replaces older turns with a summary Claude writes on the server.
  6. Anthropic Engineering, "Effective context engineering for AI agents" — the attention budget, and subagents that return a condensed summary of 1,000–2,000 tokens.
  7. Task statement text, the 40-fields-versus-5 order lookup example, and the "case facts" block: Claude Certified Architect — Foundations Exam Guide v1.0, Domain 5.1.