What happened
PR #9197 added cache_control to the last system block. But in practice the cache hit rate remains near 0% because the last system block is always the dynamic datetime reminder: 当前时间是: 2026-08-10 16:16:11
This block changes every single request, so Anthropic detects a cache miss and re-creates the entire cache each time. The large static portions (persona, behavior rules — ~8000+ tokens) that should be cached never actually get read from cache.
Root cause
_apply_explicit_prompt_cache_breakpoints unconditionally picks system_blocks[-1]. But AstrBot assembles system blocks with dynamic content (desire_state, daily_briefing, datetime) at the END. The cache_control lands on the datetime block, invalidating the entire cache every request.
Suggested fix
Scan system blocks from end backwards, skip short blocks containing 当前时间 / Current datetime markers, and place cache_control on the last substantial static block instead. This would increase cache hit rate from ~0% to 80%+.
Version
v4.27.2 (Docker)
Willing to PR?
Yes
What happened
PR #9197 added
cache_controlto the last system block. But in practice the cache hit rate remains near 0% because the last system block is always the dynamic datetime reminder:当前时间是: 2026-08-10 16:16:11This block changes every single request, so Anthropic detects a cache miss and re-creates the entire cache each time. The large static portions (persona, behavior rules — ~8000+ tokens) that should be cached never actually get read from cache.
Root cause
_apply_explicit_prompt_cache_breakpointsunconditionally pickssystem_blocks[-1]. But AstrBot assembles system blocks with dynamic content (desire_state, daily_briefing, datetime) at the END. The cache_control lands on the datetime block, invalidating the entire cache every request.Suggested fix
Scan system blocks from end backwards, skip short blocks containing
当前时间/Current datetimemarkers, and placecache_controlon the last substantial static block instead. This would increase cache hit rate from ~0% to 80%+.Version
v4.27.2 (Docker)
Willing to PR?
Yes