MCPcopy Create free account
hub / github.com/VectifyAI/OpenKB / _accepts_cache_control

Function _accepts_cache_control

openkb/agent/compiler.py:277–305  ·  view source on GitHub ↗

Whether ``model`` honours Anthropic-style ``cache_control`` markers. The markers emitted by :func:`_cached_text` are an Anthropic feature. LiteLLM forwards them to Anthropic directly, and to Anthropic (Claude) models served via OpenRouter, Bedrock and Vertex. For other providers — n

(model: str)

Source from the content-addressed store, hash-verified

275
276
277def _accepts_cache_control(model: str) -> bool:
278 """Whether ``model`` honours Anthropic-style ``cache_control`` markers.
279
280 The markers emitted by :func:`_cached_text` are an Anthropic feature.
281 LiteLLM forwards them to Anthropic directly, and to Anthropic (Claude)
282 models served via OpenRouter, Bedrock and Vertex. For other providers —
283 notably Gemini — LiteLLM instead translates the marker into a
284 provider-native cached-content object that conflicts with
285 ``system_instruction``/``tools`` and makes *every* request fail with
286 ``400 CachedContent can not be used with ...``. Detect the provider so the
287 marker can be dropped before it reaches such a backend.
288 """
289 # Import the real symbol rather than going through the module-level
290 # ``litellm`` reference: provider detection must stay correct even when a
291 # caller patches ``openkb.agent.compiler.litellm`` to stub out completion.
292 from litellm import get_llm_provider
293
294 try:
295 provider = get_llm_provider(model)[1]
296 except Exception:
297 provider = ""
298 lowered = model.lower()
299 if provider == "anthropic":
300 return True
301 if provider in ("openrouter", "bedrock", "vertex_ai") and (
302 "claude" in lowered or "anthropic" in lowered
303 ):
304 return True
305 return False
306
307
308def _strip_cache_control(messages: list[dict]) -> list[dict]:

Calls

no outgoing calls