Hard

Design Context and Memory for a Long-Running Agent System Design Interview

Design context curation, compression, retrieval, and durable memory for agents operating across many hours and context windows.

1. Problem Statement

Design memory and context management for an agent that works on a project for days, uses many tools, and must resume accurately after context compaction.

2. Architecture Discussion Map

Use this as one discussion aid, not a single correct answer. Your design should follow from the requirements, scale, and trade-offs you establish.

Rendering architecture diagram...
Mermaid Source (For AI Bots)
graph LR
    A["Design Context and Memory for a Long-Running Agent"]
    A --> F1["Memory tiers and source-of-truth model"]
    A --> F2["Context selection, compaction, and eviction"]
    A --> F3["Retrieval indexing, freshness, and provenance"]
    A --> F4["Concurrent updates and consistency"]
    A --> F5["Quality, privacy, cost, and long-horizon evaluation"]

3. Key Focus Areas

  • 1
    Memory tiers and source-of-truth model
  • 2
    Context selection, compaction, and eviction
  • 3
    Retrieval indexing, freshness, and provenance
  • 4
    Concurrent updates and consistency
  • 5
    Quality, privacy, cost, and long-horizon evaluation

4. What Strong Candidates Should Demonstrate

  • Treat context as a finite attention budget rather than an append-only log.
  • Separate working state, episodic memory, semantic memory, and source-of-truth artifacts.
  • Measure whether compaction and retrieval preserve task-critical facts.

Evaluation Guide

This is an evaluation framework, not a single model answer. Strong designs may make different choices when their assumptions and trade-offs are explicit.

Memory model

25%

Senior signals

  • Separates active plan/working set, conversation history, durable facts, artifacts, and external records.
  • Defines authority and versioning instead of letting summaries overwrite source evidence.

Context curation

30%

Senior signals

  • Budgets tokens by utility, compacts old state, preserves decisions and unresolved work, and avoids recursive summary drift.
  • Selects tools and schemas without flooding every turn.

Retrieval and consistency

25%

Senior signals

  • Uses metadata, semantic and lexical retrieval, recency, permissions, and provenance.
  • Handles stale memories, contradictory updates, concurrent agents, and deletion.

Evaluation and safety

20%

Senior signals

  • Measures task success, recall, hallucinated memory, compaction loss, latency, and token cost.
  • Covers sensitive-memory retention, tenant isolation, and user controls.

Trade-offs to articulate

  • Compression ratio versus information loss.
  • More retrieved context versus attention dilution.
  • Automatic memory writes versus false durable facts.

Practice follow-up questions

  1. 1.A summary incorrectly states a migration completed. How is the error detected?
  2. 2.Two agents update the same plan concurrently. What is authoritative?

Want interactive feedback?

Practice drawing this system component-by-component on a live whiteboard while the interviewer probes at your target level.

Start Interview

Core Concepts

Context EngineeringAgent MemoryRetrievalCompactionLong-Horizon Tasks