Review the prerequisites
Suitable for: Can write basic programs and handle model context for the first time.
- Token
- A unit used by the model to encode and measure content; it does not correspond to a fixed number of Chinese characters or words. The lab supplies token counts directly and does not implement tokenization.
- Context
- The information available to the model in this request, including instructions, history, tool definitions, and source material.
- Generation budget
- The limit on generated content. Some APIs also count reasoning usage toward this budget; check the target API's rules.
- Safety margin
- Headroom reserved by the application for counting errors or expected growth. It does not replace actual token counts.
How does the mechanism work?
Step-by-step explanation
- Assemble the request
Count instructions, history, tool definitions, and evidence separately.
- Check constraints
Check both total capacity and the separate output limit.
- Call and check status
Distinguish completion, budget exhaustion, refusal, and transport interruption.
- Prepare for the next round
Recount after adding tool results to check whether necessary evidence is retained.
Foundation · Understand the concepts
Why can a short document still exceed the request limit?
Objectives of this level: Can indicate which parts of the complete input are included and distinguish between insufficient capacity and insufficient generation.
Visual guide · Recount the next request
These counts assume the lab’s shared 32,000-unit capacity. An independent output limit still applies; character counts and provider tokens are different units. Select the figure to open it at full size.
Count the whole request
A program reading a contract sends more than the contract itself: instructions, conversation history, tool definitions, and retrieved evidence also occupy input space. A few pages of text do not establish that the complete request is small. Tokens are an accounting unit; 2,000 characters cannot be assumed to equal 2,000 tokens.
Distinguish context capacity from the output limit
Context capacity limits the information a request can accommodate. A separate output limit caps generation. For interfaces where input and generation share capacity, a permitted output setting may still overflow the context when combined with the input. Increasing the output setting does not expand the context window.
Work through an explicit assumption
The lab assumes total capacity of 32,000, input of 23,000, a generation budget of 6,000, and a reserve of 1,000. Its local rule leaves 2,000. Adding a 4,000-token tool result on the next round exceeds capacity by 2,000. This is a request-capacity problem. If input fits but generation stops at its output limit, that is a different failure. A network disconnection alone establishes neither.
Run experiments and observe counterexamples
Offline arithmetic experiment for a given number of tokens; no model calls, no verification of tokenizers, streaming, or actual vendor limitations.
Python 3.10+ · Runs by default using only the standard library · Runs on your computer
- Calculate by hand first, then run the script to verify
- Change tool result increment and recalculate
- Deliberately exceed the independent output limit, check the wrong branch
python3 context_budget.pyView the entry-point script
"""Given token counts: no tokenizer, model request or provider-specific limit."""
import json
def remaining(context, output_limit, output, reserve, components):
values = [context, output_limit, output, reserve, *components.values()]
if any(type(v) is not int or v < 0 for v in values):
raise ValueError("counts must be non-negative integers")
if output > output_limit:
raise ValueError("output limit exceeded")
return context - sum(components.values()) - output - reserve
def demo():
components = dict(instructions=2000, history=10000, tools=3000, evidence=8000)
output = 6000
result = 4000
before = remaining(32000, 8000, output, 1000, components)
after = remaining(32000, 8000, output, 1000, {**components, "result": result})
return dict(input_tokens=sum(components.values()), current_room=before,
next_turn_room=after, next_turn_fits=after >= 0)
if __name__ == "__main__":
print(json.dumps(demo(), sort_keys=True))
Expected output when running locally
{"current_room": 2000, "input_tokens": 23000, "next_turn_fits": false, "next_turn_room": -2000}- Complete input items are consistent
- Next round of capacity recalculation
- Passing the experiment does not mean passing the answer quality
code example
Full contract terms determine exceptions
Ordinary summarization tasks become dependent on precise explanations of definitions, negatives, and exceptions.
When the budget is insufficient, can you summarize all the terms and explain them?
The abstract can locate relevant sections, but read the full definitions, terms, and exceptions of the applicable version before key conclusions, and retain the citation. If the combination still exceeds the window, split it into acceptable sub-tasks according to the problem, save the intermediate claims and basis and then synthesize them; if the necessary context cannot be retained, narrow the scope of the conclusion. Changing tokens cannot offset errors caused by missing conditions.
Capacity adjustments must retain evidence that determines the conclusion, and independent acceptance of semantic adequacy is required.
Acceptance task for this level
Calculate the current request and the margin after adding the tool results by hand, and write down three failure phenomena.
Reading this browser’s record…
Hide the answer and check your understanding
The output limit is 8000. Why would allowing 6000 generated tokens in this example still exceed capacity in the next round?
Expand reference derivation
The separate output limit is only one constraint. The next round's input of 27000, generation budget of 6000, and safety margin of 1000 total 34000, exceeding the teaching capacity of 32000.
Further explanations and practice
When encountering unfamiliar principles, first read the implementation, continuous questioning and migration cases, and then independently explain the premise and boundaries. Answers and notes are saved to the original account record.
Sources and verification scope
The principles are based on public information; the numbers, cases and tasks are the teaching design of this website. Offline experiments verify the range noted on this page, and the learning effect still needs to be judged through independent tasks and feedback.