Context Management & Reliability
Domain 1 covered the basics of session state and lifecycle hooks. Domain 5 goes deeper on the reliability side of long-running, multi-agent systems: prompt caching for cost and latency, structured handoffs between agents and sessions, escalation that never trusts a model's self-reported confidence, error propagation across multiple hops, and provenance when several sources disagree.
5.1 Prompt caching for cost and latency
Every request to the Claude API is stateless — the full prompt is reprocessed from scratch each time. Prompt caching changes that trade-off: you mark a portion of the prompt, a long and stable prefix (a system prompt, a set of tool definitions, a large reference document), as cacheable. If a later request sends that exact same prefix again, Claude reuses the cached processing instead of redoing it — the repeated portion is billed at a steep discount and returns faster.
The exam framing: caching is a reliability lever, not just a cost trick
The scenario the exam reaches for is a high-volume production workload with a stable, repeated context prefix — the textbook example is a coding agent that re-sends the same large codebase context on every turn of a session. The win comes entirely from prefix stability: caching only pays off when the cached bytes are identical between requests.
That has a direct architectural consequence: restructure prompts so volatile content comes last. Put the system prompt, tool definitions, and any large stable documents at the front — cached once, reused many times. Put the thing that changes every request (the latest user message) at the end. A prompt built the other way around — volatile content mixed into or ahead of the stable prefix — invalidates the cache on almost every request and pays full price every time.
# Cache-friendly ordering
messages = [
# stable: system prompt + tool defs + large docs, marked cacheable
{"role": "system", "content": [
{"type": "text", "text": SYSTEM_PROMPT},
{"type": "text", "text": CODEBASE_CONTEXT, "cache_control": {"type": "ephemeral"}}
]},
# volatile: the one thing that changes this turn, always LAST
{"role": "user", "content": latest_user_message}
]Cached entries also expire: by default after 5 minutes of inactivity, refreshed at no extra cost on every hit (a 1-hour TTL is available at double the write cost for less frequent access patterns). A byte-identical prefix that arrives after too long a gap still misses the cache — a dropped hit rate doesn't always mean the prefix changed, it can just mean the requests spread out too far.
5.2 Handoff patterns between agents and sessions
Domain 1 covered how a subagent reports back to its coordinator inside one running system. This section is about a different kind of handoff: transferring a long-running task from one session or agent instance to another entirely — for example, a session that hits its loop-iteration cap and must reseed a fresh session to continue, or a support case that transfers from a bot to a human agent.
The failure mode the exam tests is the same shape in both directions: the handoff payload is either too much (the raw conversation history, dumped wholesale, forcing the receiver to re-derive everything) or too little("start over with no context," throwing away confirmed work). The correct pattern sits in between:
- What's been tried— actions already taken and their outcomes, so the new session/agent doesn't repeat failed approaches.
- What's confirmed — durable facts already established (identity verified, account number, case category) that must not be re-derived or re-asked.
- What's still open — the unresolved part of the task, framed as the actual next step.
| Handoff payload | Bot -> human support handoff |
|---|---|
| Verified identity | Customer ID, account, verification method and timestamp |
| Issue category | e.g. "billing dispute — duplicate charge" |
| Steps already attempted | Refund policy checked (over limit), duplicate-charge lookup run (confirmed duplicate) |
| Current hypothesis | Likely a billing-system double-submit; needs manual refund approval above bot's authority |
5.3 Escalation: deterministic thresholds, not self-reported confidence
This is anti-pattern #2 from Domain 1, deepened: escalation and handoff triggers must be objective and enforced in code, never based on the model self-reporting how confident it is. Concrete, deterministic triggers the exam expects you to recognise:
- A refund or transaction amount exceeds a policy limit (a fixed dollar threshold your code checks).
- N consecutive tool failures — a counted, code-enforced ceiling, not a vibe.
- The customer makes an explicit request for a human — a detectable, unambiguous signal.
- A loop-iteration cap being hit — the same bound that stops runaway agent loops doubles as an escalation trigger.
The anti-pattern the exam plants over and over: routing escalation off the model saying something like "I am only 60% confident in this answer." LLM self-reported confidence is poorly calibrated— a model can be very confidently wrong, and just as easily unconfident about an answer that is actually correct. A confidence score generated by the same model that might be wrong is not an independent check on that model; it's the fox reporting on the henhouse.
5.4 Error propagation across multi-agent systems
Domain 1's anti-pattern #5 (silent subagent failure) covered a single subagent swallowing an error. This section is about what happens across multiple hops: if subagent A fails partway through and its (partial) output feeds subagent B, B needs to know that A's output is incomplete or degraded — not treat it as a normal, complete result.
A subagent that hits an error partway through its work must propagate that error to the coordinator (or the next subagent in the chain) as structured information:
- What failed — the specific step or tool call, and the error category.
- What was completed before the failure — so downstream steps know exactly how much of the result is trustworthy.
- Whether it is safe to retry — transient vs. terminal, so the coordinator can decide the recovery path.
Two failure modes bracket the correct behaviour. On one side, a subagent that returns an empty or success-looking report after a partial failure launders the error into false confidence — everything downstream reasons over incomplete data as if it were whole, and the mistake compounds hop over hop. On the other side, letting the whole system crash uninformatively destroys the work that did succeed and gives operators nothing to act on. The correct middle path is a structured, partial/degraded report that downstream agents are designed to check for.
5.5 Provenance: tracking where claims come from
In systems that synthesize information from multiple sources or subagents — the Multi-Agent Research System scenario's core pattern — every claim in the final output should be traceable back to the source that produced it. Provenance is what lets a reader (or a downstream system) tell the difference between a well-supported fact and a guess.
When two sources disagree, or a claim shows up with no source at all, the synthesis step's job is to surface that conflict, not resolve it invisibly. Two ways synthesis quietly manufactures false confidence:
- Majority vote across correlated, non-independent sources.If subagents share an upstream input or a common blind spot, "2 out of 3 agree" is not independent confirmation — it can launder a single shared error into apparent consensus.
- Blending contradictory claims into one confident-sounding statement. Hedged language that mashes two disagreeing dates or facts together reads as authoritative while communicating nothing verifiable.
The correct handling: flag the conflict or unsourced claim explicitly in the output, and either exclude it or route it for separate verification — never majority-vote it away, and never re-run subagents repeatedly until they happen to agree, which manufactures consensus rather than finding the truth.
Checkpoint quiz — Domain 5
Exam-style: one scenario, one correct answer, three plausible mistakes. Click an option to lock in and see the explanation.
A coding agent re-sends the same 40,000-token codebase context (system prompt + file tree + tool definitions) on every turn of a long session. Only the latest instruction changes each turn. What should the architect do to control cost and latency?
A support agent has been working a case for 40 minutes and must hand off to a human representative because the customer explicitly asked for one. What should the handoff payload contain?
Which of these is the correct set of escalation triggers for handing a case to a human, per the architecture the exam expects?
In a three-hop pipeline (data-collector subagent -> analysis subagent -> report subagent), the data-collector partially fails after gathering 60% of its sources before an API quota error stops it. What should happen next?
A synthesis agent receives three subagent reports on the same fact. Two report 'feature X shipped in Q2' with sources cited; the third reports 'feature X shipped in Q3' with no source, contradicting the other two. What should the synthesis step do?
Quick glossary
Every term below appears somewhere in this course. If a question uses a word you're unsure of, check here before re-reading the whole lesson.
Agentic loop
The repeating cycle behind any Claude-powered agent: send a request, check what Claude wants to do next (stop_reason), run a tool if asked, send the result back, repeat until Claude is done.
stop_reason
A field on Claude's response telling your code why it stopped talking — e.g. it wants to call a tool (tool_use), it finished (end_turn), or it ran out of room (max_tokens).
tool_use / tool_result
tool_use is Claude asking your code to run something (a search, a database lookup...). tool_result is your code's answer, sent back so Claude can continue.
Subagent / Agent tool
A helper Claude spawns to do one focused piece of work in its own separate memory space, then reports back a summary — so the main conversation doesn't get cluttered with the helper's scratch work.
Hooks (PreToolUse / PostToolUse)
Small scripts that run automatically around a tool call — one right before it (can block it entirely) and one right after (can react to the result). Used for rules that must always hold, not just usually hold.
MCP (Model Context Protocol)
A standard way to connect Claude to external systems — databases, internal tools, company APIs — through a shared plug-in format instead of custom one-off code every time.
MCP Tools vs Resources vs Prompts
The three things an MCP connection can offer: Tools are actions Claude decides to call itself; Resources are data the surrounding app decides to hand Claude; Prompts are ready-made instructions a person picks, like a menu option.
.mcp.json
A config file listing which external MCP connections a project uses — shared with the whole team via version control, with any secret keys kept out of it and read from environment variables instead.
CLAUDE.md
A plain-text file Claude reads automatically at the start of every session in a project — the place for standing instructions like coding conventions or how the codebase is organized.
.claude/rules/
Instructions that only switch on for certain files (e.g. only when editing test files), instead of loading into every single session the way CLAUDE.md does.
Agent Skill
A packaged set of instructions Claude loads by itself when a task matches, without anyone typing a command — think of it as an instruction manual Claude picks up automatically off the shelf.
allowed-tools vs disallowed-tools
Two different settings that sound alike: allowed-tools just skips the usual 'are you sure?' prompt for tools you've pre-approved — it doesn't block anything else. disallowed-tools is what actually removes a tool from what's available.
Plan mode
A mode where Claude describes what it's about to do and waits for a yes before touching any files — used for bigger or riskier changes, skipped for small obvious ones.
Message Batches API
A cheaper way to send Claude a large pile of requests when nobody is waiting on the answer right away — costs about half as much, but can take up to a day to come back.
Prompt caching
A way to avoid Claude re-reading the same large, unchanging block of text (like a system prompt or a codebase) on every single request — it's remembered for a while, which is both cheaper and faster.
Context window
The total amount of conversation and text Claude can 'see' at once for a given request. When a conversation runs long, older parts may need to be summarized or dropped to make room.
Hub-and-spoke (multi-agent)
A setup where one coordinator agent hands out tasks to several helper agents and collects their answers — the helpers never talk directly to each other, only to the coordinator.
Anti-pattern
A design choice that looks reasonable but causes real problems in practice — this course names seven specific ones the exam likes to hide inside wrong answers.