A 1M-token window is a ceiling, not a working size. Set the budget yourself, or the model will set it for you by quietly dropping things.
- Chroma tested 18 models, including GPT-4.1, Claude Opus 4 and Gemini 2.5, and found accuracy fell as input grew even on simple tasks.
- Stanford's Lost in the Middle study found models use facts at the start and end of a prompt better than facts buried in the center.
- A workable budget splits the window into four fixed lines: system prompt, retrieved documents, conversation history and an output reserve.
- Treat 30 to 50 percent of the advertised window as a starting ceiling, then move it up or down only after testing your own tasks.
- Count tokens per bucket on every request and alert when any bucket passes 90 percent of its cap.
If you want to know how to manage LLM context window budget, start with a number the model card doesn't print: the length at which your model begins to get things wrong. It's almost never the advertised limit. A model sold with a 1 million token window can accept that much text without throwing an error, but accepting text and using it are different jobs, and the second one gets worse long before the first one fails.
Teams find this out late. Answers get a little vaguer. A rule from the system prompt is ignored on turn 40. A clause in a retrieved contract goes unmentioned. Nobody can say why, because nothing crashed and no log line turned red.
The fix is dull and it works. Treat the window like a budget with fixed lines, set a working ceiling well under the advertised one, and enforce both in code rather than in a team wiki.
The term has a paper trail. In 2025 the vector database company Chroma published a study it called Context Rot, testing 18 models, among them GPT-4.1, Claude Opus 4 and Gemini 2.5. The headline finding was blunt: performance dropped as input length grew, even on tasks that were deliberately simple, such as repeating a string of words back. If a model slips on that, it will slip on your contract review.
How to Set Token Budget Per Task for AI Agents Before Costs Spiral
A 200,000-token budget can be split into six slices, with 35% or 70,000 tokens going to tool output. Capping results at about 3,000 tokens turns a 220,000-token bill for one page carried through 11 calls into 33,000 tokens. - how to set AI agent token budgets - prevent runaway AI agent token costs
Chroma also found that distractors hurt. Passages that looked relevant but weren't made the models worse, and the damage grew as the prompt got longer. That matters for anyone stuffing a retrieval pipeline with the top 50 chunks instead of the top 5, because every near-miss paragraph you add is a distractor in waiting.
Position matters too. A Stanford-led team (Nelson Liu and colleagues) showed in the paper Lost in the Middle that models answer best when the relevant passage sits at the very start or very end of the input, and worst when it's in the middle. Plot it and you get a U shape. Put your most important document in slot 15 of 30 and you've picked the weakest seat.
Nvidia's RULER benchmark, released in 2024, went after the marketing directly. Its authors found that of the models claiming a context of 32K tokens or more, only about half held up at 32K on their tougher tasks. The claimed limit and the usable limit were different numbers.
Anthropic has taken the same view in its own guidance. Its engineering post on context for agents describes context as a finite resource with diminishing returns, and uses the phrase context rot itself. When a model's maker tells you to ration the window, you ration the window.
How much context should I put in an LLM prompt
Less than the window allows, and less than you'd guess. There's no published standard for the right fraction, and anyone who gives you one number for every model is selling something. A sensible starting point is 30 to 50 percent of the advertised window for tasks that need reasoning across several passages, and you can go higher for plain lookups where the model only has to find one fact.
Frankly, the needle-in-a-haystack charts vendors like to show are the weakest evidence here. They test whether a model can find one planted sentence, which is the easy case. Your task probably asks the model to compare two documents, follow a long instruction set, or keep a persona steady across a long chat. That's the harder case, and it's the one Chroma and RULER suggest breaks first.
Cost is a second reason to hold back. You pay for every input token on every call, and a long prompt also takes longer to process before the first output token appears. A prompt that is 80 percent filler is slower and pricier and less accurate. That's a rare triple loss.
How Context Window Length Actually Breaks Your AI Agent's Unit Economics
How does context window length affect inference cost? Not linearly. Attention scales roughly with the square of context length, and the KV cache adds a growing memory tax on top, which is exactly where AI agent unit economics quietly fall apart. - how context window size affects AI agent costs - why large language model context breaks unit economics
Four buckets, fixed in advance
Here's a concrete split for a model with a 200,000 token window. Set the working ceiling at 80,000 tokens, which is 40 percent. Leave the other 120,000 as headroom you never plan to fill. Inside the 80,000, assign four lines: 5,000 for the system prompt, 40,000 for retrieved documents, 25,000 for conversation history, and 10,000 for output.
Those numbers are an example, not a recommendation to copy. A coding agent will want a bigger history bucket and a smaller document bucket, and a support bot answering from a help center will want the reverse. What matters is that each line has a number, the number lives in a config file, and the code checks it before every request.
The system prompt. This is the bucket that grows without anyone deciding to grow it. Every incident adds a rule, nobody deletes one, and a year later you have 9,000 tokens of instructions that contradict each other. Cap it. When it hits the cap, something has to leave before something else enters. Run an ablation now and then: remove a rule, run your test set, and see if the score moves. Many rules turn out to be dead weight.
Keep this prefix stable and put it first. Both Anthropic and OpenAI offer prompt caching for repeated prefixes, which cuts the cost and delay of resending the same instructions, and a prompt that changes every turn can't use it.
Retrieved documents. This is the biggest line and the one with the most waste. The cap is a ceiling and not a target. If your reranker says three chunks are relevant and the other 20 are noise, send three. Deduplicate near-identical passages before they reach the prompt, since Chroma's distractor result says repeated near-matches cost you accuracy.
Order the chunks deliberately. Put the strongest at the top and the second strongest at the bottom, and let the weaker ones sit in the middle, where the Lost in the Middle curve says the model pays least attention anyway. Label each chunk with its source and date so the model can say where an answer came from.
Conversation history. Long chats are where context rot usually starts, because history only ever grows. Keep the last handful of turns word for word, and replace everything older with a running summary that you regenerate when the bucket fills. Pin the few facts that must survive, such as the user's goal, their constraints and any decision already made, in a separate short block that never gets summarized away.
Tool output is the worst offender in agent setups. A single web page or log dump can eat 15,000 tokens, and it's useless two steps later. Anthropic's context-engineering guidance names clearing old tool results as one of the safest, lightest forms of compaction. Do that before you touch anything else.
Output reserve. Output tokens count against the window, which people forget until a long answer gets cut off mid-sentence. If you use a reasoning model, the thinking tokens usually count too, so a 10,000 token reserve can vanish into reasoning before the visible answer starts. Size this line from the longest answer you actually want, then add the reasoning budget on top. Never borrow from it to fit one more document.
When a bucket overflows
It will overflow. Decide the order of cuts now, not at 2 a.m. during an outage. History goes first, through summarization. The tail of the retrieved documents goes second, starting with the lowest ranked. The system prompt is cut only by a human editing it. The output reserve is never touched.
Count tokens with the provider's own counter, not by dividing characters by four. Tokenizers differ between models, and code, tables and non-English text all produce far more tokens per character than plain English prose does. A budget measured in characters is a guess, and it'll be wrong in the direction that hurts.
Log the count for each bucket on every request. A dashboard that shows the four lines over time will tell you things no one reports in a meeting: that the history bucket doubled after the last release, or that one customer's documents are three times the average. Set an alert at 90 percent of any cap. When it fires, you've caught a problem while it's still a configuration change.
Don't skip the boring alternative either. If you keep hitting caps, the answer may be a smaller task, not a bigger window. Split a long analysis into stages, let each stage see only what it needs, and pass a short written handoff between them. Several short, focused calls often beat one enormous one, and each is easier to debug.
Find your own ceiling
Published numbers tell you where to look. They can't tell you where your workload breaks. Take 50 real tasks with known good answers, and run them with the same relevant material padded out with realistic filler at 10,000, 25,000, 50,000 and 100,000 tokens. Score each run. The point where accuracy falls by more than a few points is your ceiling, and you set the budget a notch below it.
Run a second test on position. Take the passage that holds the answer and move it from the start to the middle to the end, and compare scores. If the middle seat loses 10 points, you've learned how much your document ordering matters, and you've learned it from your own data instead of a paper.
Then do it again. A model upgrade can move the ceiling in either direction, and a longer advertised window doesn't promise a higher usable one. RULER found exactly that gap between claimed and effective length, and newer models have been built with it in mind, but you shouldn't take that on trust. Write the tested ceiling, the model version and the test date into the same config file that holds your four caps, so the next person who reads it knows how old the number is.
Also read: How to Set Token Budget Per Task for AI Agents Before Costs Spiral • How to Recognize Revenue From Prepaid AI Credits Before Your Audit • How to Reduce MCP Tool Definitions Token Usage Before Your Agent Starts
This article is posted in AI News, check it out for more related stories.
Join the discussion
Almost there. Sign in and your reply posts straight away.
原文来源:startupfortune.com