TokenCast: Forecasting Token Consumption During LLM Agent Execution

📄 arXiv: 2609.35760v1 📥 PDF

作者: Chaoqian Ouyang, Ling Yue, Libin Zheng, Huanghui Guo, Shengxiang Xu, YiShu Wang, Ran Li, Jian Yin, Shaowu Pan, Shimin Di

分类: cs.LG, cs.AI, cs.SE

发布日期: 2026-09-28

🔗 代码/项目: GITHUB


💡 一句话要点

提出TokenCast以解决LLM代理执行中的令牌消耗预测问题

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 大型语言模型 令牌消耗 动态预测 资源管理 执行效率 成本表示 智能系统

📋 核心要点

  1. 现有方法在LLM代理执行中,令牌消耗的预测准确性不足,导致资源浪费。
  2. TokenCast通过学习可组合的成本表示,动态更新令牌消耗预测,提升了预测的准确性。
  3. 实验结果显示,TokenCast在多个任务和模型上显著降低了令牌消耗,提升了执行效率。

📝 摘要(中文)

在大型语言模型(LLM)代理执行相同任务时,令牌消耗可能在不同运行中变化超过一个数量级。代理根据工具反馈和中间结果选择下一步,而不断增长的上下文会逐渐增加每次调用的输入大小。因此,任务的总消耗在执行前难以预测,并且预测必须随着运行的展开而修正。本文提出TokenCast,学习每个执行段的可组合成本表示,记录其自身消耗及引入的上下文增长。通过组合相邻段,获得一个累积估计,捕捉早期段的上下文被后续调用重新读取时产生的额外输入成本。随着执行的展开,新观察证据刷新预测,无需额外的LLM调用,平均每次运行的累积预测时间为32.8毫秒。在4个任务套件和6个代理模型中,TokenCast的平均绝对误差相比最强对比者降低了14.5%。在离线预算控制重放中,TokenCast平均使用的令牌比固定预算策略少21.3%。

🔬 方法详解

问题定义:本文旨在解决在LLM代理执行过程中,令牌消耗预测不准确的问题。现有方法无法有效应对执行中上下文增长带来的挑战,导致资源的浪费和效率低下。

核心思路:TokenCast的核心思想是学习每个执行段的可组合成本表示,记录其消耗及引入的上下文增长。通过组合相邻段,能够动态更新令牌消耗的预测,避免了额外的LLM调用。

技术框架:TokenCast的整体架构包括多个模块:首先是执行段的成本学习模块,其次是上下文增长的记录模块,最后是基于新观察证据的预测更新模块。整个流程通过组合相邻段的成本来实现累积预测。

关键创新:TokenCast的主要创新在于其可组合的成本表示方法,能够动态捕捉上下文增长对令牌消耗的影响。这一方法与传统的固定预算策略相比,能够更灵活地适应不同的执行场景。

关键设计:在设计上,TokenCast采用了特定的损失函数来优化成本预测,并通过实验验证了不同参数设置对模型性能的影响。网络结构上,TokenCast结合了上下文信息和历史消耗数据,以提高预测的准确性。

🖼️ 关键图片

fig_0
img_1
img_2

📊 实验亮点

实验结果表明,TokenCast在96个评估组合中,平均绝对误差相比最强对比者降低了14.5%。在离线预算控制重放中,TokenCast平均使用的令牌比固定预算策略少21.3%,显示出其在资源利用上的显著优势。

🎯 应用场景

TokenCast的研究成果在多个领域具有潜在应用价值,尤其是在需要高效资源管理的自然语言处理任务中。通过准确预测令牌消耗,能够优化LLM代理的执行效率,降低计算成本,提升用户体验。未来,该方法还可以扩展到其他需要动态资源分配的智能系统中。

📄 摘要(原文)

When a large language model (LLM) agent executes the same task, token consumption can vary by over an order of magnitude across runs. The agent chooses its next steps based on tool feedback and intermediate results, while the growing context steadily inflates the input size of every subsequent call. The total consumption of a task is therefore hard to predict before execution and the prediction must be revised as the run unfolds. In this paper, we propose TokenCast, which learns a composable cost representation for each execution segment, recording its own consumption and the context growth it introduces. Composing adjacent segments yields a cumulative estimate that captures the extra input cost incurred when context from earlier segments is re-read by every later call. As execution unfolds, newly observed evidence refreshes the forecast, requiring no additional LLM calls and incurring a mean cumulative prediction time of 32.8 ms per run on SWE-bench Verified. Across 4 task suites and 6 agent models, TokenCast's mean absolute error reduction against the strongest comparator averages 14.5% over 96 evaluated combinations. In offline budget-control replay, TokenCast uses 21.3% fewer tokens on average than a fixed-budget policy at matched trace completion. The code is available at https://github.com/DEFENSE-SEU/TokenCast.