You have a long-running agent that accumulates conversation and tool output until it overruns its context window mid-task. Walk me through the techniques you'd use to keep it coherent over a long task without just truncating history.

technical-conceptual · Senior level · data-ml

What the interviewer is really asking

Probes practical context-management techniques for long-horizon agents — compaction, external memory, and tool-result pruning — versus naive truncation that drops critical decisions.

What to say

What to avoid

Example answers

Strong: I avoid blind truncation — it drops the decisions the agent still depends on. First, compaction: as we near the limit, summarize the conversation and reinitialize a fresh window seeded with that summary so coherence and key state survive. Second, external memory: the agent writes structured notes — decisions, open tasks, dependencies — to storage outside the window and keeps references like IDs or paths to re-load just-in-time, instead of carrying everything inline. Third, prune tool-result pollution: once a tool's raw output deep in history has been consumed, I collapse it, since the agent rarely needs the raw payload again. Net effect is the smallest high-signal window that still remembers what matters.

Weak: When it gets close to the limit I'd drop the oldest messages to make room for new ones — usually the most recent context is the most relevant anyway. If that loses too much, I'd move it to a model with a bigger context window so we can keep the whole history in the prompt and not have to manage it.

Want questions matched to your role? Paste a job title, job description, or CV and get a personalized set, or go Pro to unlock the full bank.