Best Practices for Managing an Agent's Token Budget
The first rule of token budgeting is to keep the system prompt as lean as it can be. A system prompt is paid on every single request, forever, so a bloated prompt quietly taxes every turn of every session. Audit it regularly: move long instructions into files or tool descriptions, compress multi-page style guides into terse rules, and delete content that no longer affects behaviour. Aim for a system prompt small enough that the conversation and memory have room to grow without chasing the model's ceiling.
Reserve output headroom on purpose, never as an afterthought. The matrix defaults to 2,048 reserved tokens because that covers a substantial structured reply with tool-calling JSON, but the right number depends on your workload. A summarisation agent needs more room for long extracts, while a classification agent that returns one word needs very little. Whatever you choose, budget it explicitly so the input side of the window can never silently crowd out the model's ability to answer.
Size RAG chunks for the window, not for the embedder. Retrieval pipelines are often tuned for embedding quality and recall, with chunk sizes chosen for vector search, while the number of chunks injected per request is an afterthought. The matrix makes the injection cost visible: six 1,000-token chunks are 6,000 tokens of every request. Practice is to size chunks around 250 to 500 tokens and to cap injected content by relevance score, injecting three or four tight chunks instead of ten loose ones.
Measure the averages that feed the conversation estimate. The matrix multiplies average user and assistant tokens by turn count, so using realistic averages is the difference between a useful plan and a fantasy. Sample ten real conversations, count the tokens, and average them. If your users paste long documents or your agent writes verbose reports, the true average will be higher than intuition suggests, and you want the budget built on the real number.
Build compaction into the design before the first warning fires. A healthy agent needs a policy for what happens at turn 40 in a long session: summarize the early exchange into a compact memory entry, drop tool-call noise, or trim the least relevant retrieved chunks. The matrix's long-conversation warning exists precisely to prompt this policy. Agents that lack one degrade gracefully into incoherence, losing the beginning of the conversation while the window fills with repetition.
Match the model to the mission. A million-token model is not automatically better; it costs more, runs slower, and can even make attention worse on huge inputs. Use the matrix to compare the same workload across models: if your projected request is 30,000 tokens, a 128K model with better reasoning beats a 1M model every time. Reserve the giant windows for workloads that genuinely need them, such as long-document analysis, and let the budget justify the model choice rather than habit.
Inspect the distribution, not just the average, of your token usage. Some sessions end in three turns; some run to sixty. A budget tuned to the mean will overflow on the tail, which is exactly where the expensive failures happen. Model the worst plausible session, the longest conversation with the largest retrieval, and check that configuration against the window. If the worst case overflows, the design is not done.
Treat memory content as a managed asset with an eviction policy. Long-term memory grows without bound unless something removes it, and stale entries consume budget while adding noise. Implement relevance-based retention: keep entries that have been useful, compress summaries as they age, and archive or drop entries older than a threshold. The matrix's memory-dominance warning flags when retrieval is eating more than half the budget, which is usually a sign the eviction policy has stopped working.
Keep tool-calling responses tight. Agents that emit verbose JSON, duplicate tool arguments, or log intermediate reasoning into the conversation inflate the assistant-side token average quickly. Instruct the model, via the system prompt, to return only necessary fields and to avoid echoing content. Over the course of a long session, small per-reply savings compound into thousands of tokens of preserved headroom.
Finally, re-baseline the budget whenever anything changes. A new model with a different context size, a redesigned prompt, a bigger retrieval library, or a new average reply length all change the math. Run the matrix after each change, compare the utilization before and after, and adjust the design. The discipline of re-baselining is cheap, and it is the reason teams with a budgeting habit so rarely meet a context-overflow incident in production.