Track prompt cache hits and stabilize request prefix #5
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "t3code/prompt-cache-tracking"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Usage(cachedTokens), aggregating them inaddUsagewhile keeping the field absent when no provider reports cache stats.cacheHitRatein core, clamped to 0-1, derived fromcachedTokens / inputTokensandundefinedwhen input is unknown.extractCachedTokens, preferringprompt_tokens_details.cached_tokensand falling back to DeepSeek'sprompt_cache_hit_tokens.cacheHitRateandcachedTokensin the web UI: compactN% cachedsession label plus a cached count/rate in the usage tooltip.ToolRegistry.toToolSpecs()and the provider request body.prompt_cache_key(cacheKey) from the agent so providers route same-prefix requests to the same cache shard.Testing
cacheHitRate,addUsagecached handling, and cache detail formatting inpackages/core/src/messages.test.tsandapps/web/src/tokens.test.ts.extractCachedTokenstests covering nested OpenAI, DeepSeek fallback, and missing stats, plus streamed usage assertions inpackages/provider-openai/src/provider.test.ts.packages/kernel/src/registries.test.tsand verified sorted wire tools plusprompt_cache_keyin the provider request body.