mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +00:00
fix: allow disabling prompt caching
(cherry picked from commit c1c1a12fe6)
This commit is contained in:
parent
7e7e3af5b0
commit
e6184c1cc6
3 changed files with 32 additions and 2 deletions
|
|
@ -521,7 +521,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:
|
||||
|
|
|
|||
|
|
@ -1410,8 +1410,11 @@ DEFAULT_CONFIG = {
|
|||
},
|
||||
|
||||
# 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",
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -1026,6 +1026,30 @@ class TestInit:
|
|||
)
|
||||
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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue