Keep the Anthropic tool definitions cache breakpoint off deferred tools

Merged
SU
3d ago
+16-1

#[CacheToolDefinitions] puts cache_control on the last tool in the request
when ToolSearch comes last in an agent's tools that last tool is a deferred one and Anthropic rejects the whole request

Tool 'FixedNumberGenerator' cannot have both defer_loading=true and cache_control set. Tools with defer_loading cannot use prompt caching.

the tool search docs say to put the breakpoint on a non-deferred tool so this stamps the last tool without defer_loading instead
with ToolSearch last that's the search tool itself
requests without deferred tools go out exactly like before

the AnthropicToolSearchAgent fixture already lists ToolSearch last so the new test just adds the attribute to it

checked live on claude-sonnet-5-5 with ToolSearch last and a large regular tool
before this every prompt() and stream() call failed with the 400 above
after it both go through and the second prompt read 39561 cached tokens across its two steps

https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-search-tool#prompt-caching