Symptom

A method whose body the agent traces line-by-line to understand the algorithm; the high-level shape is obscured by interleaved details. Verifying behavior preservation requires re-reading the entire span on every edit. The agent's carries the unstructured body, and the count rises as the agent re-derives the structure on each read.

Goal

The method reads as a sequence of named operations the agent verifies against without re-deriving the algorithm. Each helper is small enough to reason about in a single reasoning step. The agent's holds the orchestrator and the relevant helper; the of any edit drops because the relevant unit is named.

Before the refactoring

function add(item, quantity) {
if (this.readOnly) throw new Error('list is read-only');
const existing = this.items.find(line => line.product.id === item.id);
if (existing) {
existing.quantity += quantity;
} else {
this.items.push({ product: item, quantity });
this.items.sort((a, b) => a.product.id - b.product.id);
}
this.recalculateTotal();
}

After the refactoring

function add(item, quantity) {
assertWritable(this);
const existing = findLineFor(this.items, item);
if (existing) {
increaseQuantity(existing, quantity);
} else {
insertNewLine(this.items, item, quantity);
}
this.recalculateTotal();
}
Example source: Illustrative example written for this site, not a quotation from the book. The pattern itself is Joshua Kerievsky's, from Refactoring to Patterns (Addison-Wesley, 2004), see the chapter on Compose Method.
Pressure

Every edit re-loads the full method body to confirm behavior preservation. Chained orchestration changes compound context cost; reasoning about cross-step invariants gets harder as the method grows. The agent's multiplies with body length — verifying any single change requires scanning every other statement to confirm it didn't shift, and on chained edits compounds.

Tradeoff

Each helper inflates the agent's context-window load by one definition the next reasoning step must load. Over-decomposing fragments a single procedure across many files. The agent's rises during the decomposition itself — every reference to the body must be confirmed to route through the new helper rather than continuing to inline what's left.

Relief

The composed method captures the algorithm as a list of named steps the agent reads at one indent; each helper has one signature and one body the agent verifies independently, and edits to one step do not need the others loaded. The agent's per edit drops because the relevant unit is the helper, not the parent.

Trap

A deeply-nested hierarchy of helpers where the agent must chase multiple definitions to understand a single original method — context cost multiplies and cross-helper invariants vanish from view. The agent's retrieval cost across the call graph rises faster than the per-helper context-window load drops; tiny helpers cost more to assemble than to inline.