I measured one AI agent session token by token. 5 of 20 turns ate 94% of the cost.
Description and use
The author measured token costs in a single 20‑turn AI agent session, finding that 25 % of turns consumed 94 % of cache‑write cost due to tool list changes that invalidated cached prefixes. Recommendations: disable unused tools and stabilize the tool list.
Problem
AI agents incur high costs per turn, but the distribution of token usage is unclear.
Outcome
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.
Workflow
- 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.
Evidence
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.
- Record date: 2026-10-22T23:11:26.865Z