fix(caching): prompt_caching.enabled toggle for strict Anthropic proxies (salvage #35862, closes #13477) - #56105
Merged
Merged
Conversation
…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.
Contributor
This was referenced Jul 1, 2026
waefrebeorn
pushed a commit
to waefrebeorn/slermes
that referenced
this pull request
Jul 2, 2026
…or re-evaluation (NousResearch#56126) * Revert "fix(caching): honor prompt_caching.enabled across model switch + fallback" This reverts commit 1f86e39. * Revert "fix: allow disabling prompt caching" This reverts commit 7e81b23.
Jasper6439
pushed a commit
to Jasper6439/hermes-agent
that referenced
this pull request
Jul 5, 2026
…or re-evaluation (NousResearch#56126) * Revert "fix(caching): honor prompt_caching.enabled across model switch + fallback" This reverts commit 36f9f50. * Revert "fix: allow disabling prompt caching" This reverts commit c1c1a12.
habarmc1223-sudo
pushed a commit
to habarmc1223-sudo/hermes-agent-fluxmem
that referenced
this pull request
Jul 8, 2026
…or re-evaluation (NousResearch#56126) * Revert "fix(caching): honor prompt_caching.enabled across model switch + fallback" This reverts commit 969477b. * Revert "fix: allow disabling prompt caching" This reverts commit 58d8548.
santhreal
pushed a commit
to santhreal/hermes-agent
that referenced
this pull request
Jul 13, 2026
…or re-evaluation (NousResearch#56126) * Revert "fix(caching): honor prompt_caching.enabled across model switch + fallback" This reverts commit c5b2feb. * Revert "fix: allow disabling prompt caching" This reverts commit 64a756d.
Gravezzz
pushed a commit
to Gravezzz/hermes-agent
that referenced
this pull request
Jul 21, 2026
…or re-evaluation (NousResearch#56126) * Revert "fix(caching): honor prompt_caching.enabled across model switch + fallback" This reverts commit 36f9f50. * Revert "fix: allow disabling prompt caching" This reverts commit c1c1a12.
kshitijk4poor
pushed a commit
to kshitijk4poor/hermes-agent
that referenced
this pull request
Aug 1, 2026
Setting prompt_caching.cache_ttl to a falsy value (false, null, off, disabled, no, none) now fully disables prompt caching instead of being silently ignored. The disable propagates through anthropic_prompt_cache_policy() (early return when _cache_disabled flag is set) and restore_primary_runtime() (override after snapshot restore), so it survives /model switches and fallback re-derivation — the gap that caused NousResearch#56105 to be reverted in NousResearch#56126. Salvage of NousResearch#33555 by @BB-light, with model-switch/fallback survival gap fixed on top. Co-authored-by: BB-light <BB-light@users.noreply.github.com>
kshitijk4poor
pushed a commit
that referenced
this pull request
Aug 1, 2026
Setting prompt_caching.cache_ttl to a falsy value (false, null, off, disabled, no, none) now fully disables prompt caching instead of being silently ignored. The disable propagates through anthropic_prompt_cache_policy() (early return when _cache_disabled flag is set) and restore_primary_runtime() (override after snapshot restore), so it survives /model switches and fallback re-derivation — the gap that caused #56105 to be reverted in #56126. Salvage of #33555 by @BB-light, with model-switch/fallback survival gap fixed on top. Co-authored-by: BB-light <BB-light@users.noreply.github.com>
5 tasks
leewenjie
pushed a commit
to leewenjie/hermes-agent
that referenced
this pull request
Aug 7, 2026
…or re-evaluation (NousResearch#56126) * Revert "fix(caching): honor prompt_caching.enabled across model switch + fallback" This reverts commit 36f9f50. * Revert "fix: allow disabling prompt caching" This reverts commit c1c1a12.
randlee
pushed a commit
to randlee/hermes-agent
that referenced
this pull request
Aug 11, 2026
Setting prompt_caching.cache_ttl to a falsy value (false, null, off, disabled, no, none) now fully disables prompt caching instead of being silently ignored. The disable propagates through anthropic_prompt_cache_policy() (early return when _cache_disabled flag is set) and restore_primary_runtime() (override after snapshot restore), so it survives /model switches and fallback re-derivation — the gap that caused NousResearch#56105 to be reverted in NousResearch#56126. Salvage of NousResearch#33555 by @BB-light, with model-switch/fallback survival gap fixed on top. Co-authored-by: BB-light <BB-light@users.noreply.github.com>
prmartinow
pushed a commit
to prmartinow/hermes-agent
that referenced
this pull request
Aug 26, 2026
Setting prompt_caching.cache_ttl to a falsy value (false, null, off, disabled, no, none) now fully disables prompt caching instead of being silently ignored. The disable propagates through anthropic_prompt_cache_policy() (early return when _cache_disabled flag is set) and restore_primary_runtime() (override after snapshot restore), so it survives /model switches and fallback re-derivation — the gap that caused NousResearch#56105 to be reverted in NousResearch#56126. Salvage of NousResearch#33555 by @BB-light, with model-switch/fallback survival gap fixed on top. Co-authored-by: BB-light <BB-light@users.noreply.github.com>
melon-xf
added a commit
to melon-xf/hermes-agent
that referenced
this pull request
Sep 3, 2026
…or re-evaluation (NousResearch#56126) * Revert "fix(caching): honor prompt_caching.enabled across model switch + fallback" This reverts commit 36f9f50. * Revert "fix: allow disabling prompt caching" This reverts commit c1c1a12.
melon-xf
added a commit
to melon-xf/hermes-agent
that referenced
this pull request
Sep 3, 2026
Setting prompt_caching.cache_ttl to a falsy value (false, null, off, disabled, no, none) now fully disables prompt caching instead of being silently ignored. The disable propagates through anthropic_prompt_cache_policy() (early return when _cache_disabled flag is set) and restore_primary_runtime() (override after snapshot restore), so it survives /model switches and fallback re-derivation — the gap that caused NousResearch#56105 to be reverted in NousResearch#56126. Salvage of NousResearch#33555 by @BB-light, with model-switch/fallback survival gap fixed on top. Co-authored-by: BB-light <BB-light@users.noreply.github.com>
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.
Summary
Adds a
prompt_caching.enabledconfig toggle so a user on a strict Anthropic-compatible proxy (LiteLLM-style, e.g.llm.echo.tech) that injects its owncache_controlmarkers can turn off client-side markers entirely — fixing the HTTP 400"A maximum of 4 blocks with cache_control may be provided. Found 5"reported in #13477 without regressing caching for every well-behaved third-party gateway.Salvages @janrenz's PR #35862 (the config toggle), then closes the gap it left: the disable must survive
/modelswitches and fallback re-derivation.Why the toggle, not a third-party strip
The original report (#13477) proposed stripping ALL markers whenever
base_urlisn'tanthropic.com. That matches every non-Anthropic endpoint, so it would kill caching for MiniMax, Zhipu GLM, Bedrock, Foundry, Kimi, DeepSeek — all of whichanthropic_prompt_cache_policydeliberately caches on and none of which double-inject. Wrong lever. The real problem is one misbehaving proxy adding a 5th marker on top of our 4; the correct fix is a per-setup opt-out.Changes
hermes_cli/config.py: addprompt_caching.enabled: truedefault + escape-hatch comment.agent/agent_runtime_helpers.py: gateanthropic_prompt_cache_policyonenabled=false→ returns(False, False)before any branch, so init,/modelswitch, and fallback all honor it.agent/agent_init.py: keep @janrenz'sisinstancehardening on thecache_ttlread; drop the now-redundant init-only override (the policy gate covers it).tests/: policy-level kill-switch tests (native / OpenRouter / third-party / model-switch survival / enabled-true-keeps-caching) + @janrenz's init test.website/docs/: document theenabledtoggle.scripts/release.py: AUTHOR_MAP entry for @janrenz.Root cause
Client never exceeds 4 markers on native Anthropic (traced E2E:
apply_anthropic_cache_controlmarks system + last-3, tool-merge collapses them 1:1). The proxy adds a 5th server-side. The only client-side lever that helps is not sending markers to that proxy — a config toggle.Validation
/modelswitchE2E confirmed the disable survives all three re-derivation paths and re-enabling restores caching.
test_anthropic_prompt_cache_policy.py29/29 green;test_run_agent.pycaching subset 9/9 green.Closes #13477 (via the toggle, not the proposed strip). Salvages #35862 with authorship preserved.
Infographic