Skip to content

The agent that grows with you

fix: follow-up polish for salvaged PR #85512

kshitij4fa728b6bed3
diff --git a/agent/agent_runtime_helpers.py b/agent/agent_runtime_helpers.py
index 6a261783544..35d9848496c 100644
--- a/agent/agent_runtime_helpers.py
+++ b/agent/agent_runtime_helpers.py
@@ -2248,8 +2248,11 @@ def anthropic_prompt_cache_policy(
capability="prompt_caching",
custom_providers=getattr(agent, "_custom_providers", None),
)
- except Exception:
- pass
+ except Exception as _cap_exc:
+ logger.debug(
+ "custom-provider prompt_caching capability lookup failed: %s",
+ _cap_exc,
+ )
if custom_prompt_caching is not None:
return custom_prompt_caching, custom_prompt_caching
diff --git a/hermes_cli/config.py b/hermes_cli/config.py
index 42eef070678..29c7a4551e6 100644
--- a/hermes_cli/config.py
+++ b/hermes_cli/config.py
@@ -1799,6 +1799,12 @@ def get_custom_provider_model_capability(
return None
if custom_providers is None:
try:
+ if config is None:
+ # Read-only path: this helper never mutates the entries it
+ # scans, and get_compatible_custom_providers shallow-copies
+ # each entry before normalizing, so the no-deepcopy cache is
+ # safe here (~135us saved per call on the blank-stub paths).
+ config = load_config_readonly()
custom_providers = get_compatible_custom_providers(config)
except Exception:
return None
diff --git a/tests/hermes_cli/test_custom_provider_context_length.py b/tests/hermes_cli/test_custom_provider_context_length.py
index 04818f2274c..2220262a174 100644
--- a/tests/hermes_cli/test_custom_provider_context_length.py
+++ b/tests/hermes_cli/test_custom_provider_context_length.py
@@ -98,6 +98,27 @@ class TestGetCustomProviderModelCapability:
custom,
) is None
+ def test_capability_is_route_isolated(self):
+ """A declaration for one route must not apply to another route.
+
+ Guards normalize_route_base_url matching: if the URL comparison ever
+ regresses to a model-only (or hostname-only) shortcut, this pins the
+ failure.
+ """
+ custom = [
+ {
+ "base_url": "https://other.example.invalid/anthropic",
+ "models": {"fable": {"prompt_caching": True}},
+ }
+ ]
+
+ assert get_custom_provider_model_capability(
+ "fable",
+ "https://example.invalid/anthropic",
+ "prompt_caching",
+ custom,
+ ) is None
+
class TestGetModelContextLengthHonorsOverride:
diff --git a/tests/run_agent/test_anthropic_prompt_cache_policy.py b/tests/run_agent/test_anthropic_prompt_cache_policy.py
index ea2ed73a4ef..9fe66cd4c36 100644
--- a/tests/run_agent/test_anthropic_prompt_cache_policy.py
+++ b/tests/run_agent/test_anthropic_prompt_cache_policy.py
@@ -212,6 +212,25 @@ class TestThirdPartyAnthropicGateway:
assert agent._anthropic_prompt_cache_policy() == (False, False)
+ def test_capability_on_other_route_does_not_apply(self):
+ """prompt_caching declared for a DIFFERENT base_url must not enable
+ caching for this agent's route — route isolation at the policy level."""
+ agent = _make_agent(
+ provider="custom:anthropic-proxy",
+ base_url="https://gateway.example.com/anthropic",
+ api_mode="anthropic_messages",
+ model="fable",
+ )
+ agent._custom_providers = [
+ {
+ "name": "other-proxy",
+ "base_url": "https://other.example.com/anthropic",
+ "models": {"fable": {"prompt_caching": True}},
+ }
+ ]
+
+ assert agent._anthropic_prompt_cache_policy() == (False, False)
+
class TestMiniMaxAnthropicWire:
"""MiniMax's own model family on its Anthropic-compatible endpoint.