Contents

How a Language Model Actually Works

Lesson 31 of 78. Sign in to keep your place.

Module 4 · What the model can see

Budgeting the window, line by line

8 min read

A 128,000-token window, and the 21,440 tokens actually claimedSystem prompt and policy: 1,800Grows by three sentences each time somebody patchesan edge caseTool and function definitions: 2,400Serialised into every request, including the oneasking when the office closesFew-shot examples: 1,200Cheap to add, rarely revisited, occasionallycontradicting the system promptRetrieved documents, six at 700: 4,200Six good passages beat forty mediocre ones, and notonly on priceConversation history, 18 turns: 9,600Nearly half the input alreadyThe current user message: 240The only part a person actually wroteReserved for the response: 2,000Input and output share the window; unreserved, thereply is cut off mid-sentenceThis application is nowhere near its limit, so a bigger window would fix nothing it has wrong. Thepressure will come from history, which is the only line that grows every turn, and the line nobody hasever examined is the tool definitions.
This application is nowhere near its limit, so a bigger window would fix nothing it has wrong. The pressure will come from history, which is the only line that grows every turn, and the line nobody has ever examined is the tool definitions.

Figure

Write down where it all goes

People discover their context budget when something breaks. It is better to compute it in advance, because every item on the list is a decision somebody made and can unmake.

A realistic assistant with a 128,000-token window:

Text
system prompt and policy               1,800
tool / function definitions            2,400
few-shot examples                      1,200
retrieved documents (6 × 700)          4,200
conversation history (18 turns)        9,600
current user message                     240
------------------------------------------
input                                 19,440
reserved for the response              2,000
------------------------------------------
total                                 21,440   of 128,000

Two things become visible immediately. First, this application is nowhere near its limit, so “we need a bigger window” would be the wrong diagnosis for any problem it has. Second, history is nearly half the input and growing every turn, which is where the eventual pressure will come from.

The reservation is not optional

Almost every provider counts input and output against the same window. If your input is 127,000 tokens of a 128,000-token window, the model has room for 1,000 tokens of reply and will be cut off mid-sentence.

So reserve explicitly. Decide the maximum response length, subtract it, and treat the remainder as your real input budget. Truncation that happens silently in a client library is a bug you will chase for a day.

Four ways to trim history, in order of preference

Drop nothing yet. For most applications, conversations end long before the window does. Complexity added early is complexity for no reason.

Sliding window. Keep the system prompt, the first user message, and the last n turns. Simple, predictable, and it loses whatever was decided in the middle, which for a long support conversation is often the important part.

Summarise the old turns. Replace turns 1 to 12 with a model-written summary and keep the recent ones verbatim. Effective, and it introduces a compounding failure: summaries of summaries lose specifics, and the loss is invisible because the text still reads fluently. Keep the original transcript stored so you can recover.

Retrieve from history. Store past turns and pull back only the relevant ones. Best quality, most machinery, and it now inherits every retrieval failure mode in this module.

Tool definitions are the quiet cost

The line most teams have never examined is the tool definitions. Every function’s name, description, and full parameter schema is serialised into the prompt on every request, whether or not any tool is relevant. Forty tools with thorough descriptions can reach 8,000 tokens, sent on a request that asks what time the office closes.

Two fixes, both straightforward. Trim the schemas: a parameter description of three sentences rarely outperforms one clear sentence, and optional parameters nobody uses can go entirely. Then, if the count is large, select tools per request: a cheap classifier or an embedding lookup over tool descriptions can narrow forty to six before the prompt is built. Both changes reduce cost and improve selection accuracy at the same time, which is unusual enough to be worth taking.

Cost is not proportional to window size

A common misreading: a 1-million-token window does not mean using it is sensible. Every token you send is paid for and processed. Filling a large window costs the same as a large prompt anywhere else, plus the latency of prefill, plus the accuracy cost of the position effects in the next lesson.

The largest context windows are best understood as a capability for occasional heavy use (a whole codebase, a long deposition, a book) and not as licence to stop thinking about what goes in the prompt on ordinary requests.

Count before you guess

Python
import tiktoken
enc = tiktoken.get_encoding("o200k_base")
parts = {"system": SYSTEM, "tools": TOOLS_JSON, "examples": FEWSHOT}
for k, v in parts.items():
    print(f"{k:10} {len(enc.encode(v)):6,}")

Run this against your own application. The commonest discovery is that tool definitions or a long-untouched system prompt account for far more than anyone assumed, and that they are sent on every single request whether relevant or not.

The habit worth forming

Treat the context window as a shared resource with named claimants, review it the way you would review a bill, and require a justification for each line. Instructions accumulate: someone adds three sentences to the system prompt to fix an edge case, nobody removes them, and a year later the prompt is 4,000 tokens of overlapping and occasionally contradictory guidance that is degrading behaviour rather than improving it.

Every lesson here is open. Your progress is recorded once you pass the AI, Actually Explained exam.

Check your understanding

An assistant with a 128,000-token window starts returning replies that stop mid-sentence, and the input is around 126,000 tokens. What is happening?

Pick the one you would defend. Your answer stays private.

Next lesson · 9 minWhere in a long prompt things get missed

Stuck on something?Ask Anjali, your AI tutor

How to cite: Addaly (2026) ‘Budgeting the window, line by line’, in How a Language Model Actually Works. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/how-llms-work/what-fills-the-window (Accessed: 13 October 2026).