Claude Certified Architect · Foundations
Module 5: Context and reliability
Study notes written by Sanjay Shah. Not official Anthropic material. Facts marked "check before relying on it" may have changed.
On this page
Course: Claude Architect (Foundations): Design production systems with Claude · Study notes, our own words · Facts checked 2026-11-25
Exam domain: Context Management & Reliability, 15% (official exam guide v1.1, November 2026)
Take first: Building with the Claude API (opens in a new tab) (free, Anthropic Academy), the context and agent parts. If your company runs on a cloud platform, also take Claude with Amazon Bedrock (opens in a new tab) or Claude on Google Cloud (Vertex AI) (opens in a new tab).
This is the capstone module. It reuses the coordinator and handoff ideas from Module 1, the schemas and validation from Module 3, and the error contract from Module 4.
Video: Module 5 long video, "Keep Long-Running Claude Systems Honest" (planned, locked lesson). Diagrams D5.1 to D5.5 match the video.
What you'll be able to do
Draw a context budget for a long-running system: what's fixed, what's pinned, what grows.
Keep key facts safe from summarization, and keep exploration out of the main context.
Use prompt caching for the stable part of a prompt, and know what it does and doesn't do.
Design failure propagation so a timeout never becomes "nothing found".
Keep a source attached to every claim, and show conflicts instead of hiding them.
Escalate on clear rules, and sample-review the rest.
Key ideas
1. Why long runs fail differently
A single call either works or it doesn't, and you can see which. A system that runs for an hour, across dozens of tool calls and several subagents, fails more quietly:
The context fills up. Every tool result stays in the conversation, and later turns pay for all of it.
Facts get lost. When older turns are summarized to make room, exact numbers, IDs and times are the first casualties.
Errors get swallowed. A subagent's timeout turns into "no results" somewhere between the tool and the final report.
Confidence stays high. The final report sounds just as sure whether it's built on complete evidence or on half of it.
Each of the next sections handles one of these.
2. The context budget
Think of the context window as a budget with three kinds of spending:
Fixed: the system prompt and tool definitions, sent on every request.
Pinned: a small block of key facts your code keeps up to date (section 4).
Growing: conversation history and, above all, tool results.
On 2026-11-25 the current Claude models have a 1M-token context window by default; some older models have 200K (check the model overview (opens in a new tab) for yours). A big window doesn't remove the need for a budget:
Cost and latency grow with every token you send, on every turn.
Attention is shared. The more unrelated material in the context, the easier it is for the important line to get less weight.
Limits still exist. A run that keeps growing will eventually hit one. The API has a dedicated stop reason,
model_context_window_exceeded, for that case.
Practical rules:
Trim at the tool. Return selected fields, top-N with counts, references instead of blobs (Module 4). This is by far the most effective control.
Measure. The token counting endpoint estimates a request's size before you send it, free. Log tokens per turn so you can see what's growing.
Order long inputs well. Put long documents first, with clear headings or tags, and the question and instructions after them.
Clear what's stale. Old tool results that have already been used can be dropped or replaced by a one-line note. The API's context editing feature can clear old tool results automatically (in beta on 2026-11-25).
D5.1 Context budget, before and after.
3. Prompt caching: cheaper, faster, not smarter
Long-running systems resend the same prefix (system prompt, tool definitions, a rubric, a big reference document) on every call. Prompt caching lets the API reuse that processed prefix.
How it works (checked 2026-11-25):
You mark where the cacheable prefix ends with
cache_control: {"type": "ephemeral"}. Up to 4 breakpoints per request.The cache key follows the prompt order: tools, then system, then messages. Change anything early in that order, and everything after it misses the cache.
The default lifetime is 5 minutes, refreshed each time it's used. A 1-hour option exists.
Cache reads cost a small fraction of normal input (0.1× on many models, lower on some current ones). Writing to the cache costs more than a normal input (1.25× for 5 minutes, 2× for 1 hour).
There's a minimum cacheable length, which differs by model.
Design consequences:
Put stable things first, and changing things last. Tools and system prompt at the start; the user's question and fresh tool results at the end. Don't put a timestamp at the top of your system prompt.
Parallel subagents with the same system prompt and rubric benefit a lot: one write, many reads.
Caching changes cost and speed, not the answer. It isn't memory and it doesn't keep facts safe. Section 4 does that.
4. Case facts, summaries, subagents and notes
When a run gets long, you have four tools for keeping context useful. Use them together.
Pinned case facts, kept by code. A small structured block of the facts that must never be lost: incident ID, start time, affected tenants count, deploy ID, decisions made and by whom. Your code updates it from tool results (not the model from memory), and it goes into every request, near the start of the dynamic part. When older turns are summarized, the case facts are untouched.
Summaries for older turns. Summarize the conversation once it passes a threshold, keeping recent turns in full. Summaries are fine for "what have we tried and why"; they're bad at exact values, which is why those live in the case facts. In Claude Code, /compact does this on demand and auto-compaction does it near the limit; a PreCompact hook can save anything that must survive. On the API, server-side compaction exists in beta (2026-11-25; the docs name it inconsistently, so check before relying on it).
Subagents for exploration. If finding an answer means reading 30 log files, a subagent reads them in its own context and returns ten lines with sources (Module 1). The main context only ever sees the summary.
A notes file for very long or restartable runs. The agent writes progress, decisions and open questions to a file or store outside the context. If the run restarts, or context is cleared, it reads the notes back. The API's memory tool is one way to give an agent such a store (it's client-side: your code implements where the memory lives; stable on 2026-11-25).
D5.2 The case facts pattern. Facts are kept by code, not remembered by the model.
5. Failure propagation
The rule: a failure must arrive at the decision-maker as a failure. Module 4 designed this at the tool. Here it runs through the whole system.
Every subagent and every tool returns a result with:
status: complete, partial or failed;tried: what it attempted (queries, sources, time ranges);error: what went wrong, if anything, and whether it's retryable;partial_results: what it did get;not_checked: what it couldn't cover.
The coordinator then has real choices: retry with backoff, narrow the query, try another source, or report the gap to a person. What it must never do is treat a failed search as an empty one.
D5.3 Failure propagation.
Transient API failures need their own handling (checked 2026-11-25):
A 429 (
rate_limit_error) means you hit a rate limit; respect theretry-afterheader.A 529 (
overloaded_error) means the service is temporarily overloaded.The official SDKs retry connection errors, 429s and 5xx errors automatically with exponential backoff, twice by default, and this is configurable. Above that, your own policy decides.
One catch: a 429 caused by hitting a spending cap has no
retry-afterand keeps failing until access resumes. Backoff alone won't fix it, so alert someone.
Fallbacks. For non-critical steps (a summary, a label), a fallback to another model when the main one is unavailable keeps the system moving. For critical steps, it's often better to pause and queue than to quietly use a different model whose output you haven't evaluated.
Retries and side effects. Every retried write needs an idempotency key (Module 4). A retry policy without one turns one refund into two.
6. Provenance: every claim has a source
A long-running agent's final report is only as good as your ability to check it. Design the report so every claim carries:
the claim itself;
a source ID (log line, query, ticket, document and page);
a short quote or the exact query result;
a timestamp where time matters.
Two more rules:
Show conflicts; don't average them. If the deploy log says the change went out at 10:02 and the status page says the incident started at 09:55, the report says both, with sources, and marks it unresolved. A blended "around 10:00" hides the most important fact in the incident.
Separate "observed" from "inferred". Observed: things a source says. Inferred: conclusions the agent drew. Readers treat them differently, and so should your review.
For prose answers grounded in documents, the API's citations feature (generally available on 2026-11-25) returns the passages an answer relied on, which gives you provenance without a custom quote field.
D5.5 Provenance chain. The report is split into Observed and Inferred sections.
7. Escalation on rules, review by sampling
When should the system hand over to a person? Not "when the text sounds unsure". Tone is a poor signal: a calm, confident report can be badly wrong, and a hedged one can be fine.
Escalate on checkable rules:
a policy says so (a category, an amount, a customer tier);
the user asked for a human;
the next action is out of the agent's scope or permissions;
there's an unresolved gap or conflict on something that matters;
a guard tripped (turns, budget, time) before the task was complete.
Everything else goes to the auto lane, and a random sample of the auto lane (for example 5%) goes to a reviewer. Reviewers' findings feed your evaluation set and your prompt and tool fixes. Without sampling, you only ever see the cases you already knew were risky.
D5.4 Escalation and review.
8. The same design on any platform
Claude is available through Anthropic's API and through cloud platforms: on 2026-11-25 the docs list Amazon Bedrock, Claude Platform on AWS, Microsoft Foundry, and Google Cloud (now called "Claude Models on Google Cloud" in the docs). The architecture in this module doesn't change by platform. What can change:
Feature availability and timing. For example, the API's MCP connector wasn't listed for Bedrock on 2026-11-25. Check each feature you depend on, per platform.
Model IDs, quotas and rate limits, which are set per platform.
Data residency and compliance, which are often the reason a company picks a platform in the first place.
Worked example: an on-call incident investigator
The system: an on-call incident investigator for a multi-tenant SaaS platform I build (made generic). It runs for up to an hour across logs, metrics, deploy history and tickets, then writes an impact report for the human incident lead.
What went wrong in v1. The final report said "no customer impact". The log search had timed out and returned an empty list. Earlier in the run, the incident start time had been summarized as "this morning", so the deploy correlation was off by an hour. And the report sounded completely sure of itself.
v2:
Budget: tools trimmed at source (log search returns the top 20 matching lines with counts; metrics return summaries, not raw series). Tokens logged per turn.
Case facts: a code-maintained block with incident ID, start time (from the alert, exact), affected tenant count, suspect deploy ID and decisions so far. Included in every request; never summarized.
Subagents: one each for logs, metrics, deploys and tickets, run in parallel (they're independent once they have the case facts). Each gets a brief (Module 1) and returns the structured result from section 5.
Caching: the shared system prompt, tool definitions and the impact rubric are cached; the four subagents read the same prefix.
Failure propagation: the log timeout now arrives as
status: partial, error: timeout, retryable. The coordinator retries once with a narrower time window; if that fails too, the report says "log search incomplete for 09:40 to 10:10".Provenance: every line of the report has a source and a quote; the deploy-time conflict is shown side by side; "Observed" and "Inferred" are separate sections.
Escalation: any incomplete source, any conflict about start time or scope, or any affected tenant count above zero goes to the incident lead immediately. Clean reports are sampled at 10% for review.
The investigator didn't get smarter. It got honest about what it saw, what it didn't, and where each claim came from.
Your turn: design exercise
Vendor due-diligence research agent. It reads 50+ documents (contracts, security questionnaires, audit summaries, news) over about two hours and writes a risk report for a procurement lead.
Design: the context strategy (what's pinned, summarized or delegated); how failures to read a document are reported; the provenance format; the escalation rules; and the review sampling. The model answer walkthrough is in the locked lesson on the site.
Design decisions and trade-offs
| Decision | Option A | Option B | How to choose |
|---|---|---|---|
| Keeping context small | Summarize after the fact | Trim at the tool | Trim at the tool first; summarize older turns second. |
| Key facts | Trust the model to remember | Pinned case facts kept by code | Code. Summaries lose exact values. |
| Exploration | In the main context | In subagents that return summaries | Subagents, when the reading is large and the answer is small. |
| Very long runs | One growing context | Notes or memory store + restartable steps | External notes once a run can outlast a context or needs to resume. |
| Prompt caching | No caching | Cache the stable prefix | Cache when the same prefix is reused within the cache lifetime; order stable → changing. |
| Failure reporting | Return what you have | Status, tried, error, partial, not checked | Always the structured form. |
| Transient errors | Retry immediately, forever | Backoff, a retry cap, honour retry-after | Backoff with a cap; alert on spend-cap 429s. |
| Model unavailable | Fail | Fallback model | Fallback for non-critical steps; pause and queue for critical ones. |
| Conflicting sources | Pick one or average | Show both, mark unresolved | Show both. |
| Escalation trigger | Model sounds unsure / low confidence | Checkable rules | Rules, plus sample review of the auto lane. |
| Platform | Anthropic API | A cloud platform | Usually decided by data residency, procurement and existing cloud; check feature parity for what you need. |
Anti-patterns
"We have a 1M window, so no budget." Cost, latency and attention still scale with what you send.
Dumping raw tool output into the context. Trim at the tool.
Letting summaries hold the numbers. IDs, amounts and times go in code-kept case facts.
Exploring in the main context. Thirty log files in the coordinator's history.
A timestamp at the top of the cached prefix. Every request misses the cache.
Treating the cache as memory. It saves cost; it doesn't keep facts.
Empty success. "Nothing found" after a timeout.
Unbounded retries, or retries on writes with no idempotency key.
Quietly switching models on a critical step.
Averaging conflicts. Hiding the disagreement that matters most.
Claims without sources. A confident report nobody can check.
Escalating on tone or self-reported confidence.
No sampling of the auto lane. You never learn what you're missing.
Assuming every feature exists on every platform.
Remember
Budget the context: fixed, pinned, growing. Trim at the tool. Measure tokens.
Case facts are kept by code and go into every request. Summaries are for the story, not the numbers.
Explore in subagents; keep notes outside the context for long or restartable runs.
Prompt caching = stable prefix first (tools → system → messages), 5-minute default lifetime; cheaper and faster, not smarter.
Failures arrive as failures: status, tried, error, partial, not checked. Retries use backoff and caps; writes use idempotency keys.
Every claim has a source and a quote. Show conflicts. Separate observed from inferred.
Escalate on rules, not tone. Sample the auto lane, and feed what you find into evals.
Facts in this module, and where to check them
| Fact | Checked | Source |
|---|---|---|
| 1M-token context default on current models; 200K on some older ones | 2026-11-25 | Models overview (opens in a new tab); Context windows (opens in a new tab) |
Stop reason model_context_window_exceeded | 2026-11-25 | Handling stop reasons (opens in a new tab) |
Prompt caching: cache_control ephemeral, 4 breakpoints, tools → system → messages, 5 min default (refreshed), 1 h option, read and write multipliers, model-specific minimum length | 2026-11-25 | Prompt caching (opens in a new tab) |
| Token counting endpoint | 2026-11-25 | Token counting (opens in a new tab) |
| Context editing (beta); memory tool (stable, client-side); server-side compaction (beta) | 2026-11-25 | Context editing (opens in a new tab); Memory tool (opens in a new tab); Compaction (opens in a new tab) |
429 rate_limit_error, 529 overloaded_error, retry-after, SDK retries twice by default with backoff; spend-cap 429 has no retry-after | 2026-11-25 | Errors (opens in a new tab) |
| Citations generally available | 2026-11-25 | Citations (opens in a new tab) |
| Platforms: Bedrock, Claude Platform on AWS, Microsoft Foundry, Claude Models on Google Cloud; MCP connector not listed on Bedrock | 2026-11-25 | Models overview (opens in a new tab); MCP connector (opens in a new tab) |
/compact, auto-compaction, PreCompact hook in Claude Code | 2026-11-25 | Claude Code commands (opens in a new tab); hooks (opens in a new tab) |
Check before relying on it:
Server-side compaction and context editing: both beta, and the docs name the compaction feature inconsistently.
Exact cache prices and minimum cacheable lengths for your model (they differ by model).
Feature availability on your cloud platform.
Practice: 15 questions for this module.