WRITE · TRACE · UNDERSTAND
Reserve output space before adding retrieval context
Implement pack_context(chunks,window,fixed,output).
Read lesson: Reserve output space before adding retrieval context →
Your experiment
Implement pack_context(chunks,window,fixed,output). chunks are (id,token_count), already ranked. Return admitted ids and total used context tokens. Skip oversized chunks, deduplicate admitted ids, require nonnegative integer counts/budgets and fixed+output<=window.
Python runs in your browser. Your draft stays on this device.
What to look for
The allocator enforces the supplied accounting contract. Incorrect tokenizer counts or omitted tool/message formatting overhead can still overflow a model context window, so the final serialized request needs a separate budget check.
Watch your code work
Ready to experimentWrite a solution or load the worked answer, then choose Trace & check.
Step through arrays, variables and training curves produced by your own Python.
