feat(caching): HERMES_CACHE_TTL env var to enable 1h prompt cache - #14812
Closed
Nazariy995 wants to merge 1 commit into
Closed
feat(caching): HERMES_CACHE_TTL env var to enable 1h prompt cache#14812Nazariy995 wants to merge 1 commit into
Nazariy995 wants to merge 1 commit into
Conversation
Nazariy995
force-pushed
the
feat/cache-ttl-env
branch
from
April 23, 2026 23:22
32f7fa1 to
435381d
Compare
Collaborator
Nazariy995
force-pushed
the
feat/cache-ttl-env
branch
from
April 24, 2026 00:03
435381d to
0074c9e
Compare
The 1h cache tier has been plumbed into apply_anthropic_cache_control() since its introduction, but there was no way to reach it from user config — self._cache_ttl was hardcoded to '5m'. This made the 1h tier effectively unreachable outside of calling the function directly. Read HERMES_CACHE_TTL from the environment instead. '5m' stays the default so nothing changes for existing deployments. Invalid values fall back to '5m' silently so a typo in .env never breaks an in-progress conversation. Useful for coding workflows with meeting breaks: chat for 10 min, walk away, come back 30 min later — 5m cache expired, 1h cache still warm. Write cost is 2x vs 1.25x, so only worth enabling when reuse gaps > 5 min are common. Tests: 5 new cases in tests/agent/test_prompt_caching.py covering default fallback, 1h pass-through, invalid value rejection, case/whitespace normalization, and end-to-end env-to-marker propagation.
Nazariy995
force-pushed
the
feat/cache-ttl-env
branch
from
April 24, 2026 00:07
0074c9e to
597da16
Compare
This was referenced Apr 24, 2026
Contributor
|
Thanks for the PR @Nazariy995 — same TTL-configurability goal was met via salvage #15065 (of parallel #12659). Closed because Hermes's policy is Appreciate the detailed cost analysis in the body — exactly the kind of real-workload motivation that moves a feature forward. Please keep contributing. |
Author
|
@teknium1 thank you for that appreciate it! i am loving this project! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Enables the 1-hour Anthropic prompt-cache tier via a new
HERMES_CACHE_TTLenv var. The"1h"TTL path has been supported insideapply_anthropic_cache_control()since it landed, but there was no user-facing way to reach it —self._cache_ttlwas hardcoded to"5m"atrun_agent.py:1001.Why this matters: On Anthropic, a 1h cache-write costs 2x the base input rate (vs 1.25x for 5m), but the cached prefix survives 12x longer. It's a clear win for workflows where the same prefix gets reused with gaps > 5 min — coding sessions with meeting breaks, sparse cron-driven agents, long-form research. Before this PR, enabling the 1h tier required forking hermes-agent or monkey-patching
AIAgent._cache_ttlat runtime.Design: Read the env var directly at
AIAgent.__init__time rather than threading a kwarg through the gateway → runner → AIAgent path. This keeps the config surface stable across CLI, gateway, batch_runner, cron, and any future entry point without touching ~30 files. Invalid values ("30m","forever", typos) fall back silently to"5m"so a mistake in.envnever crashes a conversation mid-turn.Related Issue
Fixes #
Type of Change
Changes Made
run_agent.py:1001— readHERMES_CACHE_TTLfrom env, validate against{"5m", "1h"}, fall back to"5m"on any other valuetests/agent/test_prompt_caching.py— newTestCacheTTLEnvOverrideclass with 5 casesHow to Test
unset HERMES_CACHE_TTL pytest tests/agent/test_prompt_caching.py -qChecklist
Code
feat(caching): ...)pytest tests/agent/test_prompt_caching.py -q— 19/19 passDocumentation & Housekeeping
docs/, docstrings) — N/A for this PR;website/docs/developer-guide/context-compression-and-caching.mdalready documentscache_ttl: "5m" or "1h"as valid values. Happy to add a paragraph pointing users at the env var if maintainers want — let me know.cli-config.yaml.exampleif I added/changed config keys — N/A (env var only, no YAML key)CONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/Aos.getenv()is stdlib, works identically everywhereScreenshots / Logs
Before (hardcoded
"5m"):After, with
HERMES_CACHE_TTL=1h:Test run: