Add cache control to Anthropic Bedrock provider#1615
Add cache control to Anthropic Bedrock provider#1615laminar-coding-agent[bot] wants to merge 7 commits intodevfrom
Conversation
Add CachePointBlock (type: default) to system prompt, tools, and the last message content block in Bedrock Converse API requests. This enables Anthropic's prompt caching so repeated prefixes (system instructions, tool definitions, conversation history) are cached and reused across requests, reducing latency and input token costs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Greptile SummaryThis PR adds Anthropic prompt caching to the Bedrock provider by appending Key changes:
Confidence Score: 3/5Not yet safe to merge — the !thinking_enabled guard on cache-point injection is still absent despite a prior reported fix, which will cause Bedrock API errors on any extended-thinking request. Several previous concerns are genuinely resolved (DRY helper extracted, debug print removed, cache point now placed on the last message). However, commit 67de219 was supposed to gate all three cache-point injection sites on !thinking_enabled, yet the guards are not present in the current HEAD (ad2f450). Any call to generate_content with a thinking-enabled generation_config will now append cache point blocks and receive a Bedrock validation error, regressing a scenario that was already identified and supposedly fixed. app-server/src/signals/provider/bedrock/mod.rs — specifically the three cache-point injection sites (last user message, system blocks, tool list) need !thinking_enabled guards.
|
| Filename | Overview |
|---|---|
| app-server/src/signals/provider/bedrock/mod.rs | Core caching implementation: cache points appended to last user message, system blocks, and tool list. Previous concerns (DRY, println, message ordering) are resolved, but the !thinking_enabled guard that was reportedly added in commit 67de219 is absent from all three injection sites in the current HEAD, meaning extended-thinking requests will still receive cache point blocks and will be rejected by Bedrock. |
| app-server/src/signals/provider/mod.rs | Default Bedrock model updated to global.anthropic.claude-sonnet-4-6; size-based mappings added for Haiku, Sonnet, and Opus 4 variants. No logic issues; purely a configuration update. |
| app-server/src/main.rs | Log messages renamed from Gemini-specific wording to generic LLM client. No functional changes. |
Reviews (6): Last reviewed commit: "Add cache point to tool definitions in B..." | Re-trigger Greptile
|
After reviewing the code and the Greptile bot's findings, I don't think changes are needed here. Both P2 findings are non-issues:
Both findings are explicitly marked P2/non-blocking by Greptile, and neither represents a real code quality or correctness issue. No changes needed. |
…lock construction Extract the repeated CachePointBlock builder pattern (used in 3 places) into a single `build_cache_point()` helper function. Also add a comment noting that cache points are intended for supported Anthropic Claude models and that unsupported models will surface an API error. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Done. Changes pushed:
|
Extended thinking and prompt caching are incompatible on Anthropic's Bedrock API. Hoist the thinking_enabled computation to the top of generate_content and gate all three cache point injection sites (messages, system instruction, tool config) on !thinking_enabled. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Place cache point on the last message instead of the first, so the full conversation prefix is cached across multi-turn requests. - Include cache read/write tokens in total_token_count to keep it consistent with prompt_token_count. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Pushed. Here's what was fixed:
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3125eae. Configure here.
Cache points were added for system content and last user message, but missing from tool definitions. This adds the cache point to bedrock_tools before building the ToolConfiguration. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

No description provided.