[codex] apply Anthropic cache control to tools#1815
Merged
gold-silver-copper merged 14 commits intoMay 25, 2026
Merged
Conversation
Anthropic's prompt-caching API supports up to 4 cache breakpoints per request. One of the three cacheable layers is the tools array: setting cache_control on the last ToolDefinition tells Anthropic to cache all tools up to that point independently of the system prompt. ToolDefinition currently has no cache_control field, so callers have no way to cache the tools layer. This adds the field following the same pattern already used by SystemContent and the message Content variants. - Add `pub cache_control: Option<CacheControl>` to `ToolDefinition` with `#[serde(skip_serializing_if = "Option::is_none")]` so it is absent from requests that do not use caching. - Initialize `cache_control: None` at the two ToolDefinition construction sites (completion.rs and streaming.rs TryFrom impls).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stacked follow-up to #1812. This completes the tool-cache-control surface by making Anthropic manual prompt caching actually apply a cache breakpoint to the tools layer.
Changes
cache_control: {"type":"ephemeral"}whenwith_prompt_caching()is enabled.additional_params.toolsare combined, so provider-supplied tools are handled correctly.Stack
186f4946c48d3b0505911165a837a5320b80ba55Validation
cargo test -p rig-core cache_controlcargo test -p rig-core prompt_cachingcargo test -p rig-core tool_build_marks_final_combined_toolcargo test -p rig-core providers::anthropiccargo fmt -- --checkgit diff --check