跳到主内容
@wquguru
精选88Cursor 博客(web_list)技巧与观点

Cursor 工程复盘:通过精简 Prompt 与动态加载工具降低 Agent

Sep 23, 2026·researchImproved token efficiency for longer agent runsJediah, Connor & Calvin7mJediah, Connor & Calvin·7m

原文
发到 X
推荐理由

Agent 开发者必读,详细拆解了从 Prompt 裁剪、工具动态加载到缓存断点优化的完整工程实践,可直接复用到你的 Agent 架构中。

Blog / research

博客 / 研究

As agents have matured and learned to tackle more ambitious tasks, token spend has shifted. Agents now work for longer and carry more context from one step to the next, making the way we assemble and manage that context increasingly important.

随着智能体(Agents)的成熟以及学会处理更具雄心的任务,Token 消耗发生了转变。智能体现在运行时间更长,并在步骤之间携带更多上下文,这使得我们组装和管理这些上下文的方式变得越来越重要。

Where agent inference spend goes

智能体推理消耗的分布

Production traffic · width = share of total spend · shade = billing type

生产流量 · 宽度 = 占总消耗的份额 · 色调 = 计费类型

  • Output
  • Uncached input
  • Cached input
  • 输出
  • 未缓存输入
  • 已缓存输入

Where agent inference spend goes

智能体推理消耗的分布

Production traffic · width = share of total spend · shade = billing type

生产流量 · 宽度 = 占总消耗的份额 · 色调 = 计费类型

  • Output
  • Uncached input
  • Cached input
  • 输出
  • 未缓存输入
  • 已缓存输入

Where agent inference spend goes

智能体推理消耗的分布

Production traffic · width = share of total spend · shade = billing type

生产流量 · 宽度 = 占总消耗的份额 · 色调 = 计费类型

  • Output
  • Uncached input
  • Cached input
  • 输出
  • 未缓存输入
  • 已缓存输入

Notes: System & tool defs includes compaction summaries. User text includes manually attached skills. Skills & plugins includes skill descriptions, MCP tool descriptions, and rules that go in static context.

注:系统 & 工具定义包括压缩摘要。用户文本包括手动附加的技能。技能 & 插件包括技能描述、MCP 工具描述以及放入静态上下文的规则。

Over the past few months we've responded to this shift by improving the efficiency of Cursor's agent harness. The harness gives us direct control over how each request is assembled, how context is reused, and when work is divided across agents. Changes across each of these layers reduced token costs for users by 7% without reducing agent quality.

在过去几个月里,我们通过提高 Cursor 智能体框架(agent harness)的效率来应对这一转变。该框架让我们能够直接控制每个请求的组装方式、上下文的复用方式,以及工作如何在不同智能体之间分配。这些层面的改进在不降低智能体质量的前提下,为用户减少了 7% 的 Token 成本。

#Trimming the system prompt

# 精简系统提示词

Every agent turn includes context supplied by Cursor before the model begins working. This includes the system prompt and definitions for the tools the agent can use. Because this context is included throughout a conversation, it had become one of the largest sources of spend that we fully control.

每次智能体轮次都包含模型开始工作前由 Cursor 提供的上下文。这包括系统提示词和智能体可用工具的定義。由于这些上下文贯穿整个对话,它们已成为我们完全可控的最大消耗来源之一。

When models were less capable, we had to spell out instructions for tool usage, task management, and code-change workflows. We also had to guard against strange behaviors like extremely long hash dumps, binary output, and emojis.

当模型能力较弱时,我们必须详细说明工具使用、任务管理和代码变更工作流的指令。我们还必须防范诸如极长的哈希转储、二进制输出和表情符号等异常行为。

As models improved, much of that direction became unnecessary. Instead of long lists of "DO NOT do this," "You must," or "Important" instructions, we could simply define how a tool behaves and models would generally comply. This was true across model families, allowing us to trim roughly 66% of our system prompt.

随着模型的改进,许多此类指导变得不再必要。与其列出长长的“不要这样做”、“你必须”或“重要”指令,我们可以简单地定义工具的行为方式,模型通常就会遵守。这在各个模型家族中都适用,使我们能够将系统提示词精简约 66%。

Over time, we continue to add and remove instructions as new models require new guidance, which then flows into the training of future models. Leveraging A/B tests on a large user base is crucial to effectively optimizing the harness for real traffic. While evals can be a fast and useful proxy, they often represent "hard" problems and don't properly reflect the true distribution of user requests.

随着时间的推移,我们会根据新模型所需的新指导不断添加和移除指令,这些指导随后会流入未来模型的训练中。在大规模用户群体上利用 A/B 测试对于针对真实流量有效优化框架至关重要。虽然评估(evals)可以是一个快速且有用的代理指标,但它们往往代表的是“硬”问题,并不能正确反映用户请求的真实分布。

#Loading tools only when needed

#按需加载工具

The system prompt is only one part of the context Cursor supplies on every turn. Another is tool definitions, which had grown dramatically over the course of the year as we added more powerful capabilities to the Cursor agent, including background shell monitoring, cloud subagents, and more reliable access to web content. Most of these tools are important, but each is needed in fewer than 20% of conversations.

系统提示词只是 Cursor 在每一轮交互中提供的上下文的一部分。另一部分是工具定义,随着我们赋予 Cursor Agent 更强大的能力(包括后台 Shell 监控、云端子代理以及更可靠的 Web 内容访问等),这些定义在过去一年中大幅增长。其中大多数工具都很重要,但在少于 20% 的对话中才会用到每一个工具。

That created an opportunity to improve efficiency by keeping tools available without including their full definitions in every request. We'd solved a similar problem earlier this year when we moved MCP tools into dynamic context, loading them only when needed. This reduced total tokens by 46.9% across sessions that called an MCP tool.

这为我们提供了一个通过保持工具可用但不将它们的完整定义包含在每个请求中来提升效率的机会。今年早些时候,当我们把 MCP 工具移入动态上下文并仅在需要时加载它们时,我们就解决过类似的问题。这在调用 MCP 工具的会话中将总 Token 量减少了 46.9%。

We have now applied the same technique to our own built-in tools.

我们现在已将同样的技术应用于我们自己的内置工具。

To decide which tools to keep in static context, we A/B tested several configurations based on how often each tool was used and whether models needed to see it from the start. We tracked token usage, cost, latency, tool-call errors, and overall agent usage to make sure the savings did not degrade quality.

为了决定哪些工具保留在静态上下文中,我们基于每个工具的使用频率以及模型是否需要从一开始就看到它,对几种配置进行了 A/B 测试。我们跟踪了 Token 使用情况、成本、延迟、工具调用错误以及整体 Agent 使用情况,以确保节省下来的资源不会降低质量。

Most commonly invoked tools

最常调用的工具

Share of agent conversations invoking each tool at least once

至少调用过一次各工具的 Agent 对话占比

Most commonly invoked tools

最常调用的工具

Share of agent conversations invoking each tool at least once

至少调用过一次各工具的 Agent 对话占比

Most commonly invoked tools

最常调用的工具

Share of agent conversations invoking each tool at least once

至少调用过一次各工具的 Agent 对话占比

Ultimately, we kept the high-frequency tools for reading, searching, editing, and using the shell in static context. We also retained ask_question, which some models tended to hallucinate calls for, and tools that are crucial to specific product flows, such as create_plan in Plan Mode. The remaining tools now load when the agent needs them.

最终,我们将用于读取、搜索、编辑和使用 Shell 的高频工具保留在静态上下文中。我们还保留了 ask_question,因为某些模型倾向于幻觉出对该工具的调用,以及那些对特定产品流程至关重要的工具,例如 Plan Mode 中的 create_plan。其余工具现在会在 Agent 需要时加载。

Offloading built-in tools cut static-context description tokens by 60%

卸载内置工具使静态上下文描述 Token 减少了 60%

  • Kept in static context
  • Offloaded to dynamic context
  • 保留在静态上下文中
  • 卸载到动态上下文

Offloading built-in tools cut static-context description tokens by 60%

卸载内置工具使静态上下文描述 Token 减少了 60%

  • Kept in static context
  • Offloaded to dynamic context
  • 保留在静态上下文中
  • 卸载到动态上下文

Offloading built-in tools cut static-context description tokens by 60%

卸载内置工具使静态上下文描述 Token 减少了 60%

  • Kept in static context
  • Offloaded to dynamic context
  • 保留在静态上下文中
  • 卸载到动态上下文

#Improving cache reuse

#提高缓存复用率

After reducing the amount of static context in each request, we improved how effectively repeated context could be cached across turns.

在减少每个请求中的静态上下文量之后,我们提高了跨轮次重复上下文缓存的有效性。

Every agent turn resends a long request containing tools, system instructions, setup, and the conversation so far. Much of the beginning stays the same from one turn to the next, while the conversation at the end continues to grow.

每个 Agent 回合都会重新发送一个包含工具、系统指令、配置以及迄今为止对话的长请求。从一轮到下一轮,请求开头的大部分部分保持不变,而结尾的对话则持续增长。

Prompt caching allows the model provider to reuse that unchanged prefix. However, caching configurability can vary by provider. Before GPT-5.6, the cache boundary was determined automatically based on the latest request. Even though tools and system instructions rarely changed, they were not cleanly marked as reusable on their own.

提示词缓存(Prompt caching)允许模型提供商重用那些未改变的公共前缀。然而,不同提供商在缓存的可配置性上可能存在差异。在 GPT-5.6 之前,缓存边界是根据最新请求自动确定的。尽管工具和系统指令很少发生变化,但它们并未被清晰地标记为可独立复用的内容。

Since GPT-5.6, the OpenAI API allows clients to mark explicit cache breakpoints alongside its default implicit caching. We now place breakpoints after stable layers of the request and before the growing conversation, allowing later turns to reuse more of the unchanged prefix.

自 GPT-5.6 起,OpenAI API 允许客户端在其默认隐式缓存的基础上标记显式的缓存断点。我们现在将断点放置在请求的稳定层之后、增长的对话之前,从而允许后续回合复用更多未改变的前缀内容。

Breakpoints only help if the prefix itself stays stable, so we also tightened what sits at the front of each request. We did this by reserving tools and system instructions for content that rarely changes, and by moving more variable setup past the cache boundaries into our "phantom user message." This holds user- and request-specific context like skills, subagents, and environment info.

只有当请求前缀本身保持稳定时,断点才能发挥作用,因此我们也收紧了每个请求前端的内容构成。我们通过将工具和系统指令保留给极少变化的内容来实现这一点,并将更多可变配置移至缓存边界之外,放入我们的“虚拟用户消息”中。这保留了用户和请求特定的上下文,如技能、子代理和环境信息。

These changes reduced the rate of cold cache misses by 20%.

这些变化使冷缓存未命中率降低了 20%。

#Compressing file reads

#压缩文件读取

Another large source of token spend is the context an agent adds as it works, much of which comes from reading files.

Token 消耗的另一个主要来源是 Agent 在工作过程中添加的上下文,其中大部分来自读取文件。

Cursor's agent reads files through a Read tool, which traditionally numbered every line because models are not good at counting lines on their own and need to cite specific sections for the user.

Cursor 的 Agent 通过 Read 工具读取文件,该工具传统上会对每一行进行编号,因为模型自身不擅长计数行数,且需要为用户引用特定部分。

A single line number uses only around three to five tokens, but when an agent reads tens of thousands of lines during a session, numbering every one adds a meaningful amount of context.

单个行号仅占用大约三到五个 Token,但当 Agent 在一次会话中读取数万行代码时,对每一行进行编号会显著增加上下文的开销。

We reduced that overhead by including line numbers only on every tenth line. This is still frequent enough for models to cite code properly, and the change reduced cache-read tokens by 1.6% with no reduction in quality.

我们通过在每第十行才包含行号来减少这种开销。这对于模型正确引用代码仍然足够频繁,且此次更改使缓存读取 Token 减少了 1.6%,同时质量没有下降。

#Using subagents strategically

#战略性地使用子代理

Longer agent runs create more opportunities to delegate work to subagents. This can reduce token spend because each subagent typically starts with a fresh context window rather than carrying the parent agent's full conversation. Once it reports its results, the parent can continue without carrying the subagent's full working context.

更长的 Agent 运行周期创造了更多将工作委派给子代理的机会。这可以减少 Token 消耗,因为每个子代理通常以全新的上下文窗口开始,而不是携带父代理的完整对话历史。一旦子代理报告其结果,父代理即可在不携带子代理完整工作上下文的情况下继续执行。

This kind of context isolation between agents and subagents does carry a coordination tax, though, because agents that do not share context can duplicate work or pursue tasks that are no longer necessary.

尽管代理(agents)与子代理(subagents)之间的这种上下文隔离确实会带来协调成本,因为不共享上下文的代理可能会重复工作,或执行已不再必要的任务。

We made two changes to capture the efficiency benefits without adding unnecessary coordination. First, we removed instructions that strongly encouraged agents to use subagents for codebase exploration. As subagents became more prevalent in training data and researchers incorporated them into post-training, models learned this pattern natively. Removing the extra prompting produced more balanced subagent usage.

我们进行了两项更改,以在不增加不必要协调的情况下捕获效率收益。首先,我们移除了强烈鼓励代理使用子代理进行代码库探索的指令。随着子代理在训练数据中变得更加普遍,且研究人员将其纳入后训练阶段,模型原生地学会了这一模式。移除额外的提示词产生了更平衡的子代理使用情况。

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

关联讨论

同一事件的更多信源

相似阅读

关联信息,但可能不是同一事件