Quadratic Cost from Growing Context Windows

AI agents frequently re-send the entire conversation history, tool outputs, and other state information with each step, causing the context window to grow quadratically. This means a token written at turn 1 of a 30-turn run gets billed 30 times, making re-reading the primary cost at scale.

The top 3

  1. Transformer's Self-Attention: Quadratic Cost Originator: The core self-attention mechanism within Transformer models, essential for understanding context, directly causes the quadratic scaling of computational cost and memory with increasing context window size.
  2. Quadratic Cost vs. Linear: Resource Explosion: Doubling an AI agent's context window length can quadruple computational and memory costs due to quadratic scaling, making it significantly more resource-intensive than operations with linear scaling for large inputs.
  3. Top 3 Mitigation Strategies for Quadratic Costs: Leading approaches to reduce quadratic costs include sparse attention, which limits token interactions; retrieval-augmented generation (RAG), which retrieves relevant information; and state-space models (SSMs) like Mamba, which use recurrent mechanisms for linear scaling.

Sources

Open the full topic