5.1 Preserving critical information across long interactions
Three failure mechanisms
| Mechanism | What goes wrong |
|---|---|
| Progressive summarization risk | Numerical values, percentages, dates, and customer-stated expectations get condensed into vague summaries ("the customer was unhappy about the amount") |
| "Lost in the middle" — a serial-position effect | Models reliably process the beginning and end of long inputs but may omit findings from middle sections |
| Tool-result accumulation | Verbose results consume tokens disproportionately to relevance — a 40+ field order lookup where 5 fields matter |
The API is stateless: pass complete conversation history in each subsequent request to maintain coherence (Messages API, context windows).
The case-facts layer
Extract transactional facts — amounts, dates, order numbers, statuses — into a persistent "case facts" block included in every prompt, outside the summarized history. Summarization may compress the narrative; it must not be allowed to compress the numbers.
<case_facts>
customer_id: cus_8842 (verified 14:02Z)
order_id: 12345 placed 2026-08-03 total $649.00
issue_1: damaged on arrival — photo evidence received; refund requested
issue_2: duplicate charge $649.00 on 2026-08-04 — under investigation
customer_expectation: "full refund plus return shipping, by Friday"
policy: returns.damaged.v3 (silent on out-of-stock replacement)
</case_facts>
<summarized_history>
…
</summarized_history>
For multi-issue sessions, persist structured issue data (order IDs, amounts, statuses) into a separate context layer so per-issue state does not blur together.
Trimming tool output
Trim verbose tool outputs to the relevant fields before they accumulate in context:
- TypeScript
- Python
// PostToolUse: keep only return-relevant fields from a 40+ field order lookup.
const trim = (order: RawOrder) => ({
order_id: order.id,
placed_at: order.created_at,
status: order.fulfilment_status,
total: order.total_amount,
return_eligible_until: order.return_window_ends_at,
});
# PostToolUse: keep only return-relevant fields from a 40+ field order lookup.
def trim(order: dict) -> dict:
return {
"order_id": order["id"],
"placed_at": order["created_at"],
"status": order["fulfilment_status"],
"total": order["total_amount"],
"return_eligible_until": order["return_window_ends_at"],
}
Position-aware input ordering
Mitigate "lost in the middle" by:
- Placing a key findings summary at the beginning of aggregated inputs.
- Organising detailed results with explicit section headers.
Upstream discipline for downstream budgets
- Require subagents to include metadata (dates, source locations, methodological context) in structured outputs so downstream synthesis is accurate.
- Modify upstream agents to return structured data (key facts, citations, relevance scores) instead of verbose content and reasoning chains when the downstream agent has a limited context budget.
Quiz
- Question 1
A billing dispute has run 40 turns. Your loop condenses everything older than the last six turns into a rolling prose summary. The agent has just offered to refund "the full amount" when the customer accepted a partial $47.50 credit at turn 9, and quoted a 14-day window after the customer was told 30. Which change prevents this class of error?
- Question 2
get_customer returns roughly 60 fields per record and lookup_order returns 40+ per order, including warehouse routing and every carrier scan event. After a dozen tool calls the transcript is dominated by these payloads, and the agent begins missing facts the customer stated earlier. Which intervention addresses the cause with the least behavioural risk?
- Question 3Select all that apply (2)
One conversation now covers three separate issues, each with its own order ID, amount and status. By turn 30 the agent has attributed the refund agreed for the first issue to the order from the third. The rolling summary does mention all three. Which two statements are correct? Select two.
- Question 4
To reduce token spend, a wrapper sends only the latest user message and the system prompt on each API request, retaining the rest of the exchange in its own store for logging. The agent now starts every turn with no memory of the last, re-asking for information it was already given. What is the correct understanding?
Links
- https://platform.claude.com/docs/en/build-with-claude/context-windows
- https://platform.claude.com/docs/en/build-with-claude/context-editing
- https://platform.claude.com/docs/en/build-with-claude/working-with-messages
- https://platform.claude.com/docs/en/agents-and-tools/tool-use/manage-tool-context
- https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents
- https://en.wikipedia.org/wiki/Serial-position_effect