Skip to content

[Bug] Anthropic prompt cache hit rate still low: cache_control lands on dynamic datetime block #9625

Description

@vcvcvcvcvcvcvcvcvc

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:providerThe bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner.feature:personaThe bug / feature is about astrbot AI persona system (system prompt)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions