Asked in an AI engineer interview.
What they are really testing: whether you treat context as a scarce budget and memory as a retrieval and consolidation problem, and whether you can explain how the system decides what the model sees on each step.
A strong answer:
- Split memory into tiers: the current observation (goal, latest tool outputs), a short scratchpad for decisions and constraints, a rolling summary of older turns, and a long-term store (vector index plus structured records for facts like preferences, IDs, and task status).
- Assign each section a fixed token budget before the step runs. Reserve space for the system prompt, tool schemas, and the output, then fill memory sections up to their caps. Overflow goes to summarization, not truncation.
- Retrieve with hybrid search (dense plus BM25 or keyword filters), scoped by user, session, and entity metadata, then rerank. Pull a modest top-k, often 5 to 20 candidates, and keep only the few that clear a relevance threshold.
- Score candidates on relevance, recency, and importance, not similarity alone. Deduplicate near-identical items and attach provenance (source, timestamp) so the model can weigh conflicting facts.
- Control writes as carefully as reads. Decide what is worth storing, consolidate episodes into facts, expire stale items with TTLs, and validate memory writes against a schema so a bad generation cannot silently corrupt the store.
- Log exactly which memories were retrieved and why for each step. Build a small evaluation set of memory probes to measure recall@k and answer quality as you tune chunking, budgets, and rerankers.
Common mistakes:
- Appending full conversation history until the window fills, then cutting from the top, which drops constraints the agent still needs.
- Relying on embedding similarity alone, which surfaces topically similar but outdated or wrong-user memories.
- Letting the model write arbitrary memories with no validation, so errors persist and compound across sessions.
How would you split the budget between working memory and retrieved long-term memory, and what signal would tell you it is wrong? Share your approach below.
Originally shared on LinkedIn.
An AI interview question every day, leadership for tech people and hands-on AI learning:
Top comments (0)