Agent Memory Architecture: Designing and Implementing a Tiered Memory Stack

    This article explains why memory becomes an engineering bottleneck as AI agents evolve from single-turn tools into long-running autonomous assistants. It introduces a tiered "hot-warm-cold" memory design inspired by storage hierarchies, covering the responsibilities of session, skill, and persistent note layers, a storage and retrieval combination using relational storage, full-text indexing, and model-based summarization, and cost-control mechanisms. It also outlines common pitfalls and engineering recommendations for building a measurable, evolvable memory system.

    1. Background: Why Agent Memory Becomes an Engineering Bottleneck

    As agents evolve from single-turn Q&A tools into long-running autonomous assistants, memory capability becomes the key factor that sets the upper limit of the user experience. Early solutions generally relied on plain marked-up text files to hold memory: persona settings, conversation history, and user profiles were written to separate documents and loaded into the context in full at runtime. This approach has clear advantages—it is transparent, editable, and version-controllable, and everything is easy to inspect during debugging.

    However, as the number of sessions and accumulated knowledge keeps growing, a pure file-based approach exposes three structural problems:

    1. Linear cost growth: Memory size is directly proportional to the context length injected into each request. Token consumption rises roughly linearly as history accumulates, making costs unpredictable over long-term use.
    2. Insufficient retrieval precision: Loading entire blocks of text or relying on simple keyword matching makes it hard to connect content that is “related but phrased differently,” resulting in high recall noise.
    3. Manual maintenance dependency: Blurred layer boundaries and piled-up redundant content require periodic manual cleanup, which cannot support autonomous agent operation.

    So the essence of the problem is not “whether to have memory,” but how to deliver highly relevant, low-cost memory supply within a limited context budget.

    2. Design Principles: Treat Memory as a Tiered Storage System

    Borrowing the idea of storage hierarchies in computing, agent memory can be abstracted into a three-tier “hot–warm–cold” structure. The core principle is: access frequency determines where data resides, and relevance determines the injection ratio.

    • High frequency, strong timeliness: session memory, resident in context;
    • Medium frequency, reusable: skill memory, retrieved and injected on demand;
    • Low frequency, high value: persistent notes, summarized and injected after semantic recall.

    This principle brings two direct benefits: context length no longer grows infinitely with history, and memory maintenance shifts from “manual cleanup” to “policy-driven automatic archiving.”

    3. Implementing the Tiered Memory Stack

    3.1 Responsibility Boundaries of the Three Layers

    • Session memory: Holds the context and intermediate conclusions of the current task. It has a short lifecycle and is compressed or discarded when the task ends.
    • Skill memory: Accumulates reusable experience in a “problem pattern—solution steps—verification method” structure to avoid repeated trial and error.
    • Persistent notes: Accumulates user preferences, domain knowledge, and long-term conclusions across sessions, forming the basis for long-term personalization.

    3.2 Storage and Retrieval Combination

    In engineering, a combination of “relational storage + full-text index + model-based automatic summarization” can be used: structured tables store metadata and timestamps, the full-text index handles keyword recall, and the model compresses long text into short summaries that can be injected. A sample structure is shown below:

    1. CREATE TABLE memory (
    2. id INTEGER PRIMARY KEY,
    3. layer TEXT NOT NULL, -- session / skill / note
    4. content TEXT NOT NULL,
    5. summary TEXT,
    6. created_at INTEGER
    7. );
    8. CREATE VIRTUAL TABLE memory_fts USING fts5(content, content='memory', content_rowid='id');

    During retrieval, first perform a candidate recall, then do one rerank and budget trimming:

    1. def recall(query, budget=1200):
    2. rows = fts_search(query, limit=20) # keyword recall
    3. rows = rerank(query, rows)[:8] # relevance rerank
    4. return [r.summary or summarize(r.content) # summary compression
    5. for r in rows][:budget // 150]

    3.3 Cost Control Mechanisms

    Cost control should rest on four adjustable knobs: injection budget cap, summary compression ratio, archiving trigger threshold, and expiration eviction policy. With the order of “recall first, then summarize, and inject only summaries,” the memory overhead of a single request can be reduced from “full history” to a “fixed budget,” turning the cost curve from linear into approximately constant.

    4. Common Pitfalls and Engineering Recommendations

    • Pitfall 1: Stuffing all information into the context. Context is a scarce resource and should be treated as a “cache” that requires budget management, not a “warehouse.”
    • Pitfall 2: Only doing keyword retrieval. Semantic recall and reranking need to be introduced to solve missed recall where “the phrasing differs but the meaning is the same.”
    • Pitfall 3: Writing memory without organizing it. Automatic archiving and conflict-resolution rules should be set up—for example, when a new conclusion overrides an old one, keep the update timestamp.
    • Engineering recommendation: Instrument the full pipeline to record “recall hit rate, injected token volume, and task success rate,” and use data to drive threshold adjustments; at the same time, set retention periods and cleanup policies for memory data to balance effectiveness and compliance.

    5. Conclusion

    The competitiveness of an agent memory system has shifted from “how much it can remember” to “whether it can remember the right content at a controllable cost.” A tiered memory stack combined with structured storage, full-text retrieval, and automatic summarization provides a practical, measurable, and evolvable implementation path. If combined with general cloud capabilities such as object storage, message queues, and monitoring and alerting, it is possible to further achieve persistence, asynchronous archiving, and runtime observability of memory data, laying a stable data foundation for long-running autonomous agents.