An agent runs long tasks that exceed its context window. How do you manage context so quality stays high?
What the interviewer wants to hear
- Keep the stable prefix small and cacheable
- Trim or summarise old tool outputs
- Persist key state and notes outside the context
- Use sub-agents or fresh contexts for subtasks
- Test that critical facts survive compaction
Model answer
Even before the hard limit, very long contexts cost more, slow down and can make the model miss details, so I manage context actively. The system prompt and tool definitions stay compact and stable at the start, which also keeps prompt caching effective. Large tool outputs are trimmed to what matters, and old ones are cleared or replaced with short summaries once they have been used. Important state, such as the plan, decisions, open questions and progress, is written to external notes or memory files that the agent can re-read, so compaction does not lose it. For big subtasks, I can hand work to a sub-agent with a fresh context that returns only a concise result. Then I test long runs specifically, checking that key facts and constraints from early on are still respected later.
Can you answer it under time pressure?
Take a timed hard round and get scored on every answer.
More hard Prompt Engineer questions
- What is prompt injection, and how would you reduce the risk for an assistant that reads emails and can draft and send replies?
- Design an LLM-as-judge setup to evaluate a summarisation feature. How do you make it trustworthy?
- Your company is moving its prompts from one model provider to another. How do you plan and run the migration?
- You need an assistant that serves users writing in Hindi, Tamil and mixed Hinglish. What prompting and evaluation challenges do you expect?
- A high-volume prompt costs too much. How do you reduce cost while protecting quality?
- You are building an agent that reads emails and web pages and can send messages and update a CRM. How do you protect it from indirect prompt injection?
- How would you evaluate a multi-step agent that completes tasks using tools, rather than a single prompt?
- How do you show with confidence that a new prompt is better than the current one, and not just lucky on your test set?
- Design a layered guardrail system for a public-facing LLM assistant. What goes where, and what are the trade-offs?