How Reasonix Keeps DeepSeek Prefix Cache Hits at 99%
DeepSeek's cache-hit pricing can cut token costs by 90%, but most integrations leak hits through small prefix mutations. Reasonix's approach—immutable prefixes, tail-appended state, and CI-enforced cache discipline—is a replicable blueprint for any project that wants to stop burning money on avoidable cache misses.
DeepSeek's automatic prefix caching slashes API costs for repeated prompt prefixes, but most projects see hit rates of 20–30%. Reasonix, an agent harness built specifically for DeepSeek, routinely hits 99% by treating the prompt prefix as immutable infrastructure. The base prompt, output style, language policy, persistent memory, skill index, and tool schemas are assembled once at boot and never touched mid-session.
Every state change that the model must know about—plan mode toggles, mid-session memory additions, background job completions—gets wrapped in XML blocks and prepended to the current user message, at the tail of the prompt. The stable prefix stays cache-warm; only the small tail misses. At the provider layer, Reasonix also patches a DeepSeek thinking-mode edge case where dropping `reasoning_content` on a tool-call replay causes a 400 error.
Engineering discipline locks in the gains. A run-loop diagnostic reports per-turn prefix changes and reasons for misses. CI scripts block any PR that touches cache-sensitive files unless the PR body explicitly declares cache impact, rejecting placeholder answers like "n/a" or "todo." For dual-model planner-executor setups, Reasonix keeps sessions fully independent so neither model's prefix is disturbed by the other's turns.
Most projects leak DeepSeek cache hits not through architectural flaws but through undisciplined prefix mutation—a memory note slipped into the system prompt, a tool schema tweaked mid-session. Reasonix shows that the real lever is organizational: making cache impact a required field on every PR.
Reasonix's plan-mode implementation is a sharp example of doing the simple thing that works: don't mutate the tool schema to disable writes, just intercept the call and let the model see the error. The schema stays cache-stable, and the model adapts.
The cumulative hit-rate metric that survives log compression is an underappreciated detail. Resetting the counter on compression would hide real degradation behind a misleading number.
Independent sessions for planner and executor solve a problem that many multi-agent systems ignore: model-switching inside a shared conversation destroys prefix cache entirely. The cost of separate sessions is trivial compared to the cache savings.