diff --git a/pkg/agent/pipeline_llm.go b/pkg/agent/pipeline_llm.go index b4c87634ed..a56318a3d5 100644 --- a/pkg/agent/pipeline_llm.go +++ b/pkg/agent/pipeline_llm.go @@ -564,6 +564,15 @@ func (p *Pipeline) CallLLM( llmResponseFields["prompt_tokens"] = exec.response.Usage.PromptTokens llmResponseFields["completion_tokens"] = exec.response.Usage.CompletionTokens llmResponseFields["total_tokens"] = exec.response.Usage.TotalTokens + if exec.response.Usage.PromptCacheHitTokens != nil { + llmResponseFields["prompt_cache_hit_tokens"] = *exec.response.Usage.PromptCacheHitTokens + } + if exec.response.Usage.PromptCacheMissTokens != nil { + llmResponseFields["prompt_cache_miss_tokens"] = *exec.response.Usage.PromptCacheMissTokens + } + if exec.response.Usage.PromptTokensDetails != nil { + llmResponseFields["cached_tokens"] = exec.response.Usage.PromptTokensDetails.CachedTokens + } } logger.DebugCF("agent", "LLM response", llmResponseFields) diff --git a/pkg/providers/protocoltypes/types.go b/pkg/providers/protocoltypes/types.go index b60c467014..03501cc40e 100644 --- a/pkg/providers/protocoltypes/types.go +++ b/pkg/providers/protocoltypes/types.go @@ -53,6 +53,19 @@ type UsageInfo struct { PromptTokens int `json:"prompt_tokens"` CompletionTokens int `json:"completion_tokens"` TotalTokens int `json:"total_tokens"` + + // Cache metadata (optional). DeepSeek reports prompt_cache_hit_tokens / + // prompt_cache_miss_tokens; OpenAI-compatible endpoints may report + // prompt_tokens_details.cached_tokens. Pointers distinguish "not reported" + // (nil) from a real zero. + PromptCacheHitTokens *int `json:"prompt_cache_hit_tokens"` + PromptCacheMissTokens *int `json:"prompt_cache_miss_tokens"` + PromptTokensDetails *PromptTokensDetails `json:"prompt_tokens_details"` +} + +// PromptTokensDetails carries OpenAI-style prompt token breakdowns. +type PromptTokensDetails struct { + CachedTokens int `json:"cached_tokens"` } // CacheControl marks a content block for LLM-side prefix caching.