Skip to content

[codex] apply Anthropic cache control to tools#1815

Merged
gold-silver-copper merged 14 commits into
0xPlaygrounds:mainfrom
gold-silver-copper:codex/anthropic-tool-cache-control-behavior
May 25, 2026
Merged

[codex] apply Anthropic cache control to tools#1815
gold-silver-copper merged 14 commits into
0xPlaygrounds:mainfrom
gold-silver-copper:codex/anthropic-tool-cache-control-behavior

Conversation

@gold-silver-copper
Copy link
Copy Markdown
Contributor

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

  • Marks only the final combined Anthropic tool definition with cache_control: {"type":"ephemeral"} when with_prompt_caching() is enabled.
  • Applies the marker after Rig tools and additional_params.tools are combined, so provider-supplied tools are handled correctly.
  • Shares tool assembly between non-streaming and streaming paths so both request builders behave the same way.
  • Documents that manual prompt caching now covers system prompt, tools, and messages.
  • Adds regression coverage for tool serialization, final-tool marking, additional tools, no-tool requests, and streaming shared assembly.

Stack

Validation

  • cargo test -p rig-core cache_control
  • cargo test -p rig-core prompt_caching
  • cargo test -p rig-core tool_build_marks_final_combined_tool
  • cargo test -p rig-core providers::anthropic
  • cargo fmt -- --check
  • git diff --check

jimmiebfulton and others added 4 commits May 22, 2026 21:34
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).
@gold-silver-copper gold-silver-copper marked this pull request as ready for review May 25, 2026 03:04
@gold-silver-copper gold-silver-copper added this pull request to the merge queue May 25, 2026
Merged via the queue into 0xPlaygrounds:main with commit 02548c4 May 25, 2026
5 checks passed
@github-actions github-actions Bot mentioned this pull request May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants