feat(llm): PromptCachingProvider capability — cache on renamed providers

providerSupportsCaching gated on the provider NAME being literally
'anthropic', so an Anthropic-shaped provider registered under a custom
config name (platformai, bedrock, any relay) never set
CacheLastMessage — every turn re-processed the full conversation
history uncached (~120K input tokens and 4-6s TTFT per turn on a
large session).

Add llm.PromptCachingProvider capability interface; AnthropicProvider
declares it; runtime gates providerSupportsCaching and
providerSupportsMidLoopCompaction on the capability first, with the
name check kept as legacy fallback for custom impls.
This commit is contained in:
sausheong committed 2026-06-11 22:02:37 +08:00
1 parent d5e8abf492
commit 7fa3e75ad1
4 files changed
+88 -2

No files matched your search

+5
View File
@@ -28,6 +28,11 @@ func NewAnthropicProvider(apiKey, baseURL string) *AnthropicProvider {
return &AnthropicProvider{client: client}
}
// SupportsPromptCaching implements llm.PromptCachingProvider: the
// Anthropic Messages API honours cache_control breakpoints regardless
// of what the provider block is named in user config.
func (p *AnthropicProvider) SupportsPromptCaching() bool { return true }
func (p *AnthropicProvider) Models() []llm.ModelInfo {
return []llm.ModelInfo{
{ID: "claude-sonnet-4-5-20250514", Name: "Claude Sonnet 4.5", Provider: "anthropic"},