Your agent's context window fills up mid-task. What are your options?
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Four families of techniques, usually combined - and the goal isn't just fitting under the hard limit, it's keeping the context high-signal, because quality degrades well before the window is technically full.
Full worked answer with diagram
Four families of techniques, usually combined - and the goal isn't just fitting under the hard limit, it's keeping the context high-signal, because quality degrades well before the window is technically full.
-
Compaction/summarisation. Replace older turns with a dense summary that preserves decisions made, constraints discovered, current state, and open items - then continue with summary + recent turns. The art is in what survives: losing "we already ruled out approach X" causes the agent to repeat work; losing file paths breaks continuity. Production harnesses (e.g., Claude Code's auto-compact) trigger this at a threshold rather than at the wall.
-
Tool-result hygiene. Stale tool results are the biggest dead weight - a file read from 30 turns ago that's since been edited is worse than useless. Clear or stub out old results ("[result cleared - re-run tool if needed]"), keeping the fact that the call happened. Some providers now support automated tool-result clearing as a context-editing feature.
-
Structured note-taking outside the window. Give the agent a scratchpad - todo list, notes file,
NOTES.mdin the workspace - and prompt it to maintain state there. Notes persist across compaction and even across sessions, and the act of writing them forces the model to distill. This is the standard pattern for hours-long tasks (Anthropic's context-engineering guidance leans on it heavily). -
Architectural isolation. Push context-hungry subtasks into subagents that return only condensed findings; the orchestrator's window stays clean. Alternatively, checkpoint-and-restart: summarise learnings, spawn a fresh context seeded with the notes - often better than limping along with a polluted window.
Also mention retrieval: don't preload everything "just in case" - load references on demand via tools, keeping the working set minimal.
Worth sketching. Splitting the compactor's output into keep and drop is what turns a vague "summarise it" answer into a design.
flowchart LR
A["Turns 1 to 40"] --> B{"Compactor"}
B -->|"keep"| C["Decisions, constraints,<br/>current state, open items"]
B -->|"drop"| D["Raw tool dumps,<br/>dead ends, stale reads"]
C --> E["Fresh context:<br/>summary + recent turns"]
A -->|"written during the run"| F["Notes file<br/>outside the window"]
F --> E
What a good answer covers
- Four families of techniques, usually combined - and the goal isn't just fitting under the hard limit,…
- Compaction/summarisation
- Tool-result hygiene
- Structured note-taking outside the window
- Architectural isolation
Key terms: Compaction/summarisation · Tool-result hygiene · Structured note-taking outside the window · Architectural isolation
In the glossary: Compaction · Subagent
Interviewer follow-ups to expect
What specifically goes into a good compaction summary for a coding agent?
How do you evaluate that compaction isn't losing critical state?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep