Long coding-agent sessions create a distinctive inference workload: each step usually resends the full conversation so far, while the response may be only a short tool call. Ollama and Together AI explain how prefix caching can reduce repeated work—and how agent-harness and infrastructure choices can undermine that benefit.
A cache can reuse earlier computations as long as the beginning of the new prompt remains unchanged. If something there changes, such as a dynamic value in the system prompt or a newly selected reasoning level, the following context must be processed again. The authors recommend moving changing details into the task message where possible and keeping settings such as reasoning effort constant during a session.
Tool use and agent delegation matter too. Loading tool definitions later can preserve the cache, but the post says this does not work with every model template. When tool outputs are shortened, the agent should be told what was omitted. Subagents can inherit a parent agent’s conversation, but long contexts still use memory and must be considered when generating new output.
Finally, the inference engine needs to route a request to a machine holding the relevant cache. The post discusses routing approaches, but the supplied source text cuts off partway through that section. Its caching calculations are explicitly idealized examples, not reported benchmark results. Original source: Ollama Blog