A browsing agent runs on a model with a 32,000 token context window. You reserve 4,000 tokens for the model's output. The system prompt is 1,000 tokens, the accumulated text history is 7,000 tokens, and the conversation already contains 4 screenshots at about 1,500 tokens each. Every additional screenshot also costs about 1,500 tokens, and assume the text history stays flat. Predict how many MORE screenshots fit before the request overflows the window.
Input budget is 28,000 after the 4,000 output reservation. Used: 14,000 (system plus text plus four screenshots). Remaining 14,000 divided by 1,500 per screenshot, taking the floor, gives 9 more screenshots.
Imagine a small backpack that holds 32 pounds, but you must keep 4 pounds empty for snacks on the way home. That leaves 28 pounds. You already carry a 1-pound map, 7 pounds of notes, and four 1.5-pound rocks (6 pounds of rocks). That is 14 pounds. You have 14 pounds free. Each new rock weighs 1.5 pounds. You can fit nine more rocks (13.5 pounds), but a tenth rock would push past 28. The trick is to subtract the snack reservation first, then count whole rocks only, since half a rock falling out of the bag does not count.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Context-budget arithmetic for an agent loop is one of those topics where the obvious answer is correct but the operational discipline is what separates a working agent from one that 429s the moment a task gets interesting. The numbers in this question are simple by design; the lesson is in how you structure the computation and what you do when the budget runs out.
This deep dive walks through the calculation, the per-step invariant pattern, and the eviction policies that real production agents use.
The calculation in one pass
Start from the total window and subtract every commitment.
- Total context window: 32,000 tokens.
- Output reservation: subtract 4,000. Input budget is now 28,000.
- System prompt: subtract 1,000. Remaining: 27,000.
- Text history: subtract 7,000. Remaining: 20,000.
- Existing screenshots (4 at 1,500): subtract 6,000. Remaining: 14,000.
Now divide by per-screenshot cost: floor(14000 / 1500) = floor(9.33) = 9. Nine more screenshots fit. A tenth would require 15,000 tokens, overflowing the budget by 1,000.
The four-step shape (subtract output reservation, subtract overhead, subtract existing variable content, divide remaining by per-item cost) is the same regardless of what the variable items are: images, RAG chunks, retrieved documents, tool-call results. Internalize the shape and the specifics fall out.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- Anthropic's computer-use reference for Claude Opus 4.7 explicitly tracks a sliding window of recent screenshots and drops older ones once budget pressure builds
- OpenAI's GPT-5.5 computer-use agent product enforces image limits per request and surfaces token-usage metadata on every response so callers can budget
What an interviewer would ask next. Try answering before peeking at the approach.
QHow would you change the calculation if the model auto-summarizes the oldest message when context fills up?
Treat auto-summarization as a fallback, not a primary plan. Estimate the post-summary token count of the oldest screenshot region (often 50 to 200 tokens) and re-run the budget check after summary. Track auto-summarization invocations as a metric; if the agent depends on it, your design has the wrong policy and you should evict explicitly instead.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Forgetting to subtract the output reservation, or dividing by 1500 and rounding up instead of taking the floor; both produce an off-by-one answer that overflows in production.
60 second bullets to scan on the way to the call.
Why output reservation comes off the top before any input math
Why floor division (not ceiling) is correct for whole-image budgeting
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.