fix: cache_control TTL ordering — tools ttl must be >= system ttl for Anthropic API

Anthropic requires cache_control TTL blocks in non-increasing order across
tools → system → messages. Tools had default 5m TTL while system[0] had 1h,
causing 400 BadRequest on every LLM call since v4.14.0 prompt caching.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Anton 2026-02-17 13:07:15 +03:00
parent aed7a7c504
commit 176567bf51

View file

@ -186,7 +186,7 @@ class LLMClient:
tools_with_cache = [t for t in tools] # shallow copy
if tools_with_cache:
last_tool = {**tools_with_cache[-1]} # copy last tool
last_tool["cache_control"] = {"type": "ephemeral"}
last_tool["cache_control"] = {"type": "ephemeral", "ttl": "1h"}
tools_with_cache[-1] = last_tool
kwargs["tools"] = tools_with_cache
kwargs["tool_choice"] = tool_choice