Ollama and Together AI: Making Open Models Work for Long-Horizon Agentic Workloads
Ollama and Together AI published a joint technical guide on making open models work for long-horizon agentic workloads. The central claim is that coding agents are dominated by large inputs and small outputs, so performance depends less on raw model speed than on protecting the prefix cache across turns; harness design and inference-engine routing both determine whether that cache survives.
Agent turns are mostly prefill, not decode
An agent turn is overwhelmingly a prefill problem because the harness resends the system prompt, every tool definition, the user request, every file read and every command result on each step, while the model usually returns only a short tool call. The source describes an agent loop in which each turn resends the growing transcript with only a small amount of new content, producing large input sequence length and small output sequence length.
The first phase, prefill, reads the whole prompt in one parallel pass and produces the first token; it is compute-bound and determines how long the user waits before any new tokens appear. The second phase, decode, writes the answer one token at a time, attends through everything before each new token, and is limited more by memory bandwidth than compute; it determines how fast text streams out. A normal chat response spends time in both phases. An agent turn is mostly prefill because the input is the whole session and the output is usually a short tool call. Reasoning models add thinking tokens, sometimes many, but as a session grows into the tens of thousands of tokens the input still dominates.
For agents, asking how fast a model is mostly means asking how fast it can get through a long history of previous turns. The practical answer is to cache that history and read it back instead of recomputing it.
Prefix caching changes the arithmetic of long sessions
Prefix caching is the main lever for long-horizon agent performance because it lets the inference engine reuse work from earlier turns instead of reprocessing the entire transcript on every request. The KV cache solves this within a single request: the engine keeps intermediate key and value pairs for earlier tokens and computes only the new ones. Prefix caching does the same across requests: turn 7 is turn 6 plus more content, so if the engine still holds turn 6 work, it only processes the new part.
The source gives an idealized arithmetic example. Over ten equal-sized turns, recomputing the full transcript takes 1 + 2 + ... + 10 = 55 units of prefill work; reusing the cached prefix and processing only new tokens takes 10 units. At one hundred turns, which the post says is not unusual for a coding task, the comparison is 5,050 versus 100. Real turns vary in size, so the figures are idealized. A cached session is also not completely free, because every new token still has to attend to the cached tokens.
The key rule is that a prefix cache matches from the beginning of the prompt up to the first token that is different, then stops. Everything after that first difference must be processed again. Appending to the end of the prompt does not invalidate earlier cached work. Changing anything earlier, even one character, forces reprocessing of everything after it. If the change is near the top of the prompt, the session has effectively been thrown away and the cache must be rebuilt.
The harness decides where the prompt first diverges
The harness controls what goes into each request, so it controls the point at which the prompt first differs from the prior request and therefore how much of the prefix cache can be reused. Ollama's side of the work is harness integration. The source says Ollama shipped the ability to connect harnesses through the ollama launch command, allowing tools such as Claude Code, Codex and Pi to work with open models such as DeepSeek-V4.1-Flash and GLM-5.3 while keeping existing workflows.
Connecting a harness to an API involves many layers of translation and differing expectations between harness and model. The source identifies this as a common cause of cache breakages, higher time and monetary costs, unexplainable agent behavior and harness errors.
Loading tool definitions late preserves more of the cache
Harnesses carry many tools, and putting every tool definition at the top of the prompt spends context on tools a task may never use while making it harder for the model to select the right tool. Newer harnesses support tool search, where the agent can search for and load a tool definition during the conversation.
For cache behavior, the location of that new definition matters. Adding a discovered tool to the initial tool list changes a section near the top of the prompt and invalidates later history. Appending the definition at the end of the conversation preserves the earlier prefix, because new content already goes there. The catch is model support: some chat templates do not expect a tool definition halfway through a conversation, and the call can error out. Whether a harness can load tools late without paying a cache penalty therefore depends on the model and on the model format, API adapter, renderer and tool-call parser supporting that representation.
Volatile system-prompt values force full recomputation
Putting turn-to-turn changing values in the system prompt is one of the easiest ways to destroy the prefix cache. A current timestamp, the git status or a working directory that keeps changing will make every turn a full re-read if the harness re-renders the system prompt on each turn.
Values that are fixed for one session but differ across sessions, such as the user name or the session start date, do not hurt that session. They do prevent new sessions from reusing a setup that is already cached. The recommended fix is to put variable information in the task message once and keep the system prompt identical everywhere.
Reasoning effort is a cache-sensitive session setting
The source hit a concrete cache problem on the Ollama side with GLM-5.3-Flash. In that model, reasoning effort is not a separate setting handled on the side by the engine; the chat template writes it into the very first system block, ahead of the tools and the conversation. Raising effort from low to high in the middle of a long task makes the next request differ almost at the first token, so the whole session is processed again. On a long run, changing one setting can cost hundreds of thousands of tokens of reprocessing.
The practical advice is to pick an effort level at the start and leave it there. If more thinking is needed, starting a fresh session at the higher setting is often cheaper than continuing the old one and also produces a clean context. Compacting before changing the reasoning value can reduce the number of prompt tokens that must be reprocessed.
Silent tool-output truncation damages agent behavior
A tool result becomes part of the next request and every request after it, so a large file read is paid for across the remaining turns and also consumes context window. Harnesses often cut tool output down, which is the right direction, but how the cut is made matters.
The source describes a failure case: an agent reads calendar.py, and the tool returns the first 100 lines of a 640-line file without saying it stopped. The function that matters, convert_timezone, is at line 420, and the model has no idea anything is missing. The fix is a single line in the output stating that the model received lines 1 to 100 of 640 and can search the file or request another range. With that notice, the model can search for timezone, find line 420 and read lines 410 to 450. Silent truncation saves tokens but can leave a model confidently editing code it never saw.
Subagent context should be chosen for cache and memory costs
Open models such as Kimi K3, GLM-5.3 and GLM-5.3-Flash are now good at splitting large tasks and handing pieces to subagents. How a harness starts each subagent determines how much of the parent cache can be reused.
One approach is full inheritance: the subagent receives the same system prompt, tools and conversation plus its assignment. Side chats work this way, branching off the parent session so the whole prefix is already cached. Another approach is a brief: the same system prompt and tools, then only the files and instructions the subagent needs. In that case the cache covers the shared setup and not the parent history.
Inheriting sounds strictly better, but the source says it is not. A cached prefix is cheap to process but not free: every token the subagent generates still has to read through it, and it occupies GPU memory the whole time. A reviewer that needs two files and a checklist probably does not need three hundred turns of history. If a subagent is given its own system prompt, it shares nothing with the parent, not even the setup.
The inference engine must keep the cache alive and reachable
A harness can follow every prompt-stability rule and still lose the benefit if the inference engine does not keep the cache available or does not route the next request to the machine that holds it. Together AI's side of the problem is the inference engine, which the source describes as a machine for keeping GPUs busy. A single GPU costs around $50k to rent per year, so an ideal engine keeps it from sitting idle, and at any moment it may serve hundreds of users each at a different point in a request.
Cache-aware routing sends each turn back to its prefix
A session cache lives on a particular node in a particular data center. If the next turn lands on another node, that node must process all earlier turns from scratch, and two nodes may end up storing the same prefix. Correct routing first selects a data center that runs the model, has capacity and is where the session has been running. It then selects a node inside that data center that holds the previous turns cache.
The source describes two main ways to pick the node. One is a key: the client sends something like prompt_cache_key with every request, and requests with the same key ideally go to the same node. The other is prefix hashing: hash the prefix and send the request to whichever node has the longest matching prefix cached, even if another session created that cache.
Prefix hashing is also why identical system prompts matter across sessions. If every session of a harness starts with exactly the same system prompt and tool definitions, a brand-new session may find that setup already cached. Unique identifiers in the system prompt guarantee that every session starts cold.
Routing is not as simple as always choosing the warm node. The warm node may be overloaded, forcing a choice between waiting there and taking an idle node while paying to process the prefix again. In that load-aware routing tradeoff, a cache miss can sometimes be the better deal. A perfectly stable prompt does not guarantee a hit if the backend inference engine is not implemented correctly.
Idle cache offload and block allocation manage GPU memory
Routing only helps if a cache still exists when the next request arrives. An agent may make a tool call and then wait a couple of minutes while tests run. Keeping that session cache in GPU memory the whole time takes space from active users, while discarding it means re-reading everything when the agent returns. The engine can therefore offload the cache to CPU memory while a session is idle and restore it for the next turn.
Memory is the constraint behind much of this design. The engine cannot know ahead of time whether a response will be 30 tokens or 30,000, so instead of reserving room for the maximum context length it hands out cache memory in small blocks as each request needs them, using PagedAttention in the way an operating system manages RAM. It also rebuilds the running batch on every pass through continuous batching, so when an agent fires five subagents at once, each new request takes a slot as soon as one frees instead of waiting for the slowest request in a batch to finish.
The consequence for harness builders is that headroom for cache memory, not compute, usually limits how many requests a GPU can serve at once. Every oversized tool result and every subagent carrying irrelevant history takes memory that another session cache could have used.
Disaggregated prefill and decode isolate the two phases
Agent workloads push the prefill and decode split to an extreme, with enormous prompts and tiny answers. To optimize for that pattern, the source says Together AI runs the two phases on separate clusters. One cluster is tuned for compute and performs prefill; the other is tuned for memory bandwidth and performs decode for hundreds of streams at once. The KV cache is shipped between them over RDMA. This separation means a wave of long agent prompts does not slow token streaming for everyone else, and each cluster can scale independently.
What a well-behaved long session looks like
The source combines the harness and engine rules in one session. On the harness side, the agent finds a calendar tool and adds its definition at the end of the conversation, so nothing above it changes. The agent reads calendar.py, sees that it received only lines 1 to 100 of 640, searches for timezone and reads the relevant section. Reasoning effort stays where it started. A reviewer subagent inherits the session to check agenda.ics against sessions.json.
On the engine side, every turn returns to the node that holds the session cache. While tests run, the cache waits in CPU memory. The reviewer request slots into the running batch, and each turn processes only what is new. The user does not see any of this; the visible result is that the agent stays fast at turn ninety. The arrangement depends on both sides doing their part. A harness can keep the prompt perfectly stable and still lose the cache if the engine sends turn 7 to the wrong machine. An engine can route perfectly and still lose the cache if the harness changes the first line every turn.
Why this matters for open-model agents
The practical rule for long-horizon agents is to keep the beginning of the prompt stable, append new material where possible and treat cache invalidation and cache memory as first-class design concerns. The source does not report benchmark results for specific models; its quantitative examples are idealized arithmetic showing why recomputation grows with the square of session length. It also does not claim that prefix caching alone solves long-horizon agents, because cache hits still cost attention and GPU memory and routing must balance cache warmth against load.
The broader implication is that open-model agent performance is a joint product of harness and inference-engine engineering. Tool loading, system-prompt construction, reasoning-effort changes, truncation notices and subagent context all affect whether a cache survives. Cache-aware routing, idle-cache offload, block-based memory allocation, continuous batching and separated prefill and decode clusters determine whether the engine can exploit a surviving cache. Neither side can deliver reliable long-session performance alone.