Implementation:42 evey Hermes plugins cached delegate
| Knowledge Sources | |
|---|---|
| Domains | Caching, LLM_Delegation, Cost_Optimization |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Concrete tool for SHA-256 content-addressed caching of LLM delegation results with 24-hour TTL and LRU eviction, returning cached results at zero cost on cache hits.
Description
The cached_delegate handler wraps the delegation pattern with a local cache. It hashes the model + goal pair via SHA-256 (first 16 hex chars) as the cache key, checks the cache file at ~/.hermes/workspace/orchestrator/delegation-cache.json, and returns the cached result instantly if found and within TTL. On a miss, it delegates fresh via _delegate_fresh and stores the result.
Key internal components:
- _cache_key(model, goal) — SHA-256 hash of
"{model}::{goal}"(lowercased), first 16 hex chars. Context is NOT included in the key. - _load_cache() — loads the JSON cache file from disk.
- _save_cache(cache) — saves cache with TTL expiry eviction (entries older than
TTL_SECONDS = 86400removed) and LRU eviction (if overMAX_ENTRIES = 100, evicts oldest bylast_accessed). - _delegate_fresh(model, goal, context, max_tokens) — makes a fresh
ctx.llm.completecall with the same model override trust logic asdelegate_with_model. Returns(content, tokens, model_used, note).
Usage
Call this tool for recurring questions, daily status checks, or repeated research where the answer doesn't change frequently. Registered as cached_delegate on the evey_cache toolset.
Code Reference
Source Location
- Repository: hermes-plugins
- File: evey-cache/__init__.py
- Lines: L34-251 (handler L152-240, _cache_key L73-76, _load_cache L79-89, _save_cache L92-118, _delegate_fresh L121-149, schema L34-70)
Signature
def handler(args: dict, **kwargs) -> str:
"""
Args:
args: {
model: str - optional model id,
goal: str (required) - the task or question,
context: str - extra context (NOT included in cache key),
max_tokens: number - default 2000,
bypass_cache: bool - force fresh delegation (default false)
}
Returns:
JSON: {status: "cache_hit", result, model, cached_at, age_seconds, hit_count, tokens_saved, cost: "zero (cached)"}
or {status: "cache_miss", result, model, tokens, cache_key, cache_size}
"""
def _cache_key(model: str, goal: str) -> str:
"""SHA-256 hash of model+goal, first 16 hex chars."""
def _load_cache() -> dict:
"""Load cache from disk."""
def _save_cache(cache: dict) -> dict:
"""Save cache with TTL + LRU eviction. Returns saved cache."""
def _delegate_fresh(model, goal, context, max_tokens) -> tuple[str, int, str, str | None]:
"""Fresh ctx.llm call. Returns (content, tokens, model_used, note)."""
Import
from evey_cache import handler
# Or accessed via Hermes tool call: cached_delegate
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| goal | str | Yes | The task or question |
| model | str | No | Model id (requires operator grant for override) |
| context | str | No | Extra context (NOT in cache key — different context = same cache entry) |
| max_tokens | number | No | Max response length (default 2000) |
| bypass_cache | bool | No | Force fresh delegation (default false) |
Outputs
| Name | Type | Description |
|---|---|---|
| status | str | "cache_hit", "cache_miss", "delegation_failed", or "error"
|
| result | str | The delegation result (cached or fresh) |
| model | str | Model that produced/cached the result |
| age_seconds | int | Cache entry age (cache_hit only) |
| hit_count | int | Number of cache hits for this entry |
| tokens_saved | int | Tokens saved by cache hit (cache_hit only) |
| cost | str | "zero (cached)" on hit
|
| cache_key | str | SHA-256 hash key (cache_miss only) |
| cache_size | int | Total cache entries after save (cache_miss only) |
Usage Examples
Cache Hit
# First call — cache miss, delegates and stores
tool_call("cached_delegate", {"goal": "Summarize today's news about AI"})
# {"status":"cache_miss","result":"...","model":"active","tokens":500,
# "cache_key":"a1b2c3d4e5f6a7b8","cache_size":1}
# Second call (same goal) — cache hit, zero cost
tool_call("cached_delegate", {"goal": "Summarize today's news about AI"})
# {"status":"cache_hit","result":"...","model":"active","cached_at":"2026-10-29 10:00:00",
# "age_seconds":3600,"hit_count":1,"tokens_saved":500,"cost":"zero (cached)"}
Bypass Cache
# Force a fresh delegation even if cache exists
tool_call("cached_delegate", {
"goal": "What is the current weather?",
"bypass_cache": True
})
# Always returns {"status":"cache_miss",...}