fix: allow disabling prompt caching - #35862
Conversation
|
Related: #33555 addresses the same problem (disabling prompt caching) via a different approach — falsy |
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved ⚡
✅ What's Good
- Necessary escape hatch: Some strict Anthropic-compatible endpoints reject
cache_controlmarkers. Addingprompt_caching.enabled: falsegives users a config-gated way to disable it without breaking existing behavior (default staystrue). - Minimal change: 32 additions, 2 deletions. Well-scoped.
- Backward compatible: Default is
true, so existing configs work unchanged. - Safe guard: The
isinstance(_pc_cfg, dict)check prevents crashes on unexpected config shapes. - Good test: Verifies both
_use_prompt_cachingand_use_native_cache_layoutare disabled, which is the complete effect.
Summary
A simple, well-scoped config escape hatch. No issues found.
Reviewed by Hermes Agent
…back @janrenz's PR #35862 added prompt_caching.enabled=false at init only. But _anthropic_prompt_cache_policy re-derives _use_prompt_caching on every /model switch (agent_runtime_helpers) and fallback-model swap (chat_completion_helpers), which re-enabled markers and re-broke the strict proxy the toggle was meant to fix. Move the kill switch into anthropic_prompt_cache_policy so it returns (False, False) on every path. Drop the now-redundant init-time override (kept @janrenz's isinstance hardening on the cache_ttl read). Add policy-level tests + docs for the toggle. Follow-up to salvaged PR #35862.
|
Salvaged and merged via #56105 (rebase-merge, your commit's authorship preserved in git log on main). Your prompt_caching.enabled toggle is exactly the right lever for strict Anthropic-compatible proxies. Follow-up on top moved the gate into anthropic_prompt_cache_policy so the disable survives /model switch and fallback re-derivation (init-only wasn't enough), plus docs and policy tests. Thanks! |
…ies (salvage NousResearch#35862, closes NousResearch#13477) (#184) Co-authored-by: qbit-mirror-bot <qbit-mirror-bot@users.noreply.github.com>
…back @janrenz's PR NousResearch#35862 added prompt_caching.enabled=false at init only. But _anthropic_prompt_cache_policy re-derives _use_prompt_caching on every /model switch (agent_runtime_helpers) and fallback-model swap (chat_completion_helpers), which re-enabled markers and re-broke the strict proxy the toggle was meant to fix. Move the kill switch into anthropic_prompt_cache_policy so it returns (False, False) on every path. Drop the now-redundant init-time override (kept @janrenz's isinstance hardening on the cache_ttl read). Add policy-level tests + docs for the toggle. Follow-up to salvaged PR NousResearch#35862.
…back @janrenz's PR NousResearch#35862 added prompt_caching.enabled=false at init only. But _anthropic_prompt_cache_policy re-derives _use_prompt_caching on every /model switch (agent_runtime_helpers) and fallback-model swap (chat_completion_helpers), which re-enabled markers and re-broke the strict proxy the toggle was meant to fix. Move the kill switch into anthropic_prompt_cache_policy so it returns (False, False) on every path. Drop the now-redundant init-time override (kept @janrenz's isinstance hardening on the cache_ttl read). Add policy-level tests + docs for the toggle. Follow-up to salvaged PR NousResearch#35862.
…back @janrenz's PR #35862 added prompt_caching.enabled=false at init only. But _anthropic_prompt_cache_policy re-derives _use_prompt_caching on every /model switch (agent_runtime_helpers) and fallback-model swap (chat_completion_helpers), which re-enabled markers and re-broke the strict proxy the toggle was meant to fix. Move the kill switch into anthropic_prompt_cache_policy so it returns (False, False) on every path. Drop the now-redundant init-time override (kept @janrenz's isinstance hardening on the cache_ttl read). Add policy-level tests + docs for the toggle. Follow-up to salvaged PR #35862. (cherry picked from commit 36f9f50)
…back @janrenz's PR NousResearch#35862 added prompt_caching.enabled=false at init only. But _anthropic_prompt_cache_policy re-derives _use_prompt_caching on every /model switch (agent_runtime_helpers) and fallback-model swap (chat_completion_helpers), which re-enabled markers and re-broke the strict proxy the toggle was meant to fix. Move the kill switch into anthropic_prompt_cache_policy so it returns (False, False) on every path. Drop the now-redundant init-time override (kept @janrenz's isinstance hardening on the cache_ttl read). Add policy-level tests + docs for the toggle. Follow-up to salvaged PR NousResearch#35862.
…back @janrenz's PR NousResearch#35862 added prompt_caching.enabled=false at init only. But _anthropic_prompt_cache_policy re-derives _use_prompt_caching on every /model switch (agent_runtime_helpers) and fallback-model swap (chat_completion_helpers), which re-enabled markers and re-broke the strict proxy the toggle was meant to fix. Move the kill switch into anthropic_prompt_cache_policy so it returns (False, False) on every path. Drop the now-redundant init-time override (kept @janrenz's isinstance hardening on the cache_ttl read). Add policy-level tests + docs for the toggle. Follow-up to salvaged PR NousResearch#35862.
…back @janrenz's PR NousResearch#35862 added prompt_caching.enabled=false at init only. But _anthropic_prompt_cache_policy re-derives _use_prompt_caching on every /model switch (agent_runtime_helpers) and fallback-model swap (chat_completion_helpers), which re-enabled markers and re-broke the strict proxy the toggle was meant to fix. Move the kill switch into anthropic_prompt_cache_policy so it returns (False, False) on every path. Drop the now-redundant init-time override (kept @janrenz's isinstance hardening on the cache_ttl read). Add policy-level tests + docs for the toggle. Follow-up to salvaged PR NousResearch#35862.
…back @janrenz's PR NousResearch#35862 added prompt_caching.enabled=false at init only. But _anthropic_prompt_cache_policy re-derives _use_prompt_caching on every /model switch (agent_runtime_helpers) and fallback-model swap (chat_completion_helpers), which re-enabled markers and re-broke the strict proxy the toggle was meant to fix. Move the kill switch into anthropic_prompt_cache_policy so it returns (False, False) on every path. Drop the now-redundant init-time override (kept @janrenz's isinstance hardening on the cache_ttl read). Add policy-level tests + docs for the toggle. Follow-up to salvaged PR NousResearch#35862.
Summary
prompt_caching.enabledconfig support, defaulting totrueprompt_caching.enabled: falseto disable cache marker injection for strict Anthropic-compatible providersWhy
Some strict Anthropic-compatible endpoints can reject Hermes-injected
cache_controlmarkers with errors likeUnknown parameter: messages[0].content[0].cache_control. Hermes already supportsprompt_caching.cache_ttl; this adds a narrow config-gated escape hatch without changing the default behavior for users who benefit from prompt caching.Test Plan
venv/bin/python -m py_compile agent/agent_init.py hermes_cli/config.py tests/run_agent/test_run_agent.pyvenv/bin/python -m pytest tests/run_agent/test_run_agent.py tests/run_agent/test_anthropic_prompt_cache_policy.py tests/agent/test_prompt_caching.py -q -o 'addopts='Result: 396 passed, 1 warning.