Progressive Discovery or Monolithic Context: Load It All, Fetch by Index, or Both
A policy assistant with 27 policies runs the same questions through three designs: every policy in the prompt, an index plus a read_doc tool, or the core whole and the tail by index. The run shows when each one reads the fewest tokens and makes the fewest calls.
What you will learn
- Compare monolithic, progressive and hybrid context on calls, tokens read and peak context
- Build an index plus a read_doc tool so Claude fetches one document on request
- Explain why a discovery miss is fixed with a better description, not by loading everything
- Pick the design from two facts: the size of the library and how often each part is used
Before you start
- Claude tool use: tool definitions and tool_result blocks
- Prompt caching basics
Our policy assistant knows twenty-seven company policies. A staff member asks one question, and the model asks for one policy by name. That small moment hides a real design question: does every policy go into the prompt, or only a list of them?
There are three answers. Monolithic loads everything. Progressive loads an index and fetches on request. Hybrid loads the most used part whole and the rest by index. None of them is always right. An architect picks by the numbers, and in this article we get those numbers from a real run.
Where the context gets built
A question comes in, goes through the service and reaches the context builder. The builder decides what the model sees. The prompt goes down to the Claude API. When the model asks for a policy, the builder reads it from the library and sends it back as a tool result. Then the answer comes back up.
So the library stays behind the builder, and enters the context only when it is asked for (in the progressive and hybrid designs) or always (in the monolithic one).
A whole binder, or a contents page
Think of a consultant who needs your company's policies. You can hand over the whole binder. A thin binder is fine, it all fits on the desk. A thick binder fills the desk, and most pages are never opened.
Or you give a contents page and a runner. The contents page is short and always on the desk. The runner fetches one chapter, which costs one extra trip. And if a chapter title is vague, the runner brings the wrong chapter, and that is another trip.
The binder costs space. The runner costs trips. Which one wins depends on how thick the binder is and how many pages each question needs.
Two names float around for the progressive idea. Architecture guides often say progressive discovery, and the Agent Skills documentation says progressive disclosure. It is one idea: put in the prompt only what the work needs.
The three designs in code
The project runs against a stand-in: the Anthropic SDK on an httpx mock transport with scripted replies, so no API key is needed and the replies show the design, not a real model's quality. Token counts come from the stand-in at one token per four characters, so they are the project's own numbers, not Claude prices or limits.
Each policy is a Markdown file with a short front matter (name, description) and a body. The description is the index line, the body is the full text. Here is strategies.py:
"""Three ways to give the assistant the policy library: all of it, an index it can fetch from, or both."""
from dataclasses import dataclass, field
import corpus
from stand_in import MODEL
RULES = "You answer staff questions about Harbor & Lane Ltd policy. Answer only from policy text you have read."
READ_DOC = {"name": "read_doc",
"description": "Read one policy document in full by its id. Use it when the index lists a document that "
"may answer the question.",
"input_schema": {"type": "object", "properties": {"doc_id": {"type": "string"}}, "required": ["doc_id"]}}
@dataclass
class Setup:
system: str
tools: list = field(default_factory=list)
def monolithic(docs):
"""every document sits in the system prompt, on every call"""
return Setup(RULES + "\n\n" + corpus.full_text(docs))
def progressive(docs):
"""only the index is loaded; read_doc fetches one document on request"""
index = corpus.index_text(docs)
return Setup(RULES + "\n\nPolicy index:\n" + index, [READ_DOC])
def hybrid(docs):
"""the core is loaded whole, the long tail stays behind the index"""
core = [d for d in docs if d.area == corpus.CORE]
rest = [d for d in docs if d.area != corpus.CORE]
tail = "\n\nOther policies, fetch with read_doc:\n" + corpus.index_text(rest)
return Setup(RULES + "\n\n" + corpus.full_text(core) + tail, [READ_DOC])
def ask(client, setup, docs, question):
"""up to four calls: answer, or read a document and answer. Returns (usage per call, ids read, reply)"""
by_id = {d.id: d for d in docs}
system = [{"type": "text", "text": setup.system, "cache_control": {"type": "ephemeral"}}]
msgs = [{"role": "user", "content": question}]
usage, read = [], []
for _ in range(4):
kw = {"tools": setup.tools} if setup.tools else {}
r = client.messages.create(model=MODEL, max_tokens=256, system=system, messages=msgs, **kw)
usage.append(r.usage)
if r.stop_reason != "tool_use":
return usage, read, next(b.text for b in r.content if b.type == "text")
call = next(b for b in r.content if b.type == "tool_use")
read.append(call.input["doc_id"])
msgs.append({"role": "assistant", "content": [b.model_dump(exclude_none=True) for b in r.content]})
text = by_id[call.input["doc_id"]].text
block = {"type": "tool_result", "content": text,
"tool_use_id": call.id}
msgs.append({"role": "user", "content": [block]})
return usage, read, "gave up"
Four things to notice:
- Monolithic returns every document, whole, in the system prompt, and no tools.
- Progressive puts only the index in the prompt and adds the
read_doctool. - Hybrid joins the two: the core documents are whole, the rest sit behind the index.
- In all three, the system prompt carries
cache_control, so the long prefix can be reused on the next call. When the model asks for a document, it goes back as atool_result. If you want to go further on where cache breakpoints sit, see prompt cache breakpoints.
One question, three designs
Run python run_all.py. Part A asks one question, how many weeks of parental leave do we get?, against all 27 documents:
A. one question, 27 documents
monolithic calls 1 context per call [1843] read []
progressive calls 2 context per call [567, 688] read ['parental_leave']
hybrid calls 2 context per call [792, 913] read ['parental_leave']
Monolithic makes one call and the model reads 1843 tokens. Progressive makes two calls: the first reads 567, the model asks for parental_leave, and the second reads 688. Hybrid also takes two calls, because parental leave is not a core policy.
Same question, same library. The design decides what the model reads and how many calls it takes.
When discovery misses
Progressive has a failure mode of its own. Part B asks where do I send a doctor's note after time off?
B. a discovery miss
progressive calls 3 context per call [568, 692, 819] read ['annual_leave', 'sick_leave']
The model matched the annual leave line first. Its description is "Booking time off and send requests for approval", and it shares the words send and time off with the question. Call one read the wrong policy, a wasted trip. Call two read sick_leave, whose description mentions the doctor's note, and call three answered.
The lesson: write each description for the question a person asks, not for the file. A vague line sends the model to the wrong policy. The fix is a better description, not loading everything. (In this project the stand-in ranks index lines by shared words; a real model reads more than shared words, but a vague index line is still a weak signpost.)
Size and use decide the winner
Part C asks several questions in a row, once with a three-policy library and once with all 27:
C. 3 docs, 3 questions in a row
monolithic calls 3 read 993 peak 332 cached 612 fresh 381
progressive calls 6 read 1487 peak 325 cached 760 fresh 727
hybrid calls 3 read 1209 peak 404 cached 756 fresh 453
C. 27 docs, 6 questions in a row
monolithic calls 6 read 11064 peak 1846 cached 9095 fresh 1969
progressive calls 12 read 7602 peak 716 cached 5973 fresh 1629
hybrid calls 9 read 7498 peak 920 cached 6144 fresh 1354
With three policies, monolithic reads the least (993) and makes half as many calls as progressive. With 27 policies, progressive reads 7602 against monolithic's 11064, about 31 percent less, but makes twice the calls. Hybrid reads the least of all, 7498, in nine calls. Peak context is 1846 tokens for monolithic against 716 for progressive.
A small, busy library favours loading it all. A large one, used a little at a time, favours the index. When a few policies are used on almost every question, hybrid gets the best of both. For the wider version of this question (whole corpus or retrieval), see full context or retrieval.
The same pattern is built into Claude
Claude's own features follow the same shape: a short front door always loaded, the heavy part one step away.
- Agent Skills keep a name and description loaded, about a hundred tokens per Skill. The body, under five thousand tokens, loads when the Skill triggers, and other files load as needed. See authoring a Claude Skill.
- Tool search keeps most tool definitions out until a search finds them.
- File tools work the same way: Glob and Grep find files, Read opens only the ones that matter.
Our read_doc tool is that pattern built by hand. What leaves the context is a separate job: compaction, context editing and the memory tool handle that.
The traps
- "Always progressive, it saves tokens." The three-policy library took twice the calls and read more.
- "Always monolithic, caching makes it free." Cached reads are cheaper, but they are still part of the total input the model reads on every call.
- "Load everything to fix a miss." That ignores the cause. The miss came from a vague description; rewrite the line.
The decision rule: size the library, and count how often each part is used. Then pick the design that matches both.
Recap
| Situation | Design | Cost you accept |
|---|---|---|
| Small library, needed on most calls | Monolithic | Space: the whole library in every call |
| Large library, each question needs a little | Progressive | Trips: two calls, three on a miss |
| Uneven use, a few policies lead | Hybrid | Core in every call, tail by fetch |
| The model fetches the wrong document | Rewrite the description | Better index lines, not more context |
Try it yourself
Rewrite the annual_leave description so it no longer matches a doctor's note question, run run_all.py again, and see whether part B still needs three calls. Then move parental_leave into the core area and watch part A's hybrid row. The project files for this lesson are in the community, free to join.
Related course on Udemy
Claude Certified Architect - Professional (CCAR-P) Exam Prep
Architecting with Claude: design, models, context, integration, evals, governance and stakeholders.View on Udemy ↗: Claude Certified Architect - Professional (CCAR-P) Exam Prep (paid course, opens in a new tab)Related posts
The Claude Messages API: Your First Call, Field by Field
One request in, one Message out. The four fields of a Messages API call (model, max_tokens, system, messages), how to read content blocks, stop_reason and usage, and why every turn resends the history.
Claude Tool Use: How tool_use and tool_result Work in the Messages API
Follow one order question through Claude's tool round trip: define a tool, read the tool_use block, run your own function and send a matching tool_result back, including parallel calls and is_error.
Claude Client SDKs Wrap One REST API: Raw HTTP, Python, TypeScript and Async Calls Compared
Every Claude client SDK wraps the same REST request: a POST to /v1/messages with a JSON body. See it built by hand, through the Python and TypeScript SDKs, as typed errors, and as async calls that wait together.
Anthropic SDK Timeouts, Retries and Error Classes: Configure the Client Once, Then Give 429, 529, 400 and Timeouts Their Own Move
Configure the Anthropic SDK client (timeout, max_retries, with_options, async, pagination), see which errors it retries by itself, then repair a retry wrapper so a 429, a 529, a 400 and a timeout each get the move the docs support.
