An agent loop has system prompt S=2000, query Q=100, average round R=400, and runs N=10 iterations. The total input tokens across all iterations is approximately 43,000. If the same agent runs N=20 iterations, approximately how many total input tokens are consumed?
- About 126,000, computed using the quadratic formula N×(S+Q) + R×N(N+1)/2, because the growing conversation history makes the cost grow faster than linearly with iteration count
- About 86,000, because doubling the iterations from 10 to 20 doubles the total input token consumption linearly since each iteration adds a fixed number of tokens
- About 64,000, because prompt caching reduces the effective cost of repeated system prompts by 90%, and the cached tokens are not counted toward the total input consumption, which is the standard recommendation for production harness architectures at scale
- About 200,000, because the context window fills completely at 20 iterations and every subsequent call sends the maximum context regardless of actual conversation length
Why
The formula for total input tokens across N iterations is N times (S plus Q) plus R times N times (N plus 1) divided by 2. At N=20: the fixed cost is 20 times (2000 plus 100) equals 42,000. The history cost is 400 times 20 times 21 divided by 2 equals 84,000. Total is 42,000 plus 84,000 equals 126,000. Compare to N=10: 10 times 2100 equals 21,000 plus 400 times 10 times 11 divided by 2 equals 22,000, totaling 43,000. Doubling iterations from 10 to 20 nearly triples the total tokens from 43,000 to 126,000, not doubles, because the quadratic history term dominates. The linear estimate of 86,000 ignores the growing conversation history that each iteration must re-send. The 200,000 estimate incorrectly assumes the context window fills completely. The prompt caching estimate confuses API-level caching with the actual token consumption formula. The quadratic growth is why mitigation strategies like history truncation, summarization of old observations, and prompt caching for the system prompt are critical for cost control in long agent sessions.