Domain 5 · Lesson 1 · Context & Reliability (15%)
Preserving Context Across Long Interactions
Task Statements 5.1 & 5.4 — case-facts blocks, lost-in-the-middle, and codebase exploration.
Course progress: Domain 5 ▸ lesson 1 of ~3
Four failure modes of long context (5.1)
| Failure | What goes wrong |
| Progressive summarization | Numbers, %, dates, and customer-stated expectations get condensed into vague prose and lost |
| Lost-in-the-middle | Models reliably use the start and end of long inputs; middle content gets dropped |
| Tool-output bloat | Tool results accumulate tokens out of proportion to relevance (40+ fields when 5 matter) |
| Dropped history | Failing to pass complete conversation history breaks coherence |
The fixes (map each to its failure)
Extract transactional facts (amounts, dates, order #s, statuses) into a persistent "case-facts" block included in every prompt, outside the summarized history. Trim verbose tool outputs to only relevant fields before they accumulate. Put key summaries first and use explicit section headers to beat position effects. For multi-issue sessions, persist structured issue data into a separate context layer.
Structured data over verbose prose
When downstream agents have limited context budgets, modify upstream agents to return structured data (key facts, citations, relevance scores) instead of verbose content and reasoning chains. Require subagents to include metadata (dates, source locations, methodological context) so downstream synthesis stays accurate.
Large codebase exploration (5.4)
Context degradation tell
In extended sessions the model starts giving inconsistent answers and referencing "typical patterns" instead of the specific classes it discovered earlier. That's the signal to intervene.
- Scratchpad files — persist key findings across context boundaries; reference them for later questions.
- Subagent delegation — spawn subagents for verbose investigations ("find all test files," "trace refund-flow deps") while the main agent keeps high-level coordination.
- Summarize between phases — condense findings before spawning the next phase's subagents; inject the summary into their initial context.
- Crash recovery — each agent exports state to a known location (a manifest); the coordinator loads it on resume and injects it into agent prompts.
/compact — reduce context usage during long discovery-heavy sessions.
Check yourself
Over a long support session the agent starts forgetting the exact refund amount and dates the customer stated. The most reliable fix is to:
- Summarize the conversation more aggressively to save context space
- Keep a case-facts block of amounts/dates/IDs in every prompt
- Move the whole transcript to the middle of each new request
- Raise max_tokens so the full history always fits in context
Correct: option 2. A persistent case-facts block keeps transactional specifics outside lossy summarization. More summarization (1) worsens it; the middle (3) is exactly where content is dropped; a bigger window (4) doesn't stop progressive summarization from vaguing the facts.
In a long codebase session the model begins citing "typical patterns" rather than the specific classes it found earlier. The best countermeasure is to:
- Ask the model to try harder to remember what it discovered
- Paste every previously read file back into the current prompt
- Maintain a scratchpad file of key findings and reference it
- Switch to a model with a larger maximum context window
Correct: option 3. Scratchpad files persist findings across context boundaries and counteract degradation. Exhortation is unreliable; re-pasting everything bloats context; a bigger window delays but doesn't prevent degradation.
Decision rules
Facts getting vague → case-facts block in every prompt. Verbose tool output → trim to relevant fields. Long input → key summary first + headers. Long codebase session degrading → scratchpad + subagent delegation + summarize-between-phases; crash → manifest export/reload; /compact to shrink.
Ask your teacher. Want the case-facts-block layout, or how a manifest is structured for crash recovery? Ask.