The model's working memory: what fits, what falls out, and how apps deal with the limit.
Skip to solutionKEEP THE
easyAI Engineering
What is a context window and what happens when you exceed it?
172 views
01
Understand the problem
context-windowlimitsfundamentals
02
Attempt it yourself
Sketch your approach before reading the solution — that's what interviews test.
Nudge consolestandby
Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.
03
Study the solution
The context window is the maximum number of tokens (prompt + generated output) a model can attend to in one request. Exceeding it causes an API error or forces truncation; apps handle the limit by summarizing, trimming old turns, or retrieving only relevant context. Long contexts also degrade attention quality ('lost i
Solution ready — 2 min read
Classified // press E to declassify
04
Read the code
Guarding the window before a chat call
const WINDOW = 200_000;
const RESERVED_OUTPUT = 4_096;
function fitMessages(system: string, turns: Msg[], docs: Doc[]) {
let budget = WINDOW - RESERVED_OUTPUT - countTokens(system);
const keptDocs = takeWhileUnderBudget(rankByRelevance(docs), 0.4 * budget);
const keptTurns = takeRecentUnderBudget(turns, budget - tokensOf(keptDocs));
return { system, docs: keptDocs, turns: keptTurns };
}05
Join the discussion
Discussion (0)
Sign in to join the discussion.
No responses yet. Be the first to share what you think.
Transmission complete // awaiting log
KEEP THE
STREAK ALIVE.
Dossier 12 of 80 decoded in the AI Engineering track. One more won't hurt.