Chapter 14

Isolate Context and Pass Only the Needed Facts

A separate context window is useful as a filter and a way to parallelize. It becomes a cost when every worker re-reads all the original material. A subagent gets a goal, a minimal set of artifacts, constraints, and an answer format - and must not automatically inherit the manager's whole transcript. Otherwise you pay for the same context several times and carry every prompt injection into each branch.

What to pass - the task contract, canonical identifiers, artifact versions, references to primary evidence, local stop conditions, and budget. What not to pass automatically - the full chat history, other workers' raw logs, secrets, untrusted instructions from documents, and internal drafts.

Anthropic describes subagents as a means of compression: independent context windows explore different directions and return the most important tokens to the lead agent; Claude Code documentation also notes that a subagent works in its own context and returns a summary. This saves the main context but doesn't make the summary true. In the companion project a worker's context is assembled by a narrow envelope.

TypeScript
export function createHandoff(
  source: AgentContract,
  target: AgentId,
  input: Omit<HandoffEnvelope, "from" | "to">
): HandoffEnvelope {
  if (!source.allowedHandoffs.includes(target)) {
    throw new Error(`Handoff ${source.id} -> ${target} is not allowed`);
  }
  if (input.goal.trim().length < 8) {
    throw new Error("Handoff goal is too vague");
  }
  if (input.remainingCalls < 1) {
    throw new Error("Handoff has no remaining call budget");
  }
  return { from: source.id, to: target, ...input };
}
A summary is data. The next agent must distinguish a verified fact, a quote from a tool result, an engineering conclusion, and an unconfirmed assumption. Origin matters more than a confident tone - in production add artifact versions and hashes, provenance for facts, and a package lifetime, and a worker requests a missing artifact explicitly.

Context is isolated. But a temporary projection is not storage: state must be kept outside conversations.

Links