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)¶
INV-001— Cost-Compression Monotonicity & Inclusive Bounds (Hypothesis): Across arbitrary non-negative token triples and all7PromptCacheModevariants,0.0 <= cache_hit_ratio <= 1.0,effective_billed_input_tokens >= 0.0, pure cache reads strictly reduceeffective_billed_input_tokens(0.10x), andPromptCacheMode.OFF/PREFIX_ONLYnever emit inlineCachePointmarkers.INV-002— Canonical StaticInstructionPartPrefix Identity:build_specify_agent,build_instrument_agent,build_synthesize_agent, andbuild_refactor_agentemit identical non-dynamicInstructionPart#0 (JBC_STATUTORY_BRIEF) and #1 (JBC_CANONICAL_EXEMPLAR) before specialist role instructions; all4SDD baseline agents emit identicalInstructionPart#0 (SDD_CONSTITUTION_MD).INV-003— Parallel Slice Shared Prefix +CachePointPartitioning: FullPceWorkflowOrchestratorexecution over a 2-scope mandate (MND-CACHE-PAR-001) proves concurrentInstrumentNodeandDelegateNodeworkers emit byte-identical shared user-prompt prefixes (Mandate + Snapshots) followed immediately byCachePointand distinct scope suffixes, whilePromptCacheMode.OFFemits contiguous strings with0CachePointobjects andPceWorkflowResultaggregates exactcache_read_tokens(80.0%hit ratio,72.0%input-cost savings).INV-004—448 / 448Offline Cross-Provider Wire Compatibility:verify_cross_provider_agent_compatibility()executes all16agents (12PCE+4SDD) \(\times\)7provider models \(\times\)4PromptCacheModes (auto,off,5m,1h) through realModel.prepare_request(...)pipelines with0failures (all_compatible == True), verifying Anthropicanthropic_cache*injection, OpenAIopenai_prompt_cache_optionstranslation, Google clean strip, and strict tool/output JSON Schema validity.INV-005— Multi-Suite / Cache-Ablation Matrix Runner:parse_provider_suite_spec(<label>=<provider:model>[@<cache>]or<label>=arch:<m>,build:<m>[@<cache>]) andrun_provider_matrix_benchmarkproduce side-by-sideProviderMatrixComparisonsummaries and Markdown tables isolating cache-on vs. cache-off billed-token savings.INV-006— Config, CLI--prompt-cache, &--suitePrecedence:[tool.jezz.models] prompt_cache = "1h"inpyproject.toml,--prompt-cacheCLI overrides acrossrun/renovate/benchmark,jezz run --plan-onlycache telemetry rendering, andjezz benchmark --suite ... --suite ...JSON/Markdown output all pass end-to-end.INV-007— Provider-AwareCachePointCoalescing (normalize_prompt_for_model): Explicit breakpoint providers (AnthropicModel,OpenAIResponsesModel,OpenRouterModel,FunctionModel) preserve(shared_prefix, CachePoint, suffix)tuples intact, whereas implicit-prefix models (GoogleModelandTlsResilientModel(GoogleModel)) coalesce to contiguousstrpayloads.
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¶
68.7%–72.5%LivePCEPrefix-Cache Hit Rate vs.0.0%on Open-Loop SDD: Across all5Control SDD builds (0/5JBCoccupiable,98totalJBCviolations,4/5failingmypy --strict),cache_read_tokenswas0 / 115,300(0.0%) because 1-shot Markdown expansion never reuses a static prefix. Conversely, across all4certifiedPCEbuilds (0JBCviolations,12/12held-outHypothesisoracle checks),PCE's canonical(JBC_STATUTORY_BRIEF, JBC_CANONICAL_EXEMPLAR, specialist_role)InstructionPartordering and sharedMandate + Snapshotsprefix achieved797,217 / 1,160,159(68.7%, peaking at72.5%in Wave 7B) server-side cache reads—compressing1,160,159raw input tokens down to442,664effective billed input tokens (-61.8%overall;-65.2%on Wave 7Bcase_06).Wave 7A -> 7BGoogleModelContent.partsCalibration: Wave 7A discovered that becauseGoogleModelignores inlineCachePointmarkers (profile['supports_cache'] == False), passing(prefix, CachePoint(), suffix)split each user prompt into twoPartDictsegments ([{'text': prefix}, {'text': suffix}]) for zero cache gain and degraded 2-scope instruction adherence oncase_06_escrow_machine. CoalescingCachePointtuples into contiguous strings on implicit-prefix models vianormalize_prompt_for_model(Wave 7B) restored100%JBCv1.2 occupancy and3/3oracle survival oncase_06under@autowhile achieving72.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