I measured one AI agent session token by token. 5 of 20 turns ate 94% of the cost.
Описание и применение
Автор измерил токен‑затраты одного сеанса 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