How to keep open-model coding agents fast in long sessions
Brief
Long agent sessions repeatedly send their conversation history, so preserving reusable prefix-cache data can reduce repeated prompt processing.
Keep the prompt prefix stable
- Prefix caching reuses work only until the first changed token; changing an early prompt element can force the rest of the prompt to be processed again.
- Keep the system prompt identical across turns. Put changing details in the task message, and choose reasoning effort at the start of a session.
- When loading tools late, add their definitions at the end of the prompt where supported; some model chat templates do not allow this.
Control context and cache use
- Trim oversized tool results, but tell the model what was omitted and how it can request the missing content.
- Subagents can inherit a parent's cached history or receive only a brief; inherited context may use cache memory unnecessarily.
- The article gives an idealized comparison: ten turns process 55 prompt units without caching versus 10 with caching; at 100 turns, 5,050 versus 100.
Route and retain cached sessions
- A cache hit depends on routing the next request to a node holding the session cache; overloaded warm nodes can make a cache miss preferable.
- The article describes offloading idle session caches to CPU memory and using paged cache allocation and continuous batching to manage GPU memory.
- Ollama says
ollama launchcan connect harnesses including Claude Code, Codex, and Pi to open models such as DeepSeek-V4.1-Flash and GLM-5.3.
Generated by AI from the original article. Check the source for full details.