← Back to PRs

#22303: fix: extend cacheRetention auto-injection and runtime pass-through for amazon-bedrock

by snese open 2026-02-21 01:00 View on GitHub →
agents size: XS
## Summary Two changes to make `cacheRetention` work end-to-end for Anthropic Claude models on the `amazon-bedrock` provider. ## Changes ### 1. `src/config/defaults.ts` — config auto-injection The config auto-injection in `applyContextPruningDefaults` only sets `cacheRetention: "short"` for `provider === "anthropic"`, skipping Bedrock Claude models. Extended the provider gate to also match `amazon-bedrock` models whose ID contains `anthropic.claude`. ### 2. `src/agents/pi-embedded-runner/extra-params.ts` — runtime pass-through `resolveCacheRetention` hard-gates on `provider !== "anthropic"` and returns `undefined` for all other providers. This means `cacheRetention` configured in model params is never consumed at runtime for Bedrock models. Extended the gate to also accept `amazon-bedrock` when `cacheRetention` is explicitly set in `extraParams`. No default is applied for Bedrock since pi-ai's own provider already defaults to `"short"` internally. ## Related - Fixes the config + runtime parts of #21986 - Complements PR #20866 (disables caching for non-Anthropic Bedrock models) - The TTL validation gap (`cacheRetention: "long"` → `ttl: "1h"` on unsupported models) is a separate upstream pi-ai concern, tracked in #21986 and [pi-mono discussion #1571](https://github.com/badlogic/pi-mono/discussions/1571) ## Testing - [x] AI-assisted (Kiro CLI) - [x] Lightly tested against local openclaw instance with `amazon-bedrock/us.anthropic.claude-opus-4-6-v1` - [x] Confirmed `cacheRetention` is auto-injected and consumed at runtime for Bedrock Claude models - [x] Confirmed non-Anthropic Bedrock models are correctly skipped <!-- greptile_comment --> <h3>Greptile Summary</h3> Extends `cacheRetention` support to Anthropic Claude models running on Amazon Bedrock by adding two complementary changes: - Config auto-injection in `applyContextPruningDefaults` now recognizes Bedrock Claude models (matching `amazon-bedrock` provider with model IDs containing `anthropic.claude`) and applies the default `cacheRetention: "short"` setting - Runtime pass-through in `resolveCacheRetention` now accepts Bedrock when `cacheRetention` is explicitly configured, allowing the auto-injected or user-specified values to flow through to the streaming API The changes correctly preserve the existing behavior for direct Anthropic models while extending support to Bedrock's Anthropic Claude variants. The string matching logic handles both region-prefixed (`us.anthropic.claude-*`) and non-prefixed (`anthropic.claude-*`) model ID formats. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - The changes are well-scoped, logically sound, and follow the existing patterns in the codebase. The two-part approach (config auto-injection + runtime pass-through) correctly implements the feature. The string matching logic using `.toLowerCase().includes("anthropic.claude")` appropriately handles all documented Bedrock Claude model ID formats, and the guard condition `extraParams?.cacheRetention !== undefined` ensures Bedrock only gets cacheRetention when explicitly configured (via auto-injection or user config). The changes preserve backward compatibility with direct Anthropic models and existing cacheRetention behavior. - No files require special attention <sub>Last reviewed commit: fb85a4d</sub> <!-- greptile_other_comments_section --> <sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub> <!-- /greptile_comment -->

Most Similar PRs