Aggregate reasoning usage and derive cache hit ratios

This commit is contained in:
2026-11-22 18:22:07 +00:00
parent db1cad6d2d
commit 3d82cad2c9
11 changed files with 114 additions and 11 deletions

View File

@@ -101,6 +101,16 @@ type ObservedTokenUsage struct {
CacheWriteTokens ObservedTokenCount
}
// CacheHitRatio returns the fraction of input tokens served from cache when
// both counts are known, complete, and consistent. Cache writes are independent.
func (u ObservedTokenUsage) CacheHitRatio() (float64, bool) {
input, reads := u.PromptTokens, u.CachedTokens
if !input.Known || !input.Complete || !reads.Known || !reads.Complete || input.Value <= 0 || reads.Value < 0 || reads.Value > input.Value {
return 0, false
}
return float64(reads.Value) / float64(input.Value), true
}
// ExecutionEvent contains metadata only, not provider text, request content,
// credentials, URLs, headers, or error objects. It has no stable JSON contract.
// Identifiers themselves may be sensitive. Nonterminal aggregate counters are