fix(agent): gate prompt caching by provider capability, not base_url/model string match#455
Open
sumleo wants to merge 1 commit into
Open
fix(agent): gate prompt caching by provider capability, not base_url/model string match#455sumleo wants to merge 1 commit into
sumleo wants to merge 1 commit into
Conversation
…model string match
Author
|
Hi @math-inc, gentle nudge on this when you have a moment. It's a small, self-contained prompt-caching fix, and I'm happy to rebase or tweak anything if that would make review easier. Thanks for the project and your time! |
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.
What does this PR do?
Anthropic prompt caching was gated on a base_url substring (
"openrouter" in base_url). A Claude model served through a custom Anthropic-compatible endpoint (Z.ai, LiteLLM, self-hosted proxy) therefore silently lost caching — a ~75% input-token-cost regression on multi-turn runs for those users.This replaces the fragile string match with a capability check driven by the runtime provider resolution, and applies it to both sites that compute the gate.
Related Issue
Fixes #454
Type of Change
Changes Made
gauss_cli/runtime_provider.py: addsupports_anthropic_prompt_caching(api_mode, model, base_url). ReturnsTruefor the native Anthropic Messages API, and for anychat_completionsendpoint serving a Claude model (OpenRouter or custom). Codex Responses and non-Claude chat-completions returnFalse.run_agent.pyAIAgent.__init__(L386-393): replace(is_openrouter and is_claude) or is_native_anthropicwith the capability call.run_agent.pyprovider-fallback recompute (L2650-2657): replace the duplicate("openrouter" in fb_base_url ... and "claude" in fb_model ...)gate with the same capability call, so a Claude fallback on a custom endpoint also keeps caching.self._use_prompt_cachingremains the sole gate on thecache_controlmarker (L4338-4339), so both code paths now enable caching consistently.Intentional test-expectation change
The old
test_prompt_caching_non_openrouterasserted caching was OFF for a Claude model on a non-OpenRouter endpoint — that asserted the bug. It is renamed totest_prompt_caching_claude_custom_endpointand now asserts caching is ON, which is the corrected behavior. A newtest_prompt_caching_non_claude_custom_endpointkeeps coverage that a non-Claude model on a custom endpoint stays OFF. The existing OpenRouter / non-Claude / native-Anthropic / fallback-to-anthropic tests are unchanged and still pass.How to Test
pip install -e .(oruv pip install -e .)python -m pytest tests/test_run_agent.py -qChecklist
Code
fix(agent): ...)pytest tests/test_run_agent.py -qand all tests passDocumentation & Housekeeping