Question presented to candidate: "Our chat assistant works fine in short sessions, but long conversations start failing or the bot forgets what the user said at the start. What is a context window, what exactly happens when we go over it, and how should the app handle it?"
What a strong answer should cover:
- The context window is the maximum number of tokens the model can attend to in one request, and it is shared: system prompt, tool definitions, the whole message history, retrieved documents, images, and the output (including any reasoning tokens) all count
- The model is stateless: chat APIs resend the full conversation on every call, so the history grows every turn until it no longer fits
- What happens on overflow: hosted APIs reject the request with a 400-style error rather than silently cutting it; truncation, if any, happens in your code or a framework, and naive truncation from the front drops the system prompt
- Handling strategies: reserve room for the output, keep the system prompt pinned, drop or summarise old turns, retrieve only the relevant documents, and count tokens before sending
- Even within the limit, long contexts cost more, add latency and recall less reliably (information in the middle is used worse β "lost in the middle")
Clarifying questions expected:
- Which model and context size are we on, and what
max_tokensdo we request? - What must never be lost (system rules, user identifiers, earlier decisions), and can older turns be summarised?
Code / implementation expected: Optional β a token budget check with a trimming strategy, or pseudocode for it.