hermes - 💡(How to fix) Fix [RFC] Reorder system prompt for shared prefix caching

Official PRs (…)
ON THIS PAGE

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
RAW_BUFFERClick to expand / collapse

Problem

The current system prompt order places variable content (user's project context, memory, task-specific instructions) before stable content (tool definitions, behavior rules). This means the prefix cache is invalidated on every turn — each new user message changes the prompt prefix, so no two turns share a cached prefix.

Proposed solution

Rearrange the system prompt assembly so that stable, repeating content comes first:

  1. Tool definitions / behavior rules (stable across turns)
  2. Task/project context (changes per conversation)
  3. Per-turn user message (changes every turn)

This way, turns 2+ in a conversation share the same prefix cache from the tool definitions block. On providers that support prefix caching (Anthropic, some OpenAI tiers, certain local backends), this can reduce prompt processing time by 30-50% on turns after the first.

Implementation is a simple reordering in the system prompt assembly function — no logic changes, no new features. The functional output is identical; only cache locality changes.

I've been running this locally for ~2 weeks. The observable effect is that second and subsequent turns feel noticeably faster on local backends with KV caching. On cloud APIs the token savings are invisible to the user but reduce billed prompt tokens.

Open to discussion on whether the reordering has any side effects on model behavior (none observed in my testing, but the team may know edge cases).

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - 💡(How to fix) Fix [RFC] Reorder system prompt for shared prefix caching