fix(anthropic): index message role directly in cache control hook

This commit is contained in:
lkshrk 2026-10-10 03:46:06 +02:00
parent 6a251ac5dc
commit 74d2d617a0
No known key found for this signature in database

View file

@ -614,7 +614,7 @@ class AnthropicCacheControlHook(CustomPromptManagement):
# 1. string content, or a tool message: insert cache control at message level.
# Anthropic only accepts cache_control on the tool_result block itself, never
# inside tool_result.content; the message-level marker maps onto that block.
if message.get("role") == "tool" or isinstance(message_content, str):
if message["role"] == "tool" or isinstance(message_content, str):
message["cache_control"] = control
# 2. list of objects - only apply to last item per Anthropic spec
elif isinstance(message_content, list):