feat: read prompt caching cache_ttl from config

- Load prompt_caching.cache_ttl in AIAgent (5m default, 1h opt-in)
- Document DEFAULT_CONFIG and developer guide example
- Add unit tests for default, 1h, and invalid TTL fallback

Made-with: Cursor
This commit is contained in:
WildCat Eng Manager
2026-04-19 13:40:52 -05:00
committed by Teknium
parent 9de555f3e3
commit 7626f3702e
4 changed files with 84 additions and 5 deletions

View File

@@ -685,6 +685,66 @@ class TestInit:
assert a.api_mode == "anthropic_messages"
assert a._use_prompt_caching is True
def test_prompt_caching_cache_ttl_defaults_without_config(self):
"""cache_ttl stays 5m when prompt_caching is absent from config."""
with (
patch("run_agent.get_tool_definitions", return_value=[]),
patch("run_agent.check_toolset_requirements", return_value={}),
patch("run_agent.OpenAI"),
patch("hermes_cli.config.load_config", return_value={}),
):
a = AIAgent(
api_key="test-k...7890",
model="anthropic/claude-sonnet-4-20250514",
base_url="https://openrouter.ai/api/v1",
quiet_mode=True,
skip_context_files=True,
skip_memory=True,
)
assert a._cache_ttl == "5m"
def test_prompt_caching_cache_ttl_custom_1h(self):
"""prompt_caching.cache_ttl 1h is applied when present in config."""
with (
patch("run_agent.get_tool_definitions", return_value=[]),
patch("run_agent.check_toolset_requirements", return_value={}),
patch("run_agent.OpenAI"),
patch(
"hermes_cli.config.load_config",
return_value={"prompt_caching": {"cache_ttl": "1h"}},
),
):
a = AIAgent(
api_key="test-k...7890",
model="anthropic/claude-sonnet-4-20250514",
base_url="https://openrouter.ai/api/v1",
quiet_mode=True,
skip_context_files=True,
skip_memory=True,
)
assert a._cache_ttl == "1h"
def test_prompt_caching_cache_ttl_invalid_falls_back(self):
"""Non-Anthropic TTL values keep default 5m without raising."""
with (
patch("run_agent.get_tool_definitions", return_value=[]),
patch("run_agent.check_toolset_requirements", return_value={}),
patch("run_agent.OpenAI"),
patch(
"hermes_cli.config.load_config",
return_value={"prompt_caching": {"cache_ttl": "30m"}},
),
):
a = AIAgent(
api_key="test-k...7890",
model="anthropic/claude-sonnet-4-20250514",
base_url="https://openrouter.ai/api/v1",
quiet_mode=True,
skip_context_files=True,
skip_memory=True,
)
assert a._cache_ttl == "5m"
def test_valid_tool_names_populated(self):
"""valid_tool_names should contain names from loaded tools."""
tools = _make_tool_defs("web_search", "terminal")