Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion agent/agent_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,10 @@ def init_agent(
from hermes_cli.config import load_config as _load_pc_cfg

_pc_cfg = _load_pc_cfg().get("prompt_caching", {}) or {}
_ttl = _pc_cfg.get("cache_ttl", "5m")
if isinstance(_pc_cfg, dict) and _pc_cfg.get("enabled") is False:
agent._use_prompt_caching = False
agent._use_native_cache_layout = False
_ttl = _pc_cfg.get("cache_ttl", "5m") if isinstance(_pc_cfg, dict) else "5m"
if _ttl in {"5m", "1h"}:
agent._cache_ttl = _ttl
except Exception:
Expand Down
5 changes: 4 additions & 1 deletion hermes_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1012,8 +1012,11 @@ def _ensure_hermes_home_managed(home: Path):
},

# Anthropic prompt caching (Claude via OpenRouter or native Anthropic API).
# cache_ttl must be "5m" or "1h" (Anthropic-supported tiers); other values are ignored.
# Set enabled: false as an escape hatch for strict providers that reject
# cache_control markers; cache_ttl must be "5m" or "1h" (Anthropic-supported
# tiers), other values are ignored.
"prompt_caching": {
"enabled": True,
"cache_ttl": "5m",
},

Expand Down
24 changes: 24 additions & 0 deletions tests/run_agent/test_run_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,30 @@ def test_prompt_caching_cache_ttl_invalid_falls_back(self):
)
assert a._cache_ttl == "5m"

def test_prompt_caching_enabled_false_disables_cache_markers(self):
"""prompt_caching.enabled=false is an escape hatch for strict providers."""
with (
patch("run_agent.get_tool_definitions", return_value=[]),
patch("run_agent.check_toolset_requirements", return_value={}),
patch("agent.anthropic_adapter._anthropic_sdk"),
patch(
"hermes_cli.config.load_config",
return_value={"prompt_caching": {"enabled": False}},
),
):
a = AIAgent(
api_key="test-key-1234567890",
provider="anthropic",
model="claude-sonnet-4-6",
base_url="https://api.anthropic.com/v1/",
quiet_mode=True,
skip_context_files=True,
skip_memory=True,
)
assert a.api_mode == "anthropic_messages"
assert a._use_prompt_caching is False
assert a._use_native_cache_layout is False

def test_valid_tool_names_populated(self):
"""valid_tool_names should contain names from loaded tools."""
tools = _make_tool_defs("web_search", "terminal")
Expand Down