A 5-step way to answer any context engineering question
- List the inputs. Instructions, examples, retrieved data, tool results, memory and conversation history.
- Budget tokens. Decide how much of the window each input gets.
- Order and format. Put stable content first and structure content with clear sections.
- Compress. Summarize, trim or drop stale content as the session grows.
- Measure. Task success, faithfulness, cost and latency as you change context.
Contents: Fundamentals (questions 1 to 4) · Long sessions and agents (questions 5 to 8) · Optimization and evaluation (questions 9 to 14)
Fundamentals (questions 1 to 4)
1. What is context engineering and how is it different from prompt engineering?
- Prompt engineering focuses on wording instructions.
- Context engineering covers everything in the window: instructions, retrieved documents, tool outputs, memory and history.
- It is dynamic: the context is assembled for each call.
- It matters most for agents and long sessions.
Common pitfall: Treating it as a new name for writing better prompts.
2. Why does more context not always help?
- Cost and latency rise with input tokens.
- Irrelevant content can distract the model.
- Models can underuse information in the middle of long contexts.
- Select the most relevant content instead of including everything.
Common pitfall: Filling the window because the model supports it.
3. How do you structure a context for an LLM call?
- System instructions and rules first, then stable reference material.
- Retrieved or tool content clearly delimited and labeled with sources.
- The current task or question near the end.
- An explicit output format.
Common pitfall: Mixing instructions and untrusted retrieved content without separation.
4. What is a token budget?
- A planned allocation of the context window across inputs and the expected output.
- It prevents one input, like a long tool result, from crowding out others.
- Enforce limits by truncating, summarizing or paginating.
- Monitor actual usage per call.
Common pitfall: Discovering the context limit only when calls start failing.
Long sessions and agents (questions 5 to 8)
5. How do you handle a conversation that exceeds the context window?
- Keep recent turns verbatim and summarize older ones.
- Store important facts in structured memory and retrieve them when relevant.
- Drop content that no longer matters, such as resolved tool outputs.
- Test that key facts survive compaction.
Common pitfall: Truncating from the start and losing the original task.
6. What is compaction in agent loops?
- Periodically replacing accumulated history with a summary of progress, decisions and open items.
- It keeps long tasks within the window and reduces cost.
- Summaries can drop details, so keep references to full records.
- Check task success before and after compaction.
Common pitfall: Compacting so aggressively that the agent repeats finished steps.
7. How do you manage large tool outputs?
- Return only the fields the model needs.
- Paginate, filter or summarize large results.
- Store full results outside the context with a reference the agent can query.
- Cap tool output size in code.
Common pitfall: Pasting an entire API response into the context.
8. What types of memory do agents use?
- Short-term memory: the current context window.
- Long-term memory: stored facts or past interactions retrieved when relevant.
- Some designs separate episodic (events), semantic (facts) and procedural (how-to) memory.
- Decide what to write, when to read and when to forget.
Common pitfall: Saving every message forever and retrieving noise.
Get the free 50 RAG and LLM interview questions
Join the voluntary email list and open the free set of 50 RAG and LLM interview questions with short model answers. You will also get occasional new question sets. No spam, and you can unsubscribe at any time by replying "unsubscribe" to any email.
Optimization and evaluation (questions 9 to 14)
9. How does prompt caching affect context design?
- Providers can reuse computation for a repeated prefix.
- Put stable content (system prompt, tools, reference docs) first and changing content last.
- Avoid inserting timestamps or user data at the top.
- This lowers latency and cost for repeated calls.
Common pitfall: Placing per-request variables before the static instructions.
10. How do you choose between retrieval and putting everything in context?
- Small, stable reference sets can go directly in context, especially with caching.
- Large or changing corpora need retrieval.
- Retrieval also supports permissions and freshness.
- Measure both on your task.
Common pitfall: Always defaulting to one approach.
11. How do few-shot examples fit into context engineering?
- Examples show format and edge cases better than long instructions.
- Choose examples relevant to the current input, sometimes by retrieval.
- Keep them short and consistent with the desired output.
- Too many examples cost tokens and can bias outputs.
Common pitfall: Using examples that contradict the instructions.
12. How do you protect context from injection?
- Label untrusted content and keep it separate from instructions.
- Do not give untrusted content authority to change tools or permissions.
- Validate actions in code.
- Filter or sanitize obvious instruction patterns in retrieved text.
Common pitfall: Assuming delimiters alone stop injection.
13. How do you evaluate a context change?
- Use a fixed task set and compare success rate, faithfulness, cost and latency.
- Run several samples per task because outputs vary.
- Inspect failures to see if context was missing or noisy.
- Keep the change only if it helps on the metrics you care about.
Common pitfall: Judging by a few manual tries.
14. What does "context rot" mean in long runs?
- Quality tends to drop as the context fills with stale, redundant or conflicting information.
- Symptoms: the agent forgets goals, repeats steps or follows old instructions.
- Fixes: compaction, structured state and restarting with a clean summary.
- Monitor quality versus context length.
Common pitfall: Blaming the model when the context has degraded.
FAQ
Is context engineering a real interview topic?
Yes. It shows up in AI engineer and agent interviews as questions about memory, token budgets, retrieval and long-running agents, even if the term is not used.
Do I need to know specific context window sizes?
No. Know the trade-offs; exact sizes change with each model release.
What is the most common mistake?
Adding more content instead of better-selected content.
How do I practice?
Take an agent task, log its context at each step and try to cut tokens while keeping task success.
The 0 to 1 AI Engineer Interview Playbook covers answer frameworks, system-design walkthroughs and an 8-week plan. $19.99 on Gumroad.
Get the playbookAll interview topics · Prep guides · Question deep dives · Free 50 RAG and LLM questions