The Quadratic Trap Inside Every ReAct / Tool-Calling Loop
In a multi-turn agent, Turn 1 sends the system prompt + user request. Turn 2 resends Turn 1 plus the tool output. By Turn 15, the model re-reads all 14 prior tool payloads—turning linear steps into quadratic O(N²) input token spend.
Why Prompt Caching Alone Is Half the Fix
Prefix caching slashes the cost of re-reading prior turns by up to 90%, yet verbose raw JSON/HTML tool outputs still degrade attention quality and inflate cache writes. Truncating raw tool payloads before appending them to message history compounds caching savings.
Sliding-Window Rolling Summaries for Long Sessions
Capping active message history to the last 4–6 raw turns plus a compact 400-token structured state summary bounds per-turn input tokens flat even on 40-turn autonomous runs.