跳到正文
DEV Community· hacksicilian·· 3 小時前AI 評分64

實測一次 AI Agent 會話:20 輪中 5 輪佔 94% 快取寫入成本

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

AI 導讀

作者逐 token 測量一次 20 輪 AI Agent 會話,發現其中 5 輪(25%)佔全部快取寫入成本的 94%。按快取讀取 0.1 倍、快取寫入 2 倍、輸出 5 倍、輸入 1 倍加權後,總成本約 934k tokens,每輪基礎成本為 146k tokens。

正文

hacksicilian

Everyone talks about what AI agents can do. Almost nobody measures what they actually cost.

I run a small fleet of agents. Last week I pointed a simple guard at one session's transcript and read the usage per turn - not estimated, measured. In a single 20-turn session:

  • Effective (weighted) cost: ~934k tokens. (weighting: cache read 0.1x, cache write 2x, output 5x, input 1x)
  • The floor per turn was 146k tokens - what you pay before anyone types anything. That's tools and plugins loaded every turn.
  • 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.

Three takeaways:

  1. Your per-turn floor is probably huge. Disconnect tools and plugins you're not using - you pay for them every single turn.
  2. The cost isn't repeating context, it's losing and rewriting it. Stabilizing your tool list beats shortening prompts.
  3. A "green" you didn't measure isn't green. Measure by effect, on the real run.

Caveat: this is one session, on one setup. Don't generalize my numbers - measure your own. The point is the bill hides this and the transcript doesn't.

I packaged the doctrine, the lane templates, and the consumption guard (a small Python script that reads any session's transcript and prints this breakdown) into a kit: https://spataro1.gumroad.com/l/ghjrgi

How are you measuring your agents' cost? Curious what others are seeing.



來源:DEV Community · dev.to