中文版正在随流水线自动整理,稍后刷新即可;可先阅读下方英文原文。
本文由 AI图鉴自动抓取并翻译,版权归原作者所有;如需查看原文请点下方链接。
AI图鉴首页 › AI 资讯 › 让开放模型适用于长周期 agent 工作负载
前缀缓存帮助 coding agent 在对话增长时保持高效。提示词、工具调用和推理路由决定了模型可复用多少内容。
中文版正在随流水线自动整理,稍后刷新即可;可先阅读下方英文原文。
本文由 AI图鉴自动抓取并翻译,版权归原作者所有;如需查看原文请点下方链接。
Making open models work for long-horizon agentic workloads
November 16, 2026
By Parth Sareen and Zain Hasan (Together AI)
Coding agents have an odd traffic pattern. Every time the agent takes a step, the harness sends the model the entire conversation so far: the system prompt, every tool definition, your request, every file the agent has read, and every command it has run. What comes back is usually a tool call a few dozen tokens long. Then it happens again, with everything from last time plus a little more.
This large input sequence length (ISL) and small output sequence length (OSL) is characteristic of most agentic workloads. If the GPU had to work through that whole transcript from scratch on every turn, long sessions would get slower and more expensive with every step. Prefix caching is what saves most of that work. The problem is that if you’re not careful it’s also very easy to break the prefix cache.
We come at this problem from opposite ends. Ollama works on harness integrations which means deciding what goes into each request. Together AI works on the inference engine which means deciding what happens when that request arrives. We kept finding that much of our work on each side is about protecting the cache from things the other side can do to it, so we wanted to write it all down in one place to help agent and infra builders alike!
What an agent turn looks like to a GPU
Every request goes through two phases. The first is prefill: the engine reads the whole prompt in one big parallel pass and produces the first token. GPUs are good at this because it’s a lot of math done all at once which maximizes arithmetic intensity. Prefill determines how long you wait before any new tokens appear. The second is decode: the model writes the rest of the answer one token at a time, and each new token requires reading back and attending through everything before it. Decode is limited by memory bandwidth more than by compute, and it determines how fast the text streams out.
A normal chat response spends time in both phases while 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 on top of that, sometimes a lot of them, but as a session grows into the tens of thousands of tokens the input still dominates. Each turn the input gets longer, and the output stays roughly the same size — a few tool calls.
So for agents, “how fast is this model?” mostly means “how fast can it get through a long historical account of previous turns?” The way to process a task with lots of previous turns quickly is to just cache it and read it back in rather than recomputing.
Cache is king
The easiest way to picture the KV cache (or even the prefix cache, for that matter) is reading. Imagine that to read each new word on a page, you had to start again from the top. The further down the page you got, the slower you’d go, because you’d keep having to reread everything you’d already read. That’s a model with no cache. The cache solves this within a single request: the engine keeps the work it did on earlier tokens (stored as intermediate key, value pairs) and computes only the new one.
Prefix caching does the same thing across requests. Turn 7 of an agent session is turn 6 plus a bit more, so if the engine still holds turn 6’s work, it only has to process the new part.
The arithmetic is simple. If each turn adds the same amount, ten turns without caching process 1 + 2 + … + 10 = 55 units of prompt. With caching, they process 10. At a hundred turns, which isn’t unusual for a coding task, it’s 5,050 versus 100. Real turns vary in size, so treat these as idealized numbers. A cached session isn’t completely free either, since every new token still has to attend to the cached ones. But the pattern holds: without caching, the work you redo grows with the square of the session length.
The catch is that a prefix cache matches from the beginning of the prompt up to the first token that’s different, and stops there. Everything after that first difference has to be processed again.
Adding to the end of the prompt costs nothing extra. Changing anything earlier, even a single character, means re-processing everything after it. If the change is near the top, you’ve effectively thrown away the whole session and now must rebuild the cache. Almost everything else in this post follows from that one rule.
The harness decides where that first change lands. The engine decides whether the cache is still there when the next request shows up. We’ll start with the harness.
The harnesses and APIs
On the Ollama side, we shipped the ability to connect your favorite harness through the ollama launch command. So you can connect harnesses like Claude Code, Codex, Pi (and more) with open models like DeepSeek-V4.1-Flash and GLM-5.3 and maintain your existing workflows.
Connecting a harness to an API might seem easy, but there are many layers of translation and varying expectations between a harness and a model. This often is the cause of cache breakages (incurring time and monetary costs), unexplainable agent behavior, and the harness outright erroring.
Loading tools late
Harnesses carry quite a few tools now. If every definition goes into the prompt up front, you spend context on tools the task will never use, and the model gets worse at picking the right one. Newer harnesses have added a feature for tool search to alleviate this, where the tool can be loaded and used by the agent itself after searching for it.
Let’s say you have a personal assistant as an agent which has this capability. If you ask the agent to export the events you’ve starred to a calendar, and it searches for “calendar,” loads the save_calendar definition, and calls it.
For the cache, the question is where that definition goes.
The obvious approach is to add the definition to the tool list. That works, but the tool list sits near the top of the prompt, before the conversation. So if the prefix changes everything after it gets processed again. On a long session, that can be hundreds of thousands of tokens. The better approach is to put the definition at the end, where new content goes anyway.
Except not every model supports that. Some chat templates don’t expect a tool definition halfway through a conversation, and the call errors out. So whether a harness can load tools late without paying for it depends on the model. Users shouldn’t have to know this, but anyone building a harness does.
Things at the top that change
The easiest way to wreck the cache is to put something in the system prompt that changes from turn to turn, like a current timestamp, the git status, or a working directory the agent keeps moving through. If the harness re-renders the system prompt with fresh values on every turn, every turn is a full re-read.
Things that are fixed for a session but differ between sessions, like the user’s name or the date the session started, don’t hurt that session. They do stop new sessions from reusing a setup that’s already cached, which we’ll get to on the engine side. Either way, the fix is the same: put that information in the task message, once, and keep the system prompt identical everywhere.
Reasoning effort
We hit this one on the Ollama side. In GLM-5.3-Flash, reasoning effort isn’t a separate setting the engine handles on the side. The chat template writes it into the very first system block, ahead of the tools and the conversation.
Let’s say you’re deep into a long task and it isn’t going well. You raise effort from low to high. That’s a reasonable thing to do, but the next request now differs from the last one almost at the first token. Which means the whole session gets processed again. On a long run, that can be hundreds of thousands of tokens spent on changing one setting.
Our advice is to pick an effort level at the start and leave it there. If you really need more thinking, it’s often cheaper to start a fresh session at the higher setting than to continue the old one, and you get a clean context out of it too. You could also compact before changing the reasoning value to decrease the amount of prompt tokens.
Big tool results
A tool’s output becomes part of the next request, and of every request after it. If the agent reads a 3,000-line file when it needed forty lines, you don’t pay for that once; you pay for it on every remaining turn (even if it is cached you lose out on the context window). To combat this, harnesses often cut tool output down. That’s the right call, but how you cut tool output matters.
Here’s a failure that’s easy to build by accident. The task is to fix a timezone bug in a calendar export. The 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. The model has no idea it’s missing anything.
The fix is a single line in the output, telling the model it got lines 1 to 100 of 640 and that it can search the file or request another range. With that, the model searches for “timezone,” finds line 420, and reads lines 410 to 450. Cutting output saves money. Cutting it without saying so gets you a model confidently editing code it never saw.
Subagents
Open models like Kimi K3, GLM-5.3, and GLM-5.3-Flash are now pretty good at splitting a big task and handing pieces to subagents. How the harness starts each subagent decides how much of the parent’s cache it can reuse.
One option is for the subagent to inherit everything: the same system prompt, tools, and conversation, plus its assignment. Side chats work this way. They branch off the parent session, so the whole prefix is already cached. The other option is to send a brief: the same system prompt and tools, then only the files and instructions the subagent needs. In that case the cache covers the setup and nothing more.
Inheriting sounds strictly better, but it isn’t. A cached prefix is cheap to process, 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 doesn’t need three hundred turns of history. And if you give a subagent its own system prompt, it shares nothing with the parent at all, not even the setup.
The engine side
You can do everything above perfectly and still not benefit. The cache has to still exist, and the next request has to reach the machine that holds it.
At Together AI, we think of an inference engine as a machine for keeping GPUs busy. A single GPU costs around $50k to rent per year, so ideally it should never sit idle, and at any moment it’s serving hundreds of users who are each at a different point in their request. Agent traffic pushes on those constraints in a few specific ways.
Routing requests for optimal cache hits
A session’s cache lives on a particular node in a particular data center. If the next turn in a conversation lands anywhere else, that node has to process all earlier turns from scratch, and now two nodes are storing the same prefix. In order to route correctly we first need to pick a data center that runs the model, has capacity, and is where the session has been running. Then we need to pick a node inside it that has the previous turns cache.
There are two main ways to pick the node. The simple one is to use a key: the client sends something like prompt_cache_key with every request and then ideally we route every request with the same key to the same node. The other way is to hash the prefix and send the request to whichever node has the longest matching prefix cached, even if another session put it there.
That second option is the other reason to keep the system prompt identical. If every session of a harness starts with exactly the same system prompt and tool definitions, a brand-new session might be able to find that setup already cached. If you put unique identifiers in there then every session is guaranteed
Auto-fetched and translated by AI Atlas. All rights belong to the original author.
1Panel AI 网关为内部 AI 应用和模型调用提供统一接入入口,支持模型代理、席位管理、用量统计、智能
AI 智能体工程斯坦福 Stanford CS329Z(Engineering AI Agents)中文学习教程,面向 Py
Noema Lab 创作实验室Noema Lab 提供图片分析、音乐理解、歌词创作、提示词优化、音乐生成和音频处理工具,帮助音乐创作者迭代
Raphael AIRaphael AI 是在线 AI 图像生成与编辑平台,可通过提示词生成图像、使用参考图并选择不同模型,也提
腾讯混元新人免费体验包(每模型可领,截至 2026-12-31)
SambaNovaSambaNova 注册约 $5 免费额度
Together AITogether AI 注册最高 $100 赠金
小米 MiMo新用户注册送免费体验额度
标题、摘要与正文均来自该信源的公开页面,版权归原作者所有;本站自动聚合与翻译,仅作出处跳转。