Planner-Actor Orchestration in Practice: Single-Context Model Switching vs Advisors vs Subagents
Build and benchmark single-context Planner-Actor switching, Executor-with-Advisor checkpoints, and isolated subagents across Gemini 4 Carbon, Neon, and Hydrogen, accounting for per-model prefix caches and thinking-token multipliers.
Disclosure: I work at Google Cloud. This is personal work built from public documentation and my own accounts, and the views are my own.
Series · Part 4 of 4
Production Agents on Vertex AI
- 01 Agent Orchestration in Practice: Google ADK vs LangGraph vs AWS Strands
- 02 Stateful Agent Memory: Rolling Sessions vs Vector RAG vs Vertex AI Memory Bank
- 03 Open-Weight Agent Serving: LoRA-Tuning Gemma 4 26B-A4B MoE on Vertex AI with vLLM
- 04 Planner-Actor Orchestration in Practice: Single-Context Model Switching vs Advisors vs Subagents
On this page (10 sections)
- Two Hidden Costs That Break Naive Multi-Model Routing
- 1. Sticker Price Lies When Thinking Tokens Multiply
- 2. The Per-Model Prefix-Cache Isolation Trap
- Comparing Three Multi-Model Routing Topologies
- Step 1: Isolated Per-Model Prefix Cache & Turn Economics
- Step 2: Live Public google-genai Adapter (ThinkingConfig)
- Step 3: Phase-Gated Escalation (k = 2 Consecutive Failures)
- Benchmark Results: 12-Task Suite Across Pricing Schedules
- Four Engineering Takeaways From the Numbers
- When to Choose Each Topology
For the past two years, model selection for coding and operations agents followed a simple routine: pick the highest-scoring frontier checkpoint your budget could stand, wire it into a tool-calling loop, and pay its token rate on every single turn. Running a 15-step debugging session meant burning frontier-tier reasoning tokens just as happily on git diff formatting or adding a missing import as on diagnosing a distributed race condition.
Late 2026 model lineups broke that default in two ways at once. First, public reasoning families such as Google’s Gemini 4 lineup split sharply along the speed-versus-depth frontier: Gemini 4 Carbon ($4.00/$20.00 standard per 1M input/output tokens effective December 1, 2026, ~57 tok/s), Gemini 4 Neon ($3.00/$15.00, ~99 to 110 tok/s), and Gemini 4 Hydrogen ($1.50/$7.50, up to ~173 tok/s). Second, production coding harnesses converged on multi-model orchestration: Antigravity’s Orchestrator switches models mid-conversation inside a single context window, Claude Code’s Advisor lets a fast executor query a stronger checkpoint at sticky decisions, and Codex delegates disjoint work to isolated subagents.
Yet pairing a strong model with a fast model has two non-obvious systems traps that turn naive implementations into slow, expensive pipelines: per-checkpoint KV prefix cache isolation and reasoning-token inflation.
This guide is Part 4 of our series on engineering production agents:
- Part 1: Agent Orchestration in Practice: Typed state graphs, parallel API fan-out, and deterministic gatekeeping across Google ADK, LangGraph, and AWS Strands.
- Part 2: Stateful Agent Memory: Rolling windows, keyword recall, SQLite vector RAG, and slot-level fact consolidation.
- Part 3: Open-Weight Agent Serving: Sizing GPU memory and 5:1 hybrid KV caches for Gemma 4
26B-A4BMoE with LoRA and vLLM. - Part 4 (this guide): Implementing and benchmarking single-context Planner-Actor switching, Executor-with-Advisor, and isolated subagents in Python over the public
google-genaiSDK, with explicit prefix-cache and thinking-token accounting.
Before Setting Sail
- Python 3.11+ with a virtual environment
- Familiarity with multi-turn tool-calling agents and provider context caching
- Optional: a Google AI Studio API key (GEMINI_API_KEY) for live calls; the 13-test pytest suite and 12-task routing benchmark run offline
Complete Runnable Companion Code & Interactive Simulator
All four routing topologies, frozen Pydantic v2 contracts, the public google-genai adapter, and the 12-task benchmark CLI live in github.com/steve-largo/largo-tutorials/tree/main/agents/planner-actor-orchestrator. You can also test custom step horizons, failure thresholds, and pricing curves directly in the interactive Multi-Model Agent Routing Simulator.
Two Hidden Costs That Break Naive Multi-Model Routing
Before writing routing code, inspect the two mechanics that dominate real API invoices in the reasoning-model era.
1. Sticker Price Lies When Thinking Tokens Multiply
Public Gemini 4 models expose configurable reasoning effort (low, medium, high, plus xhigh on Hydrogen and Neon) via types.ThinkingConfig(thinking_level=...), and internal thought tokens are billed at the output token rate. Because output tokens cost 5x input tokens and 100x cached prefix reads, reasoning verbosity often outweighs headline price per million tokens.
Public Artificial Analysis benchmark measurements illustrate the paradox clearly:
| Public Gemini 4 Model | Standard API ($/1M In / Out) | Cache Read ($/1M) | Decode Speed | Intelligence Index | Notable Task-Cost Nuance |
|---|---|---|---|---|---|
| Gemini 4 Carbon | $4.00 / $20.00* | $0.20 | ~57 tok/s | 60 (high) | $2/$10 intro through Nov 30, 2026 |
| Gemini 4 Neon | $3.00 / $15.00 | $0.15 | ~99 to 110 tok/s | 60 (high), 61-62 (xhigh) | Beats Carbon on speed and Dec 1 unit cost |
| Gemini 4 Hydrogen | $1.50 / $7.50 | $0.07 | ~173 tok/s | 51 (high), 54 (xhigh) | Emits ~48% more output tokens at xhigh (304M vs 205M) |
*Carbon’s introductory pricing ($2.00/$10.00, $0.10 cache read) runs through November 30, 2026 before stepping up to $4.00/$20.00 on December 1, 2026.
Pushing a fast, inexpensive model all the way to xhigh trying to match a frontier model backfires twice: it inflates billed reasoning tokens by roughly 2.4x visible output while still missing architectural edge cases that require deeper multi-file reasoning. Keeping the fast model at medium effort (0.9x thinking multiplier) inside an explicit plan produced by a stronger model avoids both penalties.
2. The Per-Model Prefix-Cache Isolation Trap
In a 15-turn coding session with a 14,000-token repository prefix and 2,100 tokens of tool output per turn, cumulative prompt input exceeds 400,000 tokens. Provider context caching makes that affordable by billing previously prefilled prefixes at a 95% discount ($0.07 to $0.20 per million cached tokens instead of $1.50 to $4.00).
Here is the catch many multi-model prototypes miss: KV caches are bound to a specific model checkpoint.
Turn 1 [Carbon] ──▶ Prefills 14K cold (Carbon cache watermark = 15K)
Turn 2 [Hydrogen] ──▶ Prefills 17K cold! (Hydrogen cache = 0 -> 18K)
Turn 3 [Hydrogen] ──▶ 18K warm cache + 2.8K new (95% input discount!)
Turn 4 [Hydrogen] ──▶ 21K warm cache + 2.8K new (95% input discount!)
...
Turn 9 [Carbon] ──▶ Only 15K warm + 18K cold! (Carbon pays full prefill on turns 2..8)
If a router flips between Carbon and Hydrogen on every other turn (or escalates on the very first linter error), both models repeatedly pay cold input prefill on each other’s intermediate turns. Phase-boundary routing fixes this by concentrating execution into contiguous bursts on one checkpoint and escalating only after k consecutive check failures.
Comparing Three Multi-Model Routing Topologies
Modern agent systems organize frontier and fast models in three distinct shapes:
1. Single-Context Planner-Actor (Shared Transcript, Phase-Gated Handoffs)
[Planner: Carbon/Neon] ──plan──▶ [Actor: Hydrogen burst] ──(k=2 fails)──▶ [Planner re-plan]
Shared transcript: full verbatim tool logs visible to both tiers.
2. Executor-with-Advisor (Fast Loop + Compact Escalation Digest)
[Executor: Hydrogen] ──loop──▶ stuck? ──compact digest──▶ [Advisor: Carbon] ──guidance──▶ [Executor]
Zero upfront frontier turn; advisor sees a summary rather than raw tool traces.
3. Isolated Subagents (Parent Decomposer + Fresh-Context Workers)
[Parent: Carbon] ──brief 1..N──▶ [Fresh Worker: Hydrogen] ──summary──▶ [Parent integrates]
Bounds worker context on 24+ step refactors; pays cold prefix boot per worker.
Each topology makes a different bet across prefix-cache locality, verbatim trace visibility, and context-window width. Instead of guessing which one wins, let’s model and implement all three over one shared state engine.
Step 1: Isolated Per-Model Prefix Cache & Turn Economics
Every model specification in planner_actor/catalog.py is a frozen Pydantic v2 ModelSpec holding public pricing, decode throughput, supported thinking_level values, and empirical thinking-token multipliers. compute_turn_economics() computes exact cached versus uncached input tokens, thinking tokens, dollar cost, and prefill-plus-decode latency:
def compute_turn_economics(
spec: ModelSpec,
input_tokens: int,
reusable_prefix_tokens: int,
visible_output_tokens: int,
thinking_level: ThinkingLevel,
cache_efficiency: float,
) -> TurnEconomics:
if thinking_level not in spec.supported_thinking_levels:
raise ValueError(
f"thinking_level={thinking_level!r} not supported by {spec.model_id}; "
f"supported={spec.supported_thinking_levels}"
)
bounded_reusable = max(0, min(reusable_prefix_tokens, input_tokens))
cached_input = round(bounded_reusable * cache_efficiency)
uncached_input = max(0, input_tokens - cached_input)
thinking_mult = spec.thinking_multiplier_by_effort.get(thinking_level, 1.0)
thinking_tokens = round(visible_output_tokens * thinking_mult)
total_output_tokens = visible_output_tokens + thinking_tokens
input_cost = (
uncached_input * spec.input_per_1m_usd
+ cached_input * spec.cache_read_per_1m_usd
) / 1_000_000.0
output_cost = (total_output_tokens * spec.output_per_1m_usd) / 1_000_000.0
...
Inside planner_actor/topologies.py, _SharedConversationState tracks one growing transcript_tokens counter alongside a dictionary cached_prefix_by_model: dict[str, int]. Whenever record_turn() executes on model_id, only cached_prefix_by_model.get(model_id, 0) counts as reusable prefix, accurately reflecting the real cold-prefill penalty whenever control crosses checkpoint boundaries.
Step 2: Live Public google-genai Adapter (ThinkingConfig)
The routing runners depend strictly on a ModelClient protocol, so the exact same orchestration state machine runs both offline against DeterministicBenchmarkClient and live against the public Google GenAI Python SDK (google-genai):
from google import genai
from google.genai import types
class GeminiGenAiClient:
def __init__(self, *, api_key: str | None = None, pricing_schedule="standard_dec2026"):
self._pricing_schedule = pricing_schedule
self._client = genai.Client(api_key=api_key)
def build_config(
self,
*,
thinking_level: ThinkingLevel,
max_output_tokens: int = 8_192,
system_instruction: str | None = None,
) -> types.GenerateContentConfig:
kwargs = {
"thinking_config": types.ThinkingConfig(thinking_level=thinking_level),
"max_output_tokens": max_output_tokens,
}
if system_instruction:
kwargs["system_instruction"] = system_instruction
return types.GenerateContentConfig(**kwargs)
After each live call, GeminiGenAiClient.invoke() reads usage_metadata.prompt_token_count, cached_content_token_count, candidates_token_count, and thoughts_token_count directly from the SDK response so production telemetry logs identical unit economics per turn.
Guard Model-Specific Thinking Levels at the Boundary
Public Gemini 4 Hydrogen and Neon accept thinking_level="xhigh", whereas Gemini 4 Carbon caps at "high". Validate requested thinking levels against ModelSpec.supported_thinking_levels before issuing an RPC so a config override never fails halfway through a multi-step agent run.
Step 3: Phase-Gated Escalation (k = 2 Consecutive Failures)
The core control rule in SingleContextPlannerActorRunner is intentionally compact:
- Read-Only Planning Phase (Turn 1): The Planner (
gemini-4-carbonorgemini-4-neonathigh) reads repository context and outputs an explicit step-by-step plan and verification contract. - Contiguous Actor Burst: Control switches once to the Actor (
gemini-4-hydrogenatmedium). Turn 2 warms Hydrogen’s prefix cache; Turns 3 throughNride its warm KV cache at$0.07/1Mcached reads and ~173 tok/s decode speed. - Failure-Streak Escalation Guard (
consecutive_failures >= k): A single transient lint or assertion miss stays local so Hydrogen self-corrects on its warm cache without bouncing back to the Planner. Only whenkconsecutive checks fail (defaultk = 2) or an interface mismatch blocks progress does control escalate back to the Planner, which inspects the verbatim failure trace in the shared transcript, writes a revised plan, and hands execution back to the Actor.
Benchmark Results: 12-Task Suite Across Pricing Schedules
The companion package includes a deterministic 12-task evaluation suite (planner_actor/benchmark.py) spanning 4 routine tasks (6 to 8 steps, 4.5K to 6K repo context), 4 multi-file refactors (12 to 14 steps, 12K to 16K context), and 4 architectural edge-case debugging tasks (14 to 18 steps, 18.5K to 26K context, each embedding a hidden interface/concurrency trap that requires architectural re-planning).
Running the full suite (13/13 pytest passing, 0 ruff warnings) under December 1, 2026 standard API rates produces the following scorecard (analytical simulation grounded in public Gemini 4 pricing and Artificial Analysis throughput):
=== Multi-Model Routing Scorecard (standard_dec2026, k=2) ===
| Topology | Pass | Cost / Task | Latency | Thinking Tok | Cache Hit | Switches | Escalations |
|---|---|---|---|---|---|---|---|
| Carbon solo (high) | 12/12 (100%) | $0.922 | 465.9s | 15,943 | 81.9% | 0.00 | 0.00 |
| Neon solo (high) | 12/12 (100%) | $0.684 | 251.7s | 15,444 | 81.9% | 0.00 | 0.00 |
| Neon solo (xhigh) | 12/12 (100%) | $0.774 | 308.6s | 21,423 | 81.9% | 0.00 | 0.00 |
| Hydrogen solo (xhigh) | 8/12 (67%) | $0.361 | 187.2s | 21,920 | 81.8% | 0.00 | 0.00 |
| Planner-Actor (Carbon -> Hydrogen) | 12/12 (100%) | $0.491 | 174.9s | 10,834 | 77.8% | 1.67 | 0.33 |
| Planner-Actor (Neon -> Hydrogen) | 12/12 (100%) | $0.444 | 148.3s | 10,772 | 77.8% | 1.67 | 0.33 |
| Advisor (Hydrogen + Carbon) | 12/12 (100%) | $0.362 | 140.3s | 10,234 | 82.4% | 0.67 | 0.33 |
| Subagents (Carbon + Hydrogen) | 12/12 (100%) | $0.423 | 187.7s | 10,902 | 58.9% | 2.67 | 0.33 |
=== Escalation Threshold Sweep (Carbon -> Hydrogen) ===
| Topology | Pass | Cost / Task | Latency | Thinking Tok | Cache Hit | Switches | Escalations |
|---|---|---|---|---|---|---|---|
| Carbon -> Hydrogen (k=1) | 12/12 (100%) | $0.559 | 200.5s | 11,568 | 76.3% | 3.17 | 1.08 |
| Carbon -> Hydrogen (k=2) | 12/12 (100%) | $0.491 | 174.9s | 10,834 | 77.8% | 1.67 | 0.33 |
| Carbon -> Hydrogen (k=3) | 12/12 (100%) | $0.507 | 178.3s | 11,083 | 77.9% | 1.67 | 0.33 |
Four Engineering Takeaways From the Numbers
- Planner-Actor cuts Carbon-solo cost nearly in half while running 2.66x to 3.14x faster: Under Dec 1 standard pricing, Carbon -> Hydrogen (
k=2) drops mean cost from$0.922to$0.491(-46.7%) and wall-clock time from465.9sto174.9s(2.66x faster) while keeping12/12pass rate and77.8%effective prefix-cache reuse. Swapping the Planner to Neon -> Hydrogen drops cost further to$0.444(-51.8% vs Carbon solo, -35.1% vs Neon solo) in148.3s. Hydrogen solo (xhigh)emits the highest thinking tokens of any configuration: At21,920mean thinking tokens per task (higher than Carbon solo’s15,943!), Hydrogen atxhighstill drops to8/12 (67%)on architectural edge cases, putting its effective cost per resolved task at$0.542, more expensive than Planner-Actor ($0.444to$0.491) at100%completion.- Why
k = 2beats bothk = 1andk = 3: Escalating on the very first failure (k = 1) nearly doubles model switches (3.17vs1.67) and triples escalations (1.08vs0.33), adding +13.8% cost ($0.559vs$0.491) and +25.6s of latency on transient lint and test slips that Hydrogen resolves locally. Waiting for three strikes (k = 3,$0.507) wastes an extra doomed execution turn on genuine architectural blockers before calling the Planner. - Pricing schedules change the single-model frontier: Running the same benchmark with
--pricing intro_nov2026(Carbon$2/$10) makes Carbon solo ($0.461) 33% cheaper than Neon solo ($0.684). Once Carbon steps up to$4/$20on December 1, Neon solo ($0.684,251.7s) becomes the dominant single-model baseline, and Planner-Actor hybrids widen their savings margin dramatically.
When to Choose Each Topology
| Scenario | Recommended Topology | Why It Wins |
|---|---|---|
| Multi-file feature or complex bugfix (8 to 24 steps) | Single-Context Planner-Actor (Neon or Carbon -> Hydrogen, k=2) | Upfront plan prevents dead-end edits; verbatim shared transcript gives the Planner full stack traces on escalation; 77.8% prefix-cache hit rate. |
| High-volume, well-scoped CI triage / routine fixes | Executor-with-Advisor (Hydrogen + Carbon advisor) | Skips the upfront frontier planning call completely ($0.362/task, 140.3s, 82.4% cache hit); pays frontier tokens only on the small fraction of stuck runs. |
| Parallel multi-module migrations (24+ steps, huge diffs) | Isolated Subagents (Carbon parent + Hydrogen workers) | Caps per-worker context width (58.9% cache hit, $0.423/task), preventing quadratic transcript bloat and enabling parallel fan-out across disjoint directories. |
| Ultra-hard single-shot research or security audit (under 6 steps) | Single-Model Frontier (Carbon or Neon at high/xhigh) | Too few execution steps to amortize a cold model switch; keeping 100% of reasoning in one warm frontier context avoids handoff overhead. |
Explore Your Own Workload Parameters
Open the Multi-Model Agent Routing Simulator to sweep step counts (4 to 36), check failures, k thresholds, repo prefix size (4K to 48K), and thinking-effort multipliers interactively, and see the exact escalation ceiling where single-model Neon crosses over Carbon-plus-Hydrogen.
Keep Exploring
Related Guides
Agent Orchestration in Practice: Google ADK vs LangGraph vs AWS Strands
Build the same live NOAA, Open-Meteo, and NWS marine report workflow in Google ADK 2.x and LangGraph on Vertex AI, then compare state graphs, parallel fan-out, failure handling, and LLM round-trip costs against AWS Strands.
Stateful Agent Memory: Rolling Sessions vs Vector RAG vs Vertex AI Memory Bank
Benchmark rolling ADK sessions, keyword recall, SQLite vector RAG, and consolidated slot memory across an 8-session coastal history using Google ADK 2.14 and Vertex AI Memory Bank.
Building an AI Trading Agent with Claude and News Signals
Build an automated trading agent that extracts market signals from news using Claude Haiku, executes trades via Alpaca, and manages positions with trailing stops and sentiment monitoring.
Discussion
to join the discussion.