Part 4 · Engineering Patterns for Reliable Agents

Three Context Tactics

Compaction, structured notes, sub-Agent architecture — three context management strategies for long tasks

THE QUESTION THIS PAGE ANSWERS

ANSWER FIRST

What is the key idea behind “Three Context Tactics”?

Compaction, structured notes, sub-Agent architecture — three context management strategies for long tasks

DECISION RULE

Make the claim earn its place. Use this page as a decision aid, not a definition to memorize. Connect the idea to one real task, one observable result, and one failure that would change your mind.

TRY NEXT

Write one question you could answer with evidence after trying this idea.

WATCH FOR

A conclusion that sounds complete but leaves the key assumption untested.

The Core Challenge
The Amnesia Problem in Long Tasks
A complex coding task may require the Agent to perform dozens of steps, generating tens of thousands of Tokens of conversation history. As the context window fills up, the system faces a dilemma:

Option A: Start a new window — but the new window remembers nothing and the Agent repeats work already done.
Option B: Continue in the old window — but as Tokens accumulate, the model's attention is diluted and performance degrades.

This is not a theoretical problem. Claude Code, Cursor, and Devin face this every day in production.
Strategy 1
1
Compaction
Context Compression
When the conversation is approaching the context window limit, make a single LLM call to summarize the existing conversation: retain critical information, discard redundant details, then continue working on the compressed context.
  • The Key Decision: What to keep and what to discard. This is an information-theory problem — not all Tokens are equal, and some information is irrecoverable once lost.
  • Low-Risk Operations: Pruning old tool call results (e.g., file listings, search outputs) — these generally don't affect downstream reasoning.
  • High-Risk Operations: Discarding the reasoning behind architectural decisions or unsolved bug descriptions — if dropped, the Agent will repeat past mistakes.
  • Claude Code in Practice: Retains architectural decisions and unresolved bug information; discards redundant file content output and intermediate steps of completed tasks.
Practical Tip
The summary generated by the LLM during compaction should be structured — free-form prose makes it hard to locate information quickly. For example: "Done: [list] | Pending: [list] | Key Decisions: [list] | Known Issues: [list]" — this allows downstream reasoning to find what it needs fast.
Strategy 2
2
Structured Note-taking
Externalizing Memory
The Agent actively writes critical information to external files during execution rather than relying solely on conversation history. When the context resets (new window), it reads from the note file to restore memory.
  • Core Idea: Externalize short-term memory (context window) into long-term memory (file system), enabling information continuity across windows.
  • Claude Code in Practice: Maintains a TODO list file, updating it after each step — so even if the context is compressed or reset, opening TODO immediately shows progress.
  • Claude Plays Pokémon Case Study: The Agent maintained a game notes file recording map position, collected items, and next steps. Each new conversation began by reading this file to resume memory.
  • Key Design Principle: Note format must be fixed and structured — free-form prose requires extra Tokens to interpret when read back.
Comparison with Compaction
Compaction compresses old information to continue using it; Note-taking stores information externally to retrieve later. The former suits continuous work sessions; the latter suits scenarios that may be interrupted or need to span multiple sessions. Both can be combined.
Strategy 3
3
Sub-agent Architecture
Delegated Deep Exploration
The orchestrator Agent delegates subtasks requiring deep exploration to sub-agents. Each sub-agent works within its own isolated context window (potentially consuming tens of thousands of Tokens), ultimately returning only a refined summary (1,000–2,000 Tokens) to the orchestrator.
  • Core Value: Separation of concerns + context isolation. A sub-agent's working drafts don't pollute the orchestrator's context.
  • Token Economics: A sub-agent may internally consume 30,000 Tokens reading code, analyzing dependencies, and reasoning — but reports only 1,500 Tokens of conclusions upstream. The orchestrator's context stays lean.
  • Parallelism Advantage: Multiple sub-agents can work simultaneously, each exploring a different direction, with the orchestrator synthesizing results. This is far faster than a single Agent exploring serially.
  • Real-world Examples: Cursor's background agent and Claude Code's Task tool are both implementations of sub-agent architecture.
Analogy
Imagine a CEO (orchestrator Agent) assigning 3 department managers (sub-agents) to research competitors, analyze the market, and evaluate technology respectively. Each manager may spend a week (many Tokens), but only delivers a one-page executive summary to the CEO (a refined summary). The CEO's cognitive bandwidth stays at the strategic level.
JIT Context vs Preloading
Preloading
Inject information into context at the start of the conversation
  • CLAUDE.md / Rules files loaded directly
  • User preferences, project configuration
  • Frequently used context information
  • Pro: Immediately available, no extra calls
  • Con: Consumes Tokens every time, whether needed or not
JIT (Just-In-Time)
Retrieve information into context only when needed
  • Use glob/grep to search files on demand
  • Use RAG to retrieve relevant documents
  • Call APIs for real-time data
  • Pro: Context stays lean, only contains what's needed now
  • Con: Adds one tool-call round-trip of latency
Best Practice: Hybrid Strategy
Preload high-frequency information (project conventions, core rules, user preferences) + fetch long-tail information on demand (specific file contents, API docs, history logs).

Analogous to browser caching: hot data in memory cache (preload), cold data fetched from disk or network (JIT). The goal is to maximize context hit rate — most information needed for reasoning is already in the window, with dynamic fetching reserved for occasional needs.
Comparison of Three Strategies
Strategy Core Idea Best For Examples
Compaction Compress old context, retain critical info and continue Continuous long sessions without interruption Claude Code auto-compact
Note-taking Actively write notes externally, read back across windows Tasks that may be interrupted or span multiple sessions Claude Code TODO, Cursor Rules
Sub-agent Sub-agent explores deeply, returns only a summary Deep exploration without polluting the orchestrator's context Cursor Task, Claude Code spawn
The fundamental challenge of long tasks is a finite attention window versus an infinitely growing body of information. Compaction, Note-taking, and Sub-agent Architecture each solve a distinct problem: keeping the window lean, transferring memory across windows, and isolating the noise of deep exploration. Used together, they keep Agents efficient throughout complex, long-running tasks.

Why “The Core Challenge” can find relevant content

“Compaction, structured notes, sub-Agent architecture — three context management strategies for long tasks” moves retrieval beyond storing material: the real question is how to find what is relevant. That decision shapes the input quality of RAG, recommendation, and image-search systems.

Similarity is not the answer

In the flow described by “Compaction, structured notes, sub-Agent architecture — three context management strategies for long tasks”, embeddings place items in a comparable semantic space and a neighbor index narrows the search. The final answer still depends on whether the retrieved chunks cover the question, whether the distance metric fits, and whether the evidence is current.

  • The Key Decision: What to keep and what to discard. This is an information-theory problem — not all Tokens are equal, and some information is irrecoverable once lost
  • Low-Risk Operations: Pruning old tool call results (e.g., file listings, search outputs) — these generally don't affect downstream reasoning
  • High-Risk Operations: Discarding the reasoning behind architectural decisions or unsolved bug descriptions — if dropped, the Agent will repeat past mistakes

Separate findable from relevant

Turn “Compaction, structured notes, sub-Agent architecture — three context management strategies for long tasks” into a small test: prepare queries with known answers, record relevance, misses, and distractors, then decide whether chunking, the index, or reranking needs to change.

From “The Core Challenge” to “Strategy 1”

“The Core Challenge” grounds the problem in “The Amnesia Problem in Long Tasks A complex coding task may require the Agent to perform dozens of steps, generating tens of thousands of Tokens of conversation history. As the context window fills up, the syst…”. “Strategy 1” then moves it toward “1 Compaction Context Compression When the conversation is approaching the context window limit, make a single LLM call to summarize the existing conversation: retain critical information, discard redundant deta…”. Together, they show that the lesson is not just a conclusion to remember, but a claim with conditions.

Carry the judgment into the next situation

The same logic applies to retrieval: define what counts as relevant, check whether recall covers the question, and then inspect whether ranking, chunking, or freshness pushed useful evidence out.

  • “The Core Challenge”: The Amnesia Problem in Long Tasks A complex coding task may require the Agent to perform dozens of steps, generating tens of thousands of Tokens of conversation history. As the context window fills up, the syst…
  • “Strategy 1”: 1 Compaction Context Compression When the conversation is approaching the context window limit, make a single LLM call to summarize the existing conversation: retain critical information, discard redundant deta…
  • “The closing point”: Core Idea: Externalize short-term memory (context window) into long-term memory (file system), enabling information continuity across windows

The final “The closing point” brings the discussion to “Core Idea: Externalize short-term memory (context window) into long-term memory (file system), enabling information continuity across windows”. The useful thing to carry forward is knowing which judgments must be revisited when input, scale, or risk changes.

Mark as learned Your reading progress updates automatically
← PreviousNext →

Keep reading

The next useful article in the thread.

ARTICLE DISCUSSION

Leave one useful thought here.

Keep the idea that clicked, the question that stayed open, or a small note for the next learner.

Discussing Three Context Tactics Engineering Patterns for Reliable Agents
3discussionsArticle discussion · synced with the Circle
View in the learning circle
AM
Asha MorganContent editor
INSIGHTField note

I turned one judgment from this article into a small experiment I could run today. Knowing what to observe next is more useful than simply remembering the conclusion.

ARTICLE DISCUSSION7 helpful
LH
Lin HarperIndie developer
INSIGHTInsight

After reading this, I first looked for the conditions behind the idea instead of copying the method into a project. That order made the later trade-offs much clearer.

ARTICLE DISCUSSION5 helpful
KM
Kiki MooreProduct operations
QUESTIONQuestion

When this judgment reaches real work, which constraint should be added first? I am curious which step matters most between reading and the first practical attempt.

ARTICLE DISCUSSION4 helpful