Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

I measured one AI agent session token by token. 5 of 20 turns ate 94% of the cost.

说明与用途

作者测量了单个20回合 AI 代理会话的令牌成本,发现 25% 的回合占用了 94% 的缓存写入成本,主要是工具列表变化导致缓存前缀失效。建议:禁用未使用的工具并稳定工具列表。

问题

AI agents incur high costs per turn, but the distribution of token usage is unclear.

结果

The analysis showed that 25% of turns accounted for 94% of cache‑write cost, mainly due to tool list changes that invalidated cached prefixes. The per‑turn cost floor was 146k tokens, driven by tools and plugins loaded each turn.

工作流

  • 1. Run an AI agent session with 20 turns.
  • 2. Capture the session transcript.
  • 3. Use a Python script (consumption guard) to parse the transcript and calculate token usage per turn, weighting cache read 0.1x, cache write 2x, output 5x, input 1x.
  • 4. Identify turns with high cache‑write cost and analyze tool list changes.
  • 5. Draw conclusions about cost drivers and recommend stabilizing tool lists.

证据

In a single 20-turn session: Effective (weighted) cost: ~934k tokens. (weighting: cache read 0.1x, cache write 2x, output 5x, input 1x)

来源

5 of the 20 turns (25%) accounted for 94% of all cache-write cost.

来源

The expensive turns weren't the hard ones. They lined up with the tool list changing - an MCP server disconnecting and reconnecting invalidated the cached prefix, so the whole context got rewritten, and a write costs 2x a read.

来源

  • 记录日期: 2026-10-22T23:11:26.865Z