# State, memory and context interview questions

> 6 state, memory and context interview questions for AI and ML engineer roles, each with a model answer.

Canonical: https://llmdojo.dev/interview/topic/agent-memory
Last updated: 2026-10-23

6 questions: 1 junior, 3 mid-level and 2 senior. Taught in [State, Memory and Context Over Many Steps](https://llmdojo.dev/learn/agents-harness-engineering/state-and-memory).

## [What kinds of memory does an AI agent have?](https://llmdojo.dev/interview/q/what-kinds-of-memory-does-an-ai-agent-have)

Level: Junior

**Internal knowledge** (the weights), **short-term memory** (the context, limited and gone after the task), and **long-term memory** (external stores reached by retrieval, persistent and editable).

**Diagram: Three kinds of memory**

1. AI Engineering: the model itself is a memory, of what it was trained on. Information every task needs belongs here, through training or fine-tuning.
2. The context is short-term memory: fast to use, limited in size, and it doesn't persist across tasks. It's for what the current step needs.
3. External data reached by retrieval is long-term memory, as in a RAG system. Rarely needed information belongs here.
4. So the question for each piece of information is how often it's needed, and that decides where it lives.

Place information by how often it's needed.

## [What goes wrong if the harness just drops the oldest messages when the context fills?](https://llmdojo.dev/interview/q/what-goes-wrong-if-the-harness-just-drops-the-oldest-messages-when)

Level: Mid-level

The oldest message is often the **task itself**. FIFO assumes early messages matter least, and the book warns that can be fatally wrong, especially when they state the purpose.

In the course's 12-step run, dropping the oldest loses the task at step 6 while the context still looks fine.

## [How do you keep a long run within its context without losing what matters?](https://llmdojo.dev/interview/q/how-do-you-keep-a-long-run-within-its-context-without-losing)

Level: Mid-level

**Pin** what must stay (task, instructions, constraints) and **summarise** older steps instead of dropping them: Anthropic calls it compaction.

A summary keeps only what its prompt asks for, so test that later steps still find what they need.

## [What belongs in harness state rather than the context?](https://llmdojo.dev/interview/q/what-belongs-in-harness-state-rather-than-the-context)

Level: Mid-level

Anything that must be **exact** or must **survive**: IDs processed, refunds already issued, lists, queues. Structured data stays structured in code; in a context it's just text.

**Diagram: State the harness keeps**

1. The context should hold what the next decision needs: the task, a summary, recent results.
2. Everything else can live in the harness: a state object, a database, a notes file the agent writes to.
3. AI Engineering notes text in a context is unstructured; a memory system that stores structured data, like a spreadsheet of leads or a queue of actions, keeps its structure.
4. Anthropic describes keeping lightweight identifiers, such as file paths or stored queries, and loading data with tools at run time, rather than loading everything up front.

Load details just in time with tools, keeping lightweight identifiers in the context.

## [Your context fits the window. Why might you still manage it?](https://llmdojo.dev/interview/q/your-context-fits-the-window-why-might-you-still-manage-it)

Level: Senior

**Context rot**: as tokens grow, the model's ability to recall information from the context decreases; Anthropic calls the context an attention budget. And every step re-reads, and pays for, the whole context.

So keep it to what the next decision needs, well before the hard limit.

## [How would you design a handoff to a sub-agent?](https://llmdojo.dev/interview/q/how-would-you-design-a-handoff-to-a-sub-agent)

Level: Senior

The sub-agent knows only its brief. Send the **goal, specific inputs, constraints and the shape of the result**. Ask for a **condensed summary** back (Anthropic cites 1,000–2,000 tokens) that includes what it couldn't do or wasn't sure of.

Clean contexts keep each agent focused; the risk is information lost at each boundary.

## Related
- [All interview questions](https://llmdojo.dev/interview)
