← Back to GeminiPulse Home

Cost-Per-Task Architecture Series • Part 3 of 3

The Caching Dilemma & Production Blueprints: When to Route vs. Lock In Context Caching

Published November 3, 2026 • Primary Google Source: Google Developers Blog (Google Cloud AI Production Architecture)
⚠️ The Hidden Architectural Conflict:

In isolation, routing short tasks saves money and cuts latency. But in modern agent harnesses, routing and context caching pull in opposite directions. Gemini Context Caching delivers a 75% to 90% discount when re-sending massive prompt blocks (such as codebase ASTs and tool manifests). However, context caches are tied to a specific model. If an agent bounces between Flash-Lite and Flash turn-by-turn, it either pays to maintain dual caches or destroys the caching discount entirely.

1. The Two Halves of Production Agent Traffic

To maximize both speed and cost-efficiency without losing caching advantages, production teams split their architecture across two distinct workload topologies:

Topology A: Short, Self-Contained Atomic Tasks ROUTE WITH CLASSIFIER

Workload: Commit diff inspections, syntax error parsers, CI test failure extractions, log filtering, git conflict classification.

Context Profile: Under 4,000 tokens per call. No large ongoing conversational state.

Routing Strategy: Evaluate with the atomic Noul classifier. Send simple tasks to gemini-3.5-flash-lite ($0.10/1M, 0.5s latency). Escalate complex tasks to gemini-3.8-flash on thinkingLevel: "LOW".

Financial Impact: Cuts latency by up to 60% and slashes micro-decision spend to negligible levels.

Topology B: Multi-Turn Context-Heavy Agent Sessions LOCK MODEL + CONTEXT CACHE

Workload: Google Antigravity autonomous development, SWE-bench coding runs, multi-file refactors, deep architectural reviews.

Context Profile: 100K to 1M tokens of repository structure, schemas, and accumulated conversation history resent on every turn.

Routing Strategy: Do not route mid-loop. Lock the entire session to a single model—either gemini-3.8-flash or gemini-4-argon. Warm an implicit Context Cache on Turn 1 and consume the 75%–90% caching discount across all subsequent turns.

Financial Impact: Preserves the cache discount ($0.10/1M tokens cached input vs. full prompt rates), preventing cache misses that dwarf any minor model routing savings.

2. High-Volume Warehouse Batching: The Cascade Pattern

For enterprise batch analytics, document processing, and data warehouse enrichment, Google Cloud advocates Jeff Nelson's BigQuery & Cloud Run cascade pattern:

3. The Essential Telemetry Stack: Measuring What Agents Actually Spend

Because token pricing can be deceptive, Google recommends streaming full agent execution metrics directly into Cloud Logging and BigQuery:

// Production telemetry schema for autonomous agents
interface AgentTaskTelemetry {
  taskId: string;
  model: 'gemini-3.5-flash-lite' | 'gemini-3.8-flash' | 'gemini-4-argon';
  thinkingLevel?: 'LOW' | 'MEDIUM' | 'HIGH';
  routerVerdict: 'SIMPLE' | 'COMPLEX';
  classifierConfidence: number;
  inputTokens: number;
  outputTokens: number;
  thinkingTokens: number;
  cachedTokens: number;
  durationMs: number;
  truncated: boolean; // Vital: flags if maxOutputTokens killed reasoning
  passedVerification: boolean; // Vital: denominator for Cost Per Successful Task
}

By querying this telemetry in BigQuery, platform engineers can track their real Cost Per Successful Task over time, identify tasks driving unexpected thinking spikes, and catch silent truncation errors before they impact users.

4. Try the Live Simulator

To test these production economics directly against your own agent workloads, explore our companion interactive tool:

Gemini Cost-Per-Task & Routing Simulator [SIMULATED DEMO]

Simulate task success rates, output token caps, thinking levels, and context caching trade-offs across 100,000 monthly tasks.

Launch Interactive Simulator →