Skip to content

feat: configurable prompt_caching.cache_ttl (5m default, 1h opt-in) — salvage #12659 - #15065

Merged
teknium1 merged 3 commits into
mainfrom
hermes/hermes-37dfb080
Apr 24, 2026
Merged

feat: configurable prompt_caching.cache_ttl (5m default, 1h opt-in) — salvage #12659#15065
teknium1 merged 3 commits into
mainfrom
hermes/hermes-37dfb080

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Salvage of #12659 by @ericnicolaides onto current main. Chosen over parallel PRs #14812 (env-var only, violates '.env for secrets only') and #3082 (threads kwarg through gateway + session + state DB — unnecessarily heavy for a 2-value config).

Closes #14971.

What this PR does

Exposes Anthropic's 1h prompt-cache TTL tier as a config option. Default remains 5m — zero behavior change for existing users.

# ~/.hermes/config.yaml
prompt_caching:
  cache_ttl: "1h"   # opt-in; default is "5m"

Motivated by #14971 cost data: on a $246 Anthropic workload, 56.5% of spend was input_cache_write_5m — the cache was rewriting more than reading because the 5m TTL kept expiring between turns. The 1h tier costs 2x on write (vs 1.25x for 5m) but amortizes across a full session. The 1h path has been supported inside apply_anthropic_cache_control() since it landed; this PR just exposes it.

How

AIAgent.__init__ reads prompt_caching.cache_ttl via hermes_cli.config.load_config(). Validates against {"5m", "1h"}; anything else falls back to "5m" without raising. DEFAULT_CONFIG gets a prompt_caching section so the merge resolves cleanly for upgraders. Same conflict resolution applied to match current main's _anthropic_prompt_cache_policy() helper refactor.

Changes

Validation

Config Expected _cache_ttl Got
(no prompt_caching section) 5m 5m
cache_ttl: "1h" 1h 1h
cache_ttl: "30m" (invalid) 5m (fallback) 5m
cache_ttl: "5m" (explicit) 5m 5m
prompt_caching: {} (empty) 5m 5m
  • tests/run_agent/test_run_agent.py -k cache_ttl — 3/3 pass (new tests)
  • tests/agent/test_prompt_caching.py — 14/14 pass (regression guard)
  • E2E: 5 scenarios above verified with real config.yaml + AIAgent instantiation

Co-authored-by: @ericnicolaides

WildCat Eng Manager and others added 3 commits April 24, 2026 03:19
- 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
@teknium1
teknium1 merged commit 3391234 into main Apr 24, 2026
11 of 13 checks passed
@teknium1
teknium1 deleted the hermes/hermes-37dfb080 branch April 24, 2026 10:21
@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint area/config Config system, migrations, profiles provider/anthropic Anthropic native Messages API labels Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have provider/anthropic Anthropic native Messages API type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: make prompt cache TTL configurable (5m vs 1h)

2 participants