跳到主内容
精选88Avi Chawla技巧与观点

图解受限 LLM Agent:如何省下近 3 倍 Token

A harnessed LLM agent, clearly explained!

原文
推荐理由

做 Agent 工程的同学必看,这篇把 Token 浪费的根源和优化手段讲透了,还附了开源实现和 benchmark 数据,赶紧对照自己的 harness 排查一遍。

A harnessed LLM agent, clearly explained!

一个被套上缰绳的LLM代理,清晰解释!

Two agents can run the same model on the same task and finish as expected. But one of them can spend nearly 3x the tokens to complete the task.

两个代理可以在同一任务上运行同一模型并按预期完成。但其中一个可能花费近3倍的令牌来完成任务。

The extra usage originates from the code wrapped around them, which decides what reaches the model's context on each call and how many calls there are.

额外使用量源于包裹它们的代码,这决定了每次调用时哪些内容进入模型的上下文,以及有多少次调用。

For instance, consider a tool that returned 50k tokens of JSON at some step. If it stays in the context, the model will continue to read that payload again at every subsequent step.

例如,考虑一个工具在某个步骤返回了50k令牌的JSON。如果它留在上下文中,模型将在后续每个步骤继续读取该负载。

Tool definitions behave the same way.

工具定义的行为方式相同。

A server can expose 50 tools, each with a name, a description, and an input and output schema.

服务器可以暴露50个工具,每个都有名称、描述以及输入和输出模式。

By default, all of them will stay in the prompt from the first call, whether the agent uses them or not.

默认情况下,从第一次调用开始,所有这些都会留在提示中,无论代理是否使用它们。

However, an optimally built harness can avoid that unnecessary cognitive load on the model.

然而,一个优化构建的缰绳可以避免模型承受这种不必要的认知负担。

More specifically, one core design principle of harness engineering is to push things out of the model at the right time:

更具体地说,缰绳工程的一个核心设计原则是在正确的时间将内容推出模型:

  • Memory holds the state that weights and context shouldn't carry. - Skills hold procedural knowledge. These cover the operating procedures and heuristics that specialize a general model. - Protocols hold the interaction contracts for users, other agents, and tools.
  • 记忆保存权重和上下文不应携带的状态。 - 技能保存程序性知识。这些涵盖操作程序和启发式方法,使通用模型专业化。 - 协议保存用户、其他代理和工具的交互契约。

Do note that the context never disappears permanently.

请注意,上下文永远不会永久消失。

It is always loaded when needed, and the harness decides how much is loaded and when.

它总是在需要时加载,缰绳决定加载多少以及何时加载。

For instance, to manage a 50k token payload, a harness can write it to a file and keep a preview and a path in context, hand the work to a subagent whose context is discarded afterwards, or summarize the older messages once the conversation passes a threshold.

例如,为了管理50k令牌的负载,缰绳可以将其写入文件并在上下文中保留预览和路径,将工作交给子代理(其上下文随后被丢弃),或者在对话超过阈值后总结旧消息。

If you want to see this in practice, TrueForge is an open-source harness that already implements these practices.

如果你想看到实际应用,TrueForge是一个开源缰绳,已经实现了这些实践。

Tool schemas are deferred unless preloading is switched on, large responses go to a sandbox file, and generated code calls tools back through the harness, so the sandbox never holds the credentials.

工具模式被延迟,除非启用预加载,大型响应进入沙箱文件,生成的代码通过缰绳回调工具,因此沙箱永远不会持有凭据。

The two agents I talked about at the top are from DevRev's Enterprise-Bench. TrueForge solved the same number of tasks as Claude Managed Agents on the same model, using a bit over a third of the tokens and around 40% fewer tool calls.

我在开头提到的两个代理来自DevRev的Enterprise-Bench。TrueForge在同一模型上解决了与Claude托管代理相同数量的任务,使用的令牌略多于三分之一,工具调用减少了约40%。

Here's the GitHub repo: http://github.com/truefoundry/trueforge

这里是GitHub仓库:http://github.com/truefoundry/trueforge

(don't forget to star it ⭐ )

(别忘了给它加星标⭐)

I also wrote a full breakdown of where agent tokens actually go inside a run, covering context accounting, the strategies above, and the benchmark in detail, and TrueForge worked with me to put this together.

我还写了一篇关于代理令牌在运行中实际去向的完整分析,涵盖上下文核算、上述策略以及基准测试的详细信息,TrueForge与我合作完成了这篇内容。

Read it below.

在下面阅读。

更进一步:量化金融体系

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

进入量化体系 →

相似阅读

另一事件,读法相近