跳转到主要内容

Agent 的时钟是成本输入:按墙钟时间调度长时运行

Agent 成本模型只对 token 和交接计价,却忽略了墙钟占用——在长时程运行下,真正约束共享执行器的资源。

Token 成本只是账本的一半

大多数关于 agent 成本的讨论都收敛到同一个单位:token。按轨迹做预算、支出看板,以及当前大型组织内部为控制 agent 支出而推出的一波项目,统计的都是 token,或 token 所对应的金额。这是一个合理的初步近似。token 由提供商计量,能干净地映射到账单,也容易归因到某个步骤、某次工具调用或某个子 agent。

一旦 agent 是长时程的、执行器是共享的,这个近似就失效了。一次运行在等待慢速工具时处于空闲——网页抓取、数据库迁移、沙箱构建、人工审批关卡——它仍然占着一个调度槽位。等待期间它不消耗 token,可能几分钟都不消耗 token。但它占用的槽位无法交给另一条轨迹,而这个槽位正是共享执行器上的稀缺资源。

这就是缺口所在。token 核算对占用是盲的,因为占用不是 token 事件。一个在两次检查之间休眠的轮询循环,在 token 账本里看起来几乎免费:每次轮询几个输入 token,没有值得计数的输出。而在调度器视角下,同一个循环是一个在整个等待期间钉住容量的进程。成本是真实的,只是以账本不追踪的货币支付。

交接也有同样的问题,只是形式更隐蔽。当规划者委派给工作者时,核算通常记录了双方的 token 以及它们之间的序列化成本。它很少记录这样一个事实:规划者的上下文在整个工作者执行期间一直保持打开、槽位被预留。在带扇出的多 agent 集群中,这会叠加:一个协调者等待多个子任务时占着一个槽位,同时其他几个在运行,而这段等待是不可见的。

把占用作为一等字段

修复从 harness 开始。每条步骤记录都应在 token 计数之外携带延迟和槽位持有时间。不是事后从日志推导出的指标,而是在调度时写入的字段,这样一次运行的记录就是两种货币的记录。

一条最小的每步记录如下:

{
  "step_id": "s-014",
  "agent": "retriever",
  "tokens_in": 1840,
  "tokens_out": 212,
  "tool": "http_fetch",
  "tool_latency_ms": 9400,
  "slot_acquired_at": "...",
  "slot_released_at": "...",
  "slot_seconds": 11.2,
  "wait_reason": "tool"
}

wait_reason 字段比看起来更重要。它区分了花在计算上的时间与花在等待工具、等待锁、等待对等 agent 或等待人工上的时间。每一种都有不同的补救方式:慢速工具需要缓存,或更短的超时加回退;锁需要更窄的临界区;对等等待需要不同的扇出拓扑。不附带原因,占用就是一个没人能据以行动的数字。

在轮询之间休眠的长时程 agent 是典型的罪魁祸首。这个模式通常是防御性的:每三十秒轮询一次任务直到完成,并设置宽松的尝试上限。轮询的 token 成本可以忽略。占用成本则是任务的整个墙钟时长,再乘以做同样事情的轨迹数量。在负载下,正是这一点把一个按 token 看很便宜的系统变成了会排队的系统。

因此调度器需要的是每次运行声明的最大占用,而不是默认超时。超时说“如果太久就杀掉它”;它不说“这次运行在其生命周期内最多有权使用 N 个槽位秒”。前者是安全阀。后者是预算,而预算才使调度决策成为可能。声明了大占用预算的运行可以排在较短的运行之后;声明了小占用预算的运行可以立即准入。没有声明,每次运行都被视为可能无界,调度器就无从推理。

这里有一个诚实的权衡。声明占用预算迫使你在运行开始前就知道或猜测它会持续多久。长时程 agent 恰恰是持续时间最难预测的,因为它取决于工具返回什么。实际的解决办法是按粗粒度区间声明预算,而不是精确数字,并把超出区间视为值得记录的信号,而不是硬失败。声明首先是调度提示,其次才是执行机制。

设计规则:用两种货币做预算

一旦记录了占用,设计规则就随之而来:用两种货币做预算,token 和槽位秒,各自有独立上限。它们不可互换,也不应合并成一个数字。一次运行可以 token 便宜而占用昂贵,或者相反。把它们合并,恰恰会掩盖你最想看到的那些回归。

二阶后果是:便宜的执行器模型只有在槽位被释放时才能降低成本。小模型路由——把分类、抽取或格式化步骤交给更小的模型——是真正的 token 节省。但如果被路由的步骤仍然持有槽位同样长的时间,因为瓶颈是工具调用或锁而不是推理,那么占用成本不变。节省是真实的,但只是部分的,而只统计 token 的成本模型会高估它。关于路由变更的正确问题不只是“我们省了多少 token”,而是“槽位是否更早释放了,如果没有,为什么”。

同样的逻辑适用于并发。给集群增加工作者只有在瓶颈是槽位可用性而非共享依赖时才能提高吞吐。如果每个工作者都争抢同一把锁或同一个限流工具,更多工作者意味着每单位有用输出的占用更多。双货币预算让这一点可见:每条轨迹的 token 支出可能下降,而每个完成任务的槽位秒上升,而第二个数字才决定系统能否扩展。

一个具体的机制,在调度器层面:

  • 每次运行在准入时声明一个 token 上限和一个槽位秒上限。
  • 调度器按剩余槽位容量准入运行,而不只是按队列深度。
  • 等待外部资源的步骤释放槽位,并在完成时重新入队,而不是在整个等待期间持有它。
  • harness 把两个计数器写入运行报告,按步骤和汇总。

第三点是需要工程投入的那一点,因为运行中途释放槽位意味着运行状态必须足够持久以便恢复。这是真实的成本,对于短运行不值得支付。对于长时程运行通常值得,因为替代方案是一个无法区分运行在做工作还是在做空转的调度器。

在 harness 报告中公布占用

只有当报告同时显示两种货币,成本回归才能被归因。如果 harness 报告只列出每步 token 而没有别的,那么端到端延迟翻倍就没有对应条目,每次调查都从零开始。把占用与 token 并列公布——按步骤、按运行、按集群中的每个 agent——就把一项不可见的成本变成了可以跨版本追踪的数字。

The report should make three things easy to see: which steps held the slot longest, which of those were waiting rather than computing, and how occupancy per completed task moved between versions. The first two are diagnostic; the third is the one that belongs on the same page as token spend, because it is the one that tells you whether the system is getting cheaper or merely getting quieter.

None of this argues that tokens do not matter. They are the metered, billable, externally visible cost, and they deserve their budget. The argument is that on a shared executor under long-horizon runs, wall-clock occupancy is the binding constraint, and a cost model that does not price it will keep producing systems that look efficient in the ledger and queue in production.

The Clock as a Cost Input

The reframing is small and consequential: the agent's clock is a cost input, not an operational afterthought. Tokens measure what the model consumed. Slot-seconds measure what the system could not do elsewhere while the run was in flight. Both are costs, both are attributable, and only one of them is currently on the invoice.

Teams that instrument occupancy early get a scheduler that can make admission decisions on evidence, a harness report that explains latency regressions, and a routing strategy that knows the difference between saving tokens and saving time. Teams that do not will keep discovering, under load, that the cheap run was never cheap.

分享XLinkedIn永久链接7 分钟阅读

这能回答的问题

Why is wall-clock occupancy missing from most agent cost models?

Because token counts are metered by the provider and map directly to a bill, while occupancy is not a token event. A run waiting on a slow tool consumes almost no tokens but still holds a scheduler slot, so the cost is real but unpaid in the ledger.

What is a slot-second budget?

A declared cap on how much scheduler occupancy a run may consume over its lifetime, set alongside a token cap at admission. It lets the scheduler admit runs against remaining capacity rather than queue depth, and treats exceeding the band as a signal rather than a hard failure.

Do cheap executor models always reduce agent cost?

Only if the slot is released sooner. Small-model routing saves tokens, but if the bottleneck was a tool call or a lock rather than inference, occupancy is unchanged and the saving is partial. The right question is whether the slot was freed, not just how many tokens were saved.