Skip to main content
Blitz
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage
Edit page

Model Tiering & Savings

Spec: .agents/specs/009-model-tiering.md (implemented across TIER-01 through TIER-13).

Running every turn, sub-agent, log scrape, and architectural plan on a single frontier model wastes output and thinking tokens on routine work. Running everything on a small model burns extra retries when a bug gets hard. Blitz’s Model Tiering feature treats models as dynamic compute resources: it routes each subtask to the smallest tier that fits, dials thinking effort up or down as complexity changes, escalates automatically when loops stall, and measures cost per finished task rather than raw cost per token.

Model tiering is off by default ([tiers] enabled = false). When off, Blitz uses your configured model and explicit [agent_models] pins unchanged.

Architecture: Hub-and-Spoke Escalation

When enabled, Blitz implements a Router-Worker-Verifier workflow that preserves prompt cache prefixes across tiers:

flowchart TD
    U["User Request"] --> P{"Plan or Execute?"}
    P -- "/plan (read-only)" --> F1["Frontier Tier (Plan & Architecture)"]
    P -- "Standard turn" --> M1["Mid-Tier Hub (blitz)"]
    F1 -- "Plan approved" --> M2["Mid-Tier Carry-Out & Workers (coder, qa, helios)"]
    M1 -- "Research / extraction" --> L1["Lightweight Tier (web-retriever, summaries)"]
    M1 -- "Substantial code" --> M2
    M2 -- "Large raw tool output (optional)" --> L2["Lightweight Edge Compression"]
    L2 --> M2
    M2 -- "2+ failures or 60% budget burn" --> F2["Frontier Escalation (diagnose + promote endpoint)"]
    F2 --> M2
    M2 -- "Files modified (optional verify_diff)" --> F3["Frontier Diff Critique (capped <= 600 tokens)"]
    F3 --> OUT["Completed Task + Task Economics Telemetry"]
    M2 --> OUT
    L1 --> OUT

Core Design Principles

  1. Route by subtask, not only by agent role: /plan runs route to Frontier while the approved CarryOutPrompt execution drops to Mid-Tier; sub-agents route by role (lightweight, mid, frontier) or an explicit invoke_agent tier hint; stalled sub-agents promote their active model endpoint mid-run to Frontier (escalatingModel).
  2. Dynamic thinking effort at runtime: When tiering is on, dynamic_effort is on by default—dialing reasoning_effort down on clean, routine tool steps and up when failures or large contexts appear, while preserving xhigh on providers that support it (and never overriding explicit /effort, [model_settings], or agent frontmatter).
  3. Cache-aligned isolation: Each tier maintains its own sticky OpenAI prompt_cache_key (sessionID:tier), keeps static system prompts and tool definitions fixed at the top of requests, caches edge-compressed tool outputs deterministically by content hash, and never mutates thinking_budget mid-conversation.
  4. Measure cost per finished task: Every turn and sub-agent records total USD cost, model-call count, escalation flag, and outcome so /reflect can spot false economies and recalibrate routing thresholds.

Model Tiers by Provider

By default, Blitz resolves tiers within your active provider so enabling tiering never surprises you with missing keys or cross-provider billing. Explicit overrides in [tiers] can mix providers freely (for example, Gemini Hydrogen for Lightweight with Anthropic Sonnet/Opus for Mid and Frontier).

Provider Lightweight Mid-Tier Frontier Notes
gemini (API & Vertex ADC) gemini-3.8-flash gemini-4-hydrogen gemini-4-neon Honors org ModelAllowed policy (gemini-4-carbon via override)
anthropic / vertex-anthropic claude-haiku-4-5 claude-sonnet-5 claude-opus-5 Honors org ModelAllowed policy
openai gpt-5-mini gpt-5 gpt-5.4-pro Honors org ModelAllowed policy
antigravity gemini-4-hydrogen-low claude-sonnet-4-6 claude-opus-4-6-thinking Via agy ACP CLI
claude-acp claude-haiku-4-5 claude-sonnet-5 claude-opus-5 Via Claude Code ACP
api / enterprise Auto-matched from gateway model list Auto-matched or active model Auto-matched from gateway model list Matches token classes (flash/haiku/mini/hydrogen, hydrogen/sonnet/neon, opus/carbon/pro/neon)
bedrock / azure / ollama Explicit [tiers] override Active model / override Explicit [tiers] override Unset tiers fall back gracefully to the active model

Precedence Order

When resolving a model for any agent or subtask, Blitz applies strict precedence (TIER-03):

  1. Explicit [agent_models] pin or agent default_model (always wins)
  2. Explicit run-wide model override (WithModel, e.g., a job or eval model)
  3. Explicit subtask override (WithTierOverride for /plan / carry-out, or invoke_agent(tier=...))
  4. Agent frontmatter tier (lightweight, mid, frontier)
  5. Session or workspace active model (graceful fallback)

Built-in Agent Tier Assignments

All 12 built-in agents declare a default tier in frontmatter (inert until tiering is enabled):

Tier Built-in Agents Auxiliary Calls Primary Purpose
Lightweight web-retriever, agent-creator Welcome suggestions, session summaries, query drafts, auto-mode approval/hook/goal reviews (when [permissions.auto] model is unset), optional edge_compress Burn high raw token volume cheaply; extract clean facts and structured files
Mid-Tier blitz, coder, qa, helios, project-setup, harness-reflect, harness-update Approved plan carry-out (CarryOutPrompt), localized 1–2 file plans Handle ~80% of coding, testing, and multi-step orchestration
Frontier planning-agent, project-spec, model-judge Cross-cutting /plan turns, failure/budget escalation, optional verify_diff High-leverage architecture, root-cause recovery, and short asymmetric critique

Model Selection Decision Tree

flowchart TD
    START["Incoming Turn or Subtask"] --> PIN{"Explicit pin or override? ([agent_models], /model, WithModel)"}
    PIN -- "Yes" --> USE_PIN["Use Pinned / Explicit Model (Precedence 1–2)"]
    PIN -- "No" --> MODE{"Dynamic Tiering Enabled? ([tiers] or /tiers on)"}
    MODE -- "No" --> ACTIVE["Use Session / Workspace Default Model"]
    MODE -- "Yes" --> KIND{"What kind of work is it?"}

    KIND -- "Approval review, summary, suggestions, edge_compress >16KB" --> LIGHT["Lightweight Tier (low on Gemini/Anthropic, minimal on OpenAI)"]
    KIND -- "Multi-page research, docs/release sync, agent spec" --> LIGHT_SUB["Delegate to Isolated Sub-Agent (web-retriever, docs-engineer, agent-creator)"]

    KIND -- "Root orchestration, coding, tests, coverage, ACP, CarryOutPrompt" --> MID["Mid-Tier (low -> medium -> high)"]
    KIND -- "Planning or Review" --> SCOPE{"Cross-cutting across >=3 packages or subtle invariants?"}

    SCOPE -- "No (1–2 known files)" --> MID_PLAN["Mid-Tier Plan (planning-agent with tier=mid)"]
    SCOPE -- "Yes (cross-subsystem / /plan / review)" --> CTX{"Root context > 100k tokens?"}

    CTX -- "Yes" --> FRONT_SUB["Delegate to planning-agent (Frontier, fresh sub-context)"]
    CTX -- "No" --> FRONT["Frontier Tier (high -> xhigh)"]

Dynamic Controls in Detail

Waterfall & Budget-Cap Escalation

  • Confidence-based waterfall (escalate_after_failures, default 2): Tracks consecutive deterministic tool/command failures (tool errors or nonzero run_shell_command exit codes), resetting on any successful state-changing tool or exit-0 command. On reaching the threshold, Blitz calls the Frontier tier (bounded to 30s and 500 output tokens) to diagnose the root cause, attaches frontier_escalation to the tool result, and promotes the sub-agent’s active endpoint (escalatingModel) to Frontier for recovery turns.
  • Budget-cap escalation (escalate_budget_pct, default 60): If a budgeted lower-tier sub-agent burns 60% of its max_turns while failures remain unresolved, Blitz escalates to Frontier to re-plan rather than letting a cheaper model spin through the remaining budget.

Dynamic Thinking Effort Dialing

Thinking and reasoning tokens are billed at the output token rate (typically 5x the input rate and 50x the cached-input rate). With dynamic_effort on (the default whenever tiering is enabled), Blitz adjusts reasoning_effort per model call while respecting any explicit /effort, [model_settings], or agent frontmatter override:

Active Tier Routine / Small Context Standard Turn Error Present or Large Context
Lightweight minimal on OpenAI (< 8k tokens, 0 failures); low on Gemini/Anthropic low low
Mid-Tier low (turn > 1, 0 failures, < 32k tokens) medium high (failures >= 1 or >= 64k tokens)
Frontier high high xhigh (failures >= 1 or escalated)

Blitz never mutates thinking_budget mid-conversation, preserving prompt caches on budget-based models.

Optional Edge Compression & Asymmetric Review

  • Edge Context Compression (edge_compress, default false): Routes oversized (> 16,384 bytes by default) noisy outputs from run_shell_command, manage_background_process, web_fetch, and MCP tools through the Lightweight tier before they enter Mid-Tier or Frontier context. Results are cached deterministically by sha256(tool, key, raw) so repeated turns never break prompt caching; read_file, edit/search tools, and error/path/diagnostics keys are never touched, and full outputs remain in stored history.
  • Asymmetric Diff Review (verify_diff, default false): After a Mid-Tier sub-agent modifies workspace files, runs a short Frontier critique (capped at 600 output tokens over up to 12 KB of git diff) and appends ### Frontier Review to the sub-agent summary.

Potential Savings Analysis

All estimates below use Blitz’s built-in list prices (pkg/config/features.go):

  • Anthropic: Haiku 4.5 ($1.00 in / $5.00 out / $0.10 cached), Sonnet 5 ($2.00 in / $10.00 out / $0.20 cached), Opus 5 ($5.00 in / $25.00 out / $0.50 cached)
  • Gemini: 3.8 Flash ($0.75 in / $3.75 out / $0.075 cached), 4 Hydrogen ($1.50 in / $7.50 out / $0.075 cached), 4 Neon ($3.00 in / $15.00 out / $0.15 cached)

Scenario 1: Standard Feature / Bug Fix (Plan + 12-Step Code & Test Loop)

Assumes a 30k-token workspace context (~85% prompt cache hit rate after turn 1), 1 planning pass (1.5k output + 3k thinking tokens), 12 coding/test steps (800 output + 1.5k thinking tokens/step on Frontier vs. 600 thinking tokens/step with Mid-Tier + dynamic_effort), and 1 session summary.

Configuration Anthropic (Claude 5 / Haiku 4.5) Gemini (Neon / Hydrogen / 3.8 Flash) Savings vs. Frontier-Only
Frontier-only baseline (Opus 5 or Neon everywhere) ~$0.88 ~$0.53 —
Tiered routing only (/plan Frontier, coder Mid-Tier, summary Lightweight) ~$0.49 ~$0.29 44% – 45%
Tiered + Dynamic Effort (low effort on clean Mid-Tier tool steps) ~$0.36 ~$0.21 59% – 60%

Scenario 2: Docs Research + Multi-File Refactor with Noisy Shell Logs

Assumes 3 large web_fetch / run_shell_command outputs (~40 KB / ~10k tokens each) feeding into a 15-step refactor, plus a final Frontier verify_diff pass (400 output tokens).

Configuration Anthropic Gemini Savings vs. Frontier-Only
Frontier-only baseline ~$1.42 ~$0.85 —
Tiered + Dynamic Effort + edge_compress + verify_diff ~$0.52 ~$0.31 63% – 64%

Why verify_diff is cheap: reading a 3k-token diff and writing a 400-token critique on Opus 5 costs ~$0.025 ($0.015 input + $0.010 output), compared to ~$0.30+ to have Opus 5 generate the full 12k tokens of edits and test output itself.

Scenario 3: Stalled Test Loop (Why Escalation Beats Pure Cheap Models)

A Lightweight model that spins for 6 failed tool loops on a subtle concurrency bug can spend more in cumulative context re-reads and wasted output tokens than a Mid-Tier worker that escalates once on failure #2 and finishes on step #4:

  • Lightweight spinning (6 failed loops, unresolved): ~180k cumulative input + 12k output tokens + developer time wasted.
  • Mid-Tier + Frontier waterfall escalation on failure #2: 1 compact Frontier diagnosis (2k input + 400 output tokens = **$0.02** on Opus 5), followed by a clean fix and green test run.

Summary of Expected Impact

Lever Typical Savings Main Trade-Off
Role & subtask tiering (/plan Frontier, workers Mid, research/summaries Lightweight) 25% – 45% total turn cost One cold cache write (~$0.05–$0.08) on /plan to carry-out model switch, amortized over 5+ steps
Dynamic thinking effort (dynamic_effort = true, default with /tiers on) 25% – 50% thinking/output token spend None on prompt cache; explicit /effort overrides anytime
Edge context compression (edge_compress = true, opt-in) 15% – 35% input tokens on log/web-heavy sessions Adds 1–3s latency per oversized (>16 KB) noisy tool output
Asymmetric review (verify_diff = true, opt-in) Catches Frontier-level bugs at ~5–10% of Frontier generation cost Adds one short (~3–6s) Frontier call after file-editing sub-agents
Combined (typical coding session) 40% – 65% lower cost per finished task Opt-in behind [tiers] / /tiers

Enabling & Configuring

Per-Session Switch (/tiers)

Available in both the terminal REPL and the desktop composer:

/tiers                          Show current tiering settings
/tiers on                       Enable tiering (role routing + escalation + dynamic effort)
/tiers off                      Disable tiering and return to the active model
/tiers lightweight <model>      Override the Lightweight model (e.g. gemini/gemini-4-hydrogen)
/tiers mid <model>              Override the Mid-Tier model (e.g. anthropic/claude-sonnet-5)
/tiers frontier <model>         Override the Frontier model (e.g. anthropic/claude-opus-5)
/tiers escalate on|off          Toggle waterfall & budget-cap escalation
/tiers effort on|off            Toggle dynamic thinking effort dialing
/tiers compress on|off          Toggle Lightweight edge compression of large noisy tool outputs
/tiers verify on|off            Toggle Frontier asymmetric diff review after coding sub-agents

Global or Workspace Configuration (.env.toml)

[tiers]
enabled = true
# Optional explicit model overrides (same-provider or cross-provider):
# lightweight = "anthropic/claude-haiku-4-5"
# mid = "anthropic/claude-sonnet-5"
# frontier = "anthropic/claude-opus-5"
escalate_after_failures = 2     # deterministic tool/test failures before Frontier escalation
escalate_budget_pct = 60        # % of sub-agent turn budget burned with failures before escalation
dynamic_effort = true           # dial reasoning_effort by tier, context size, and error count
edge_compress = false           # compress oversized noisy tool outputs via Lightweight tier
edge_compress_bytes = 16384     # byte threshold for edge compression
verify_diff = false             # run capped Frontier review on git diff after Mid-Tier edits

Measuring Cost per Finished Task & Recalibrating

Model tiering is instrumented end-to-end so you can verify whether tier choices actually reduce cost per completed task:

  • OpenTelemetry metrics (pkg/observability):
    • blitz.task.cost_usd (histogram, USD) and blitz.task.calls (histogram, calls) tagged by agent, tier, escalated, and outcome (ok, error, limit, canceled)
    • blitz.tier.calls (counter, by tier, agent, model)
    • blitz.tier.escalations (counter, by from_tier, to_tier, reason)
    • blitz.cache.hit_ratio and blitz.model.ttft to verify prompt caches stay warm across turns
  • Audit log & /reflect: Each finished turn and sub-agent writes a numeric task_outcome audit record (never prompt content). harness_evidence aggregates recent runs by (agent, tier) into a Task Economics summary (task count, average USD/task, average calls/task, escalation rate, failure rate), allowing /reflect to flag agents whose lower tier is burning retries and recommend adjusting [tiers] thresholds or agent tier assignments.