Skip to content

Track 7 — Token Cost Compression & Cross-Provider Generalizability

1. Objective & Architectural Closure

Track 4's empirical A/B waves (docs/track-4-sdd-vs-pce-benchmark.md) and §6 of the technical white paper (docs/whitepaper.md) surfaced two concrete engineering trade-offs in jezz: 1. Token Cost Asymmetry: Certified PCE runs averaged 334,774 tokens (~5.7x–6.8x open-loop prose SDD) because JBC Edition 1.2's 31 statutory AST rules (JBC_STATUTORY_BRIEF), canonical jezz.guards idioms (JBC_CANONICAL_EXEMPLAR), and shared EngineeringMandate + workspace snapshots were re-transmitted uncached across every SPECIFY, INSTRUMENT, SYNTHESIZE, REFACTOR, and DELEGATE worker turn and ModelRetry self-correction loop. 2. Cross-Provider Portability & Matrix Benchmarking: While [tool.jezz.models] supported multi-provider identifiers, infer_authenticated_model and TlsResilientModel lived in cli.py, jezz.evals evaluated a single model suite per invocation, and strict structured-output / tool-parameter schemas across all 16 (12 PCE + 4 SDD) agents had not been continuously verified against Anthropic, OpenAI (Chat & Responses), Google Gemini, and OpenRouter wire translators.

Track 7 closes both gaps without compromising any Pillar 1–4 invariant: - Enabled-by-Default Cross-Provider Prompt Caching (PromptCacheMode.AUTO): Canonical leading static InstructionPart ordering across all construction specialists and symmetric SDD control stages, unified ModelSettings(cache=...) retention mapping (auto, off, prefix-only, 5m, 30m, 1h, 12h), and inline pydantic_ai.CachePoint prefix/suffix partitioning across parallel INSTRUMENT/DELEGATE slices and RED_TAG remediation suffixes. - First-Class Cache & Effective Billed-Token Telemetry: Provider-normalized cache_read_tokens, cache_write_tokens, cache_hit_ratio, effective_billed_input_tokens (0.10x cached reads, 1.25x explicit cache writes), and input_cost_savings_ratio threaded end-to-end from AgentInvocationTelemetry through PceWorkflowResult, ArmRunOutcome, ArmAggregateSummary, and Markdown/JSON benchmark reports. - Offline 448-Probe Cross-Provider Wire Verifier & Multi-Suite Matrix Runner (jezz.evals.cross_provider): Deterministic compilation of all 16 agents (12 PCE + 4 SDD) across 7 real provider model classes (GoogleModel, AnthropicModel, OpenAIChatModel, OpenAIResponsesModel, OpenRouterModel) and 4 PromptCacheModes (448 / 448 wire probes passing), paired with run_provider_matrix_benchmark and repeatable jezz benchmark --suite <label>=... CLI execution.


2. Subsystems & Key Modules

Module Public Surface Key Guarantees
src/jezz/agents/caching.py PromptCacheMode, CoercedPromptCacheMode, resolve_cache_model_settings, cache_point_for_mode, partition_cached_user_prompt, model_supports_inline_cache_points, normalize_prompt_for_model, compute_cache_hit_ratio, compute_effective_billed_input_tokens, compute_input_cost_savings_ratio Maps PromptCacheMode (auto default, off, prefix-only, 5m, 30m, 1h, 12h) onto pydantic_ai.ModelSettings(cache=...) and inline CachePoint(ttl=...), coalesces unsupported CachePoint tuples into contiguous strings on implicit-prefix models (GoogleModel), and enforces inclusive UsageBase bounds (@icontract + Hypothesis).
src/jezz/agents/providers.py infer_authenticated_model, TlsResilientModel Instantiates authenticated provider models across google, anthropic, openai / openai-chat / openai-responses, openrouter, groq, mistral, cohere, deepseek, xai, cerebras, fireworks, together, gateway/*, and test using pydantic.SecretStr without mutating os.environ (JBC-SEC-002, JBC-OBS-003), wrapped in bounded exponential-backoff TLS/5xx retry protection.
src/jezz/agents/specialists.py & nodes.py JBC_STATUTORY_BRIEF, JBC_CANONICAL_EXEMPLAR, build_{specify,instrument,synthesize,refactor}_agent, run_bounded_agent Emits independent static InstructionPart(..., dynamic=False) blocks (JBC_STATUTORY_BRIEF, JBC_CANONICAL_EXEMPLAR, specialist_role) so byte 0 of system instructions is identical across all 4 JBC construction specialists; partitions shared Mandate + Snapshots prefixes from slice-specific ModuleWriteScope / RED_TAG remediation suffixes via CachePoint across InstrumentNode, SynthesizeNode, RefactorNode, and DelegateNode.
src/jezz/agents/routing.py & schemas.py JezzModelsConfig.prompt_cache, CliModelOverrides.prompt_cache, ResolvedModelRouting.prompt_cache, PceRuntimeBudget.prompt_cache_mode, AgentInvocationTelemetry, PceWorkflowResult Resolves --prompt-cache \(\to\) [tool.jezz.models].prompt_cache \(\to\) PromptCacheMode.AUTO; aggregates total_input_tokens, total_cache_read_tokens, total_cache_write_tokens, cache_hit_ratio, effective_billed_input_tokens, and input_cost_savings_ratio per workflow run.
src/jezz/evals/sdd_baseline.py, schemas.py, verifier.py, runner.py build_sdd_{specify,design,tasks,implement}_agent, BenchmarkRunConfig.prompt_cache_mode, ArmRunOutcome, ArmAggregateSummary Applies symmetric leading InstructionPart(content=SDD_CONSTITUTION_MD, name="sdd_constitution") and identical prompt_cache_mode settings to all 4 Control SDD stages so Track 4 / Track 7 A/B comparisons remain strictly apples-to-apples (0 unilateral Treatment advantage).
src/jezz/evals/cross_provider.py & src/jezz/cli.py DEFAULT_WIRE_PROBE_MODELS, verify_cross_provider_agent_compatibility, ProviderSuiteSpec, parse_provider_suite_spec, run_provider_matrix_benchmark, format_provider_matrix_markdown, jezz benchmark --suite Exercises real Model.prepare_request(...) tool/output/cache compilation across 5 provider families offline (0 live network calls) and orchestrates multi-suite / cache-ablation pydantic-evals A/B matrices from Python or CLI.

3. Provider Prompt-Cache Translation Matrix (pydantic-ai v2.71.0)

Provider Family (DEFAULT_WIRE_PROBE_MODELS) Wire Adapter (Model.prepare_request) PromptCacheMode.AUTO (cache=True) Explicit Retention (5m / 30m / 1h / 12h) PromptCacheMode.OFF (cache=False)
Anthropic (anthropic:claude-sonnet-4-6, anthropic:claude-opus-4-6) AnthropicModel.prepare_request anthropic_cache_instructions=True, anthropic_cache_tool_definitions=True, anthropic_cache=True + inline CachePoint breakpoints Snaps 30m -> 5m and 12h -> 1h onto CachePoint(ttl=...) and anthropic_cache* Strips cache settings (params.cache is None), omits CachePoint
OpenAI Chat & Responses (openai-chat:gpt-5.6, openai-responses:gpt-5.6) translate_openai_cache (OpenAIChatModel / OpenAIResponsesModel) openai_cache_instructions=True, openai_prompt_cache_options={'mode': 'implicit'} Snaps 5m -> 30m and 1h -> 12h ({'mode': 'explicit', 'ttl': '30m'|'12h'}) Strips cache settings (params.cache is None), omits CachePoint
OpenRouter (openrouter:anthropic/claude-sonnet-4-6) OpenRouterModel (Model._resolve_cache) params.cache == True + inline CachePoint passthrough to upstream provider Snaps to supported retention (5m / 1h) + CachePoint(ttl=...) Strips cache settings (params.cache is None), omits CachePoint
Google Gemini (google:gemini-3.8-flash, google:gemini-4-hydrogen) GoogleModel (profile['supports_cache'] == False; server-side implicit prefix caching) Strips ModelSettings.cache cleanly and coalesces (prefix, CachePoint, suffix) via normalize_prompt_for_model into a single PartDict ([{'text': prefix + suffix}]) so Gemini's implicit prefix cache achieves 65%–72.5% hit rates without Content.parts fragmentation Graceful fallback (params.cache is None) + contiguous PartDict coalescing Contiguous string prompt (0 CachePoint objects)

4. Falsifiable Invariants Verified (tests/test_track7_caching_and_providers.py)

  1. INV-001 — Cost-Compression Monotonicity & Inclusive Bounds (Hypothesis): Across arbitrary non-negative token triples and all 7 PromptCacheMode variants, 0.0 <= cache_hit_ratio <= 1.0, effective_billed_input_tokens >= 0.0, pure cache reads strictly reduce effective_billed_input_tokens (0.10x), and PromptCacheMode.OFF / PREFIX_ONLY never emit inline CachePoint markers.
  2. INV-002 — Canonical Static InstructionPart Prefix Identity: build_specify_agent, build_instrument_agent, build_synthesize_agent, and build_refactor_agent emit identical non-dynamic InstructionPart #0 (JBC_STATUTORY_BRIEF) and #1 (JBC_CANONICAL_EXEMPLAR) before specialist role instructions; all 4 SDD baseline agents emit identical InstructionPart #0 (SDD_CONSTITUTION_MD).
  3. INV-003 — Parallel Slice Shared Prefix + CachePoint Partitioning: Full PceWorkflowOrchestrator execution over a 2-scope mandate (MND-CACHE-PAR-001) proves concurrent InstrumentNode and DelegateNode workers emit byte-identical shared user-prompt prefixes (Mandate + Snapshots) followed immediately by CachePoint and distinct scope suffixes, while PromptCacheMode.OFF emits contiguous strings with 0 CachePoint objects and PceWorkflowResult aggregates exact cache_read_tokens (80.0% hit ratio, 72.0% input-cost savings).
  4. INV-004 — 448 / 448 Offline Cross-Provider Wire Compatibility: verify_cross_provider_agent_compatibility() executes all 16 agents (12 PCE + 4 SDD) \(\times\) 7 provider models \(\times\) 4 PromptCacheModes (auto, off, 5m, 1h) through real Model.prepare_request(...) pipelines with 0 failures (all_compatible == True), verifying Anthropic anthropic_cache* injection, OpenAI openai_prompt_cache_options translation, Google clean strip, and strict tool/output JSON Schema validity.
  5. INV-005 — Multi-Suite / Cache-Ablation Matrix Runner: parse_provider_suite_spec (<label>=<provider:model>[@<cache>] or <label>=arch:<m>,build:<m>[@<cache>]) and run_provider_matrix_benchmark produce side-by-side ProviderMatrixComparison summaries and Markdown tables isolating cache-on vs. cache-off billed-token savings.
  6. INV-006 — Config, CLI --prompt-cache, & --suite Precedence: [tool.jezz.models] prompt_cache = "1h" in pyproject.toml, --prompt-cache CLI overrides across run/renovate/benchmark, jezz run --plan-only cache telemetry rendering, and jezz benchmark --suite ... --suite ... JSON/Markdown output all pass end-to-end.
  7. INV-007 — Provider-Aware CachePoint Coalescing (normalize_prompt_for_model): Explicit breakpoint providers (AnthropicModel, OpenAIResponsesModel, OpenRouterModel, FunctionModel) preserve (shared_prefix, CachePoint, suffix) tuples intact, whereas implicit-prefix models (GoogleModel and TlsResilientModel(GoogleModel)) coalesce to contiguous str payloads.

5. Live Gemini Empirical Cache-Ablation Results (Waves 7A & 7B — 10 Workspace Builds)

With Proton Pass CLI authenticated ([Agent] Antigravity), jezz benchmark --suite executed 10 live end-to-end workspace builds (5 Control SDD + 5 Treatment PCE) on tiered arch=google:gemini-4-hydrogen + build=google:gemini-3.8-flash across 1-scope case_01_bps_split and 2-scope parallel case_06_escrow_machine:

Wave & Suite Case ID Control SDD (JBC / mypy / Cache Hit%) Treatment PCE (JBC / Oracle) PCE Requests PCE Raw Input PCE cache_read_tokens (Hit%) PCE Effective Billed In (Savings)
7A gemini_cached (@auto, pre-coalesce) case_01_bps_split 13 viol (0 LS) / Pass / 0.0% 0 viol / 3/3 (100%) 24 239,034 163,958 (68.6%) 91,472 (-61.7%)
7A gemini_cached (@auto, pre-coalesce) case_06_escrow_machine 34 viol (2 LS) / Fail / 0.0% Halted (1 JBC-VRF-006) 108 1,136,413 761,271 (67.0%) 451,269 (-60.3%)
7A gemini_uncached (@off, contiguous) case_01_bps_split 15 viol (1 LS) / Fail / 0.0% 0 viol / 3/3 (100%) 19 156,621 102,699 (65.6%) 64,192 (-59.0%)
7A gemini_uncached (@off, contiguous) case_06_escrow_machine 17 viol (1 LS) / Fail / 0.0% 0 viol / 3/3 (100%) 33 292,113 188,311 (64.5%) 122,633 (-58.0%)
7B gemini_calibrated_auto (@auto, coalesced) case_06_escrow_machine 19 viol (1 LS) / Fail / 0.0% 0 viol / 3/3 (100%) 43 472,391 342,249 (72.5%) 164,367 (-65.2%)

Key Empirical Takeaways

  1. 68.7%–72.5% Live PCE Prefix-Cache Hit Rate vs. 0.0% on Open-Loop SDD: Across all 5 Control SDD builds (0/5 JBC occupiable, 98 total JBC violations, 4/5 failing mypy --strict), cache_read_tokens was 0 / 115,300 (0.0%) because 1-shot Markdown expansion never reuses a static prefix. Conversely, across all 4 certified PCE builds (0 JBC violations, 12/12 held-out Hypothesis oracle checks), PCE's canonical (JBC_STATUTORY_BRIEF, JBC_CANONICAL_EXEMPLAR, specialist_role) InstructionPart ordering and shared Mandate + Snapshots prefix achieved 797,217 / 1,160,159 (68.7%, peaking at 72.5% in Wave 7B) server-side cache reads—compressing 1,160,159 raw input tokens down to 442,664 effective billed input tokens (-61.8% overall; -65.2% on Wave 7B case_06).
  2. Wave 7A -> 7B GoogleModel Content.parts Calibration: Wave 7A discovered that because GoogleModel ignores inline CachePoint markers (profile['supports_cache'] == False), passing (prefix, CachePoint(), suffix) split each user prompt into two PartDict segments ([{'text': prefix}, {'text': suffix}]) for zero cache gain and degraded 2-scope instruction adherence on case_06_escrow_machine. Coalescing CachePoint tuples into contiguous strings on implicit-prefix models via normalize_prompt_for_model (Wave 7B) restored 100% JBC v1.2 occupancy and 3/3 oracle survival on case_06 under @auto while achieving 72.5% cache hits (-65.2% billed-input savings).

6. Reproducible Live Cache-Ablation & Multi-Provider Matrix Commands

Once Proton Pass CLI has an active authenticated session (pass-cli login), execute live cache-ablation or multi-provider pydantic-evals A/B sweeps directly via jezz benchmark --suite:

# 1. Live Gemini prompt-cache A/B probe (auto vs. off on matched tasks):
uv run jezz benchmark <work_dir> \
  --suite gemini_cached=arch:google:gemini-4-hydrogen,build:google:gemini-3.8-flash@auto \
  --suite gemini_uncached=arch:google:gemini-4-hydrogen,build:google:gemini-3.8-flash@off \
  --case-id case_01_bps_split \
  --write-json results/track7_cache_ablation.json

# 2. Cross-provider matrix sweep (Gemini vs. Anthropic Claude vs. OpenAI GPT-5.6):
uv run jezz benchmark <work_dir> \
  --suite gemini=arch:google:gemini-4-hydrogen,build:google:gemini-3.8-flash@auto \
  --suite claude=arch:anthropic:claude-opus-4-6,build:anthropic:claude-sonnet-4-6@5m \
  --suite openai=openai-responses:gpt-5.6@auto \
  --max-concurrency 2 \
  --write-json results/track7_provider_matrix.json