D1 · Agentic Architecture › Cluster 4 · Multi-Agent

4.8 · Sub-Agents as a Cost/Cache Tactic

Spawn a cheap sub-agent — don't swap the main loop's model

CONCEPT Cheap sub-tasks want a cheaper model — but where?

Often a sub-task inside an agent loop is easy enough for a cheaper, faster model (claude-haiku-4-5 or claude-sonnet-4-6) while the main reasoning wants claude-opus-4-8. The instinct is to switch the main loop's model for that one call. That's the trap. The right move is to spawn a sub-agent on the cheaper model and keep the main loop's model unchanged.

🔑 To run a sub-task on a cheaper model, spawn a sub-agent on that model — do not change the main conversation's model mid-loop.

CONCEPT Why not just switch the main loop's model?

Because the prompt cache is model-scoped. The main loop builds up a large cached prefix (system prompt, tool definitions, growing history). If you change the model on the next call, that cache no longer applies — the new model can't reuse the other model's cached prefix, so the entire prefix is re-processed at full price. You'd pay to re-ingest everything just to save on one sub-task: a net loss, plus added latency.

A sub-agent sidesteps this entirely. It's a separate context (4.4), so running it on a cheaper model doesn't touch the main loop's cached prefix at all. The main loop resumes on its original model with its cache intact.

ApproachEffect on main loop's cacheVerdict
Switch main loop's model mid-conversationInvalidated — cache is model-scoped; whole prefix re-processed at full price❌ Avoid
Spawn a sub-agent on the cheaper modelUntouched — separate context; main cache preserved✅ Do this

DIAGRAM Two ways to run a cheap sub-task

flowchart TB subgraph BAD["❌ Switch the main loop's model"] direction LR O1["Opus loop
cache warm"] -->|switch to Haiku| H1["Haiku call
cache INVALID → reprocess prefix"] H1 -->|switch back| O2["Opus loop
cache cold again"] end subgraph GOOD["✅ Spawn a sub-agent"] direction LR O3["Opus main loop
cache stays warm"] -->|delegate sub-task| SUB["🔵 Haiku sub-agent
separate context"] SUB -->|result| O3 end classDef bad fill:#f8d7da,stroke:#dc3545,color:#721c24; classDef good fill:#d4edda,stroke:#28a745,color:#155724; classDef b fill:#d1ecf1,stroke:#17a2b8,color:#0c5460; class O1,H1,O2 bad; class O3 good; class SUB b;

CODE Delegate the cheap sub-task to a sub-agent

The main loop stays on Opus (cache intact). A cheap, isolated sub-agent handles the easy sub-task.

# Cheap sub-task (e.g. classify/extract) → its OWN sub-agent on a cheaper model.
def classify_cheap(text):
    r = client.messages.create(
        model="claude-haiku-4-5", max_tokens=64,      # cheap + fast, separate context
        messages=[{"role": "user",
                   "content": f"Classify as billing/tech/other:\n{text}"}],
    )
    return "".join(b.text for b in r.content if b.type == "text")

# Main loop stays on Opus — its model-scoped prompt cache is NEVER invalidated.
label = classify_cheap(user_msg)                       # cheap sub-agent does the easy bit

resp = client.messages.create(
    model="claude-opus-4-8", max_tokens=4096,        # SAME model → prefix cache reused
    system=BIG_CACHED_SYSTEM_PROMPT,                   # large cached prefix, reused at cache price
    tools=TOOLS,
    messages=main_messages + [{"role": "user",
        "content": f"(category={label}) {user_msg}"}],
)

# ANTI-PATTERN — do NOT do this inside the main loop:
#   client.messages.create(model="claude-haiku-4-5", messages=main_messages, ...)
#   → different model ⇒ Opus's cached prefix can't be reused ⇒ full re-processing cost.
Net effect: you get the cheaper model's savings on the sub-task and keep the main loop's warm cache — the sub-agent's separate context is what makes that possible.

EXAM TRAPS

Trap: "Just switch the model for the cheap step." → Switching the main loop's model mid-conversation invalidates the model-scoped prompt cache; you re-process the whole prefix at full price. Spawn a sub-agent instead.
Trap: Thinking the prompt cache is model-agnostic. → It is model-scoped. A different model cannot reuse another model's cached prefix.
Trap: Assuming a sub-agent's cheaper model hurts the main loop's cache. → It doesn't — the sub-agent is a separate context, so the main loop's cache is untouched.

PRACTICE

Q1 · Mid-loop you want a quick, cheap classification. Best way to keep costs down?

Spawn a sub-agent on claude-haiku-4-5 for the classification and keep the main loop on its model. Switching the main loop's model would invalidate its cache and re-bill the whole prefix.

Q2 · Why exactly does switching the main loop's model cost so much?

The prompt cache is model-scoped. Change the model and the previously cached prefix (system, tools, history) can't be reused, so it's re-processed at full input price — often far more than the sub-task saves.

Q3 · Does running the sub-agent on Haiku cool down the main loop's Opus cache?

No. The sub-agent runs in its own separate context, so the main loop's cached prefix is untouched and stays warm for the next Opus call.