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:
1 parent
d5e8abf492
commit
7fa3e75ad1
4 files changed
+88
-2
No files matched your search
+14
-2
@@ -181,14 +181,26 @@ func (r *Runtime) maybeKickoffAsyncCompaction(msgs []llm.Message, parts []llm.Sy
|
||||
}
|
||||
|
||||
// providerSupportsCaching returns true when the runtime's provider implements
|
||||
// Anthropic-style explicit prompt caching.
|
||||
// Anthropic-style explicit prompt caching. The capability interface wins:
|
||||
// a provider block named "platformai" (or "bedrock", or anything else)
|
||||
// wrapping the Anthropic implementation still caches. The name check is
|
||||
// the legacy fallback for custom LLMProvider impls that predate the
|
||||
// capability interface.
|
||||
func (r *Runtime) providerSupportsCaching() bool {
|
||||
if pc, ok := r.LLM.(llm.PromptCachingProvider); ok {
|
||||
return pc.SupportsPromptCaching()
|
||||
}
|
||||
return r.Provider == "anthropic"
|
||||
}
|
||||
|
||||
// providerSupportsMidLoopCompaction returns true for hosted frontier
|
||||
// providers that handle mid-loop summary injection cleanly.
|
||||
// providers that handle mid-loop summary injection cleanly. Same
|
||||
// capability-over-name rule as providerSupportsCaching: an
|
||||
// Anthropic-shaped provider under a custom name qualifies.
|
||||
func (r *Runtime) providerSupportsMidLoopCompaction() bool {
|
||||
if pc, ok := r.LLM.(llm.PromptCachingProvider); ok && pc.SupportsPromptCaching() {
|
||||
return true
|
||||
}
|
||||
switch r.Provider {
|
||||
case "anthropic", "openai", "gemini":
|
||||
return true
|
||||
|
||||
Reference in new issue
Block a user