AI Memory Management: A Five-Level Layered Model and Engineering Practices

    This article breaks down a five-level model for AI memory, from session-scoped context (L1) and auto-extracted profile facts (L2) to project workspaces (L3), file-based layered memory (L4), and orchestrable memory systems (L5). It explains where the boundary between managed and self-hosted memory lies, what that boundary means for data sovereignty, auditability, and migration cost, and covers the engineering constraints and common pitfalls of L2. It also outlines a two-tier file layout, retrieval and role-based isolation, selection guidance by use case, and four non-negotiable governance rules.

    1. Why Memory Deserves Its Own Layering

    In the engineering practice of AI agents and conversational applications, memory is not as simple as stuffing the entire message history into a prompt. What actually determines user experience and cost is where information is stored, its lifecycle, its visibility, and how it can be orchestrated. The industry commonly abstracts AI memory capability into a five-level model, where each level solves a different class of problem and carries different data governance responsibilities.

    L1: In-Session Memory — Short-Term State Bounded by the Context Window

    Only information from the current session is retained, and the capacity ceiling is determined by the model’s context length. Its advantage is zero additional engineering cost; its drawback is that everything is lost when the session ends, and long conversations suffer from early information being compressed or truncated. Every product has this layer — it is a baseline, not a selling point.

    L2: Automatic Profile Memory — Preference Facts Extracted on the Platform Side

    The platform extracts user preferences, identity, and habits from conversation text to form reusable background information for later sessions. Users can usually view or delete this in the settings page, or turn the capability off entirely. The key engineering constraint: this memory consists of “extracted short facts,” not archived original text.

    L3: Project Space Memory — Workspaces Isolated by Project

    Instructions, reference material, and memory are stored per project, with projects isolated from one another to prevent context from bleeding across them. It fits multi-task parallel scenarios with clear boundaries, such as different customers, different product lines, or different experiment branches.

    L4: File-Based Layered Memory — Editable Text on the User’s Own Machine

    Rules, memory, and workflows are saved as local files, typically split into a global layer and a project layer, which users can edit directly and put under version control. Control returns fully to the user, and this is an important watershed in the layered model.

    L5: Orchestrable Memory System — Retrieval, Isolation, and External Integration

    Building on L4, this level further supports full-text retrieval across all historical conversations, isolation of an entire state set by role, and integration with external memory stores or vector retrieval services, forming a programmable memory middle platform.

    2. Where the Line Falls: Managed vs. Self-Directed

    L2 and L3 memory lives on the platform’s servers and is managed by the user through a settings interface; L4 and L5 memory consists of files on the user’s own machine, and the user decides which layer to use. This line determines three things: who owns data sovereignty, how auditable the system is, and the cost of migrating across tools. When selecting a solution, answering “is memory data allowed to leave our environment?” is often more effective than comparing feature checklists.

    3. L2 Engineering Details and Common Pitfalls

    Taking the memory capability of a certain class of general-purpose assistant product as a reference, L2 typically has three shared characteristics worth confirming before designing a solution:

    • Restricted extraction sources: extraction happens only from conversation text and does not include uploaded images, attachments, or link content. This means multimodal material does not automatically enter long-term memory.
    • Turning it off is not the same as erasing it: the toggle only stops new additions, and existing memory must be deleted separately; deleting a conversation does not roll back the memory entries that conversation produced.
    • Scope isolation: within the same client, memory for different agents is independent and is not shared across agents.

    Therefore, L2 is suited to atomic short facts such as “what I prefer” and “what my professional role is,” and is not suited to carrying multi-section, long-form specifications. In practice, users have tried writing an entire writing style guide into long-term memory and failed, precisely because the extraction mechanism discards structure and length.

    A schematic memory entry structure (pseudocode, expressing data shape only):

    1. {
    2. "scope": "user_profile",
    3. "fact": "Prefers concise technical documentation with conclusions first",
    4. "source": "conversation_text",
    5. "created_at": "2024-01-01T00:00:00Z",
    6. "editable": true
    7. }

    4. From L3 to L5: Treating Memory as a Maintainable Engineering Asset

    Once you reach the file-based stage, a two-tier directory layout is recommended: the global layer holds general rules and safety constraints, and the project layer holds task context and workflow descriptions. The load order is fixed as “global first, project second,” which makes overriding and trimming straightforward.

    1. memory/
    2. global/rules.md
    3. projects/demo/rules.md
    4. projects/demo/notes.md

    L5 further adds retrieval and isolation:

    1. # Schematic: assembling memory context by role
    2. def build_context(role, project, query):
    3. parts = [load("global/rules.md")]
    4. parts.append(load(f"projects/{project}/rules.md"))
    5. parts += vector_search(query, top_k=5, filter={"role": role})
    6. return "\n\n".join(parts)

    5. Selection Guidance and a Rollout Checklist

    • Single-turn experience only: stay at L1 and keep prompt size and latency under control.
    • Personalization needed: use L2, and clearly tell users they can view, delete, and disable it.
    • Multiple projects in parallel: move up to L3 with strict project-level isolation and quotas.
    • Strong compliance and auditability: choose L4/L5 and bring memory under version control and a permission system.
    • Retrieval at scale: at L5, introduce general cloud capabilities such as object storage, message queues, logging services, and monitoring with alerting to ensure persistence, asynchronous updates, and observability.

    During rollout, four bottom lines must be enforced: minimize memory entries, define retention periods explicitly, close the deletion loop, and require explicit declaration for cross-layer writes. If general-purpose storage and retrieval capabilities from platforms such as Baidu AI Cloud are used to carry the memory layer, the same layering and governance principles apply — define the boundaries first, then talk about intelligence.