Skip to content

Re-enable Vertex Anthropic prompt caching - #886

Merged
lbarcziova merged 1 commit into
packit:mainfrom
lbarcziova:fix-vertex-prompt-caching
Oct 26, 2026
Merged

lbarcziova merged 1 commit into
packit:mainfrom
lbarcziova:fix-vertex-prompt-caching

Conversation

@lbarcziova

Copy link
Copy Markdown
Member

BeeAI 0.1.84+ defaults allow_prompt_caching to False for every VertexAIChatModel, which silently stripped the cache_control_injection_points the reasoning agent sets. Every request then re-sent the full context as fresh input: cache read/write dropped to zero and Vertex input cost spiked.

Re-enable it for Vertex Anthropic by passing allow_prompt_caching=True at construction (the adapter honors an explicit value), keyed off the public CHAT_MODEL string rather than a private attribute. Add a unit test that the flag is requested only for Vertex Anthropic, plus an end-to-end test that the transformed request retains its cache injection points.

Assisted-by: Claude Opus 4.8

@qodo-for-packit

Copy link
Copy Markdown

PR Summary by Qodo

Restore prompt caching for Vertex Anthropic models

🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes


AI Description

• Explicitly enable caching when constructing Vertex Claude models to preserve reasoning-agent cache
 points.
• Leave Gemini and direct Anthropic caching behavior unchanged.
• Test both the construction argument and cache-point retention in BeeAI’s request transformation.
Diagram

graph TD
  A["CHAT_MODEL"] --> B{"Vertex Claude?"} -->|yes| C["Enable caching"] --> D["BeeAI adapter"] --> F["Request transform"] --> G["Retained cache points"]
  B -->|no| E["BeeAI defaults"] --> D
  H["Reasoning agent"] -->|supplies points| F
Loading
High-Level Assessment

Passing the flag at construction is the direct fix for the adapter’s default; mutating the model afterward was the prior, less reliable approach. Review the separate removal of the private provider-ID normalization for its effect on Vertex Claude adaptive thinking.

Files changed (2) +62 / -36

Bug fix (1) +7 / -9
utils.pyEnable caching when constructing Vertex Claude models +7/-9

Enable caching when constructing Vertex Claude models

• get_chat_model passes allow_prompt_caching=True to BeeAI for Vertex Claude models, while leaving other providers’ construction arguments unchanged. It also removes the post-construction caching assignment and the private LiteLLM provider-ID normalization; Gemini caching remains explicitly disabled.

ymir/agents/utils.py

Tests (1) +55 / -27
test_utils.pyCover caching selection and request transformation +55/-27

Cover caching selection and request transformation

• Parameterized cases check that only Vertex Claude requests the caching constructor argument. A test using the real Vertex adapter verifies that cache injection points survive request transformation when caching is enabled and are stripped when it is disabled.

ymir/agents/tests/unit/test_utils.py

@qodo-for-packit

qodo-for-packit Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Code Review by Qodo


Resolved findings
1. Vertex Claude reasoning requests fail ✗ Dismissed
Description
get_chat_model() no longer changes BeeAI's vertexai provider ID to the vertex_ai spelling
needed for adaptive-thinking detection. When reasoning is enabled for a Vertex Claude model, the
deleted correction's documented failure path sends thinking.type=enabled, which Claude Opus 4.8
rejects.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Removing the provider-ID correction breaks adaptive-thinking requests for Vertex Claude with reasoning enabled.

## Fix Focus Areas
- ymir/agents/utils.py[77-83]

## Recommended Fix
Keep `allow_prompt_caching=True` at construction, but restore the post-construction `vertexai` to `vertex_ai` provider-ID correction independently of the caching setting. Add coverage for a Vertex Claude model with reasoning enabled.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Comment thread ymir/agents/utils.py
BeeAI 0.1.84+ defaults allow_prompt_caching to False for every VertexAIChatModel, which silently stripped the cache_control_injection_points the reasoning agent sets. Every request then re-sent the full context as fresh input: cache read/write dropped to zero and Vertex input cost spiked.

Re-enable it for Vertex Anthropic by passing allow_prompt_caching=True at construction (the adapter honors an explicit value), keyed off the public CHAT_MODEL string rather than a private attribute. Add a unit test that the flag is requested only for Vertex Anthropic, plus an end-to-end test that the transformed request retains its cache injection points.

Assisted-by: Claude Opus 4.8
@lbarcziova
lbarcziova force-pushed the fix-vertex-prompt-caching branch from f90a5ae to 1d00b1d Compare October 26, 2026 10:21
@lbarcziova
lbarcziova merged commit 5ef85af into packit:main Oct 26, 2026
16 checks passed
@lbarcziova
lbarcziova deleted the fix-vertex-prompt-caching branch October 26, 2026 10:45
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.

3 participants