feat(anthropic): add cache_control field to ToolDefinition#1812
Closed
jimmiebfulton wants to merge 1 commit into
Closed
feat(anthropic): add cache_control field to ToolDefinition#1812jimmiebfulton wants to merge 1 commit into
jimmiebfulton wants to merge 1 commit into
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).
Contributor
|
Stacked this pr into #1815 |
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
Anthropic supports caching the tools layer by setting
cache_controlon the lastToolDefinitionin the array.ToolDefinitioncurrently has no such field — this is the only cacheable layer not yet exposed in rig.SystemContentand the messageContentvariants already havecache_control. This bringsToolDefinitionin line with the same pattern.Changes
pub cache_control: Option<CacheControl>toToolDefinitionwith#[serde(skip_serializing_if = "Option::is_none")].cache_control: Noneat the twoToolDefinitionconstruction sites in theTryFromimpls (completion.rsandstreaming.rs).No behaviour change for existing callers — the field defaults to
Noneand is omitted from serialization when unset.AI Assistance
This implementation was developed with significant AI assistance (Claude). The change and rationale were reviewed and validated by the author before submission.
Issue
Fixes #1811