Context Window Token Budgeting & Progressive Memory Compaction treats the finite LLM context window as scarce RAM managed through strict partition budgeting and automatic memory compaction; the budget allocation matrix partitions total tokens (e.g. 8k/32k) into: Fixed System & Tool Definitions (20%), Dynamic Working Memory (50% for recent detailed tool/thought traces), Output Buffer (20% for generation), and Safety Margin (10%); Progressive Compaction triggers when working memory saturates: 1) Sliding Window Truncation (retaining recent
K turns), 2) Recursive Semantic Summarization (using cheap small LLMs to distill older turns into dense structured state summaries), and 3) Tool Output Pruning (stripping multi-page raw JSON responses down to essential fields while offloading full payloads to vector stores).