Three-Layer Agent Memory: Design Principles and Implementation Practice

    A useful agent is not one that merely stores history, but one that keeps the right information with clear scope, source, and lifetime. This article explains a three-layer memory design—durable memory, session retrieval, and controlled external access—and how to handle writes, conflicts, expiry, deletion, and evaluation.

    1. Judge an Agent by Whether Its Memory Is Reliable

    In a short question-and-answer exchange, an agent may only need to understand the current input. In work that lasts for days, in business processes that are revised repeatedly, or in collaboration involving multiple people, users usually expect the system to remember constraints that have already been confirmed rather than ask for the same background every time.

    Suppose a project has already settled its deployment environment, data retention period, and interface compatibility requirements. If the agent later forgets those conditions, a locally reasonable proposal can still violate the overall design. The opposite failure is also common: treating a temporary discussion as a standing rule can bias later output.

    Having memory is therefore not the same as being able to use memory reliably. Four questions matter:

    • Which information is worth keeping, and which belongs only to the current task?
    • Does stored information have a source, a scope, and a validity period?
    • When a new question arrives, how can the system find relevant records that the current user is allowed to use?
    • When facts change, how are old memories updated, revoked, or deleted?

    Durable memory, session retrieval, and external extensions can form a layered design. This is an engineering way to organize a system, not a standard that every agent must adopt. Whether three layers are appropriate depends on business complexity, data volume, and governance requirements.

    2. Layer One: Durable Memory for Stable, Distilled Long-Term Information

    2.1 Durable memory is not a complete chat log

    The main value of durable memory is to give an agent the necessary background when work continues across sessions. It is suited to information that has been confirmed, is relatively stable, and is likely to be reused, such as:

    • Output preferences the user has stated explicitly
    • Technical constraints already confirmed for a project
    • Goals and interim conclusions of a long-running task
    • Reviewed operating rules
    • A decision and the conditions under which it applies

    A full chat log also contains temporary discussion, tentative opinions, and repeated phrasing. If all of that is treated as long-term memory, the system can confuse an idea that was raised with a conclusion that was finally confirmed.

    A better approach is to treat the session as source evidence, extract a small amount of structured memory from it, and keep a reference back to the original record.

    2.2 A memory entry needs boundary conditions

    A memory cannot consist of text alone. In practice, it usually also needs:

    • An owner: user, project, team, or organization
    • An information type: preference, fact, constraint, decision, or task status
    • A source: user confirmation, a business record, or a session excerpt
    • A creation time and a most recent confirmation time
    • A validity period or conditions for rechecking
    • A visibility scope and access permissions
    • A current status: active, pending confirmation, revoked, or superseded

    For example, “keep the result concise” may be a general user preference, or it may apply only to one reporting task. Without a scope, the system may still over-compress an answer during a technical review that needs a detailed explanation.

    Likewise, “this project should not add new dependencies for now” should be stored as a project constraint, not as a permanent preference of the user across every project.

    2.3 Writes to memory must be controlled

    Long-term memory affects future decisions, so writing it should be more cautious than ordinary text generation.

    A suitable flow is to identify candidate information, judge its stability, necessity, and sensitivity, check existing records, and then decide whether to add, update, or request confirmation. High-risk matters involving permissions, finance, or security policy should not be written automatically from model inference alone.

    Passwords, temporary credentials, and unnecessary personal sensitive information should not be stored. A memory system should follow minimization: data that can be reached through a secure reference does not need to be copied into long-term memory, and information needed for only one task does not need to be kept permanently.

    3. Layer Two: Session Retrieval for Process, Evidence, and Context

    3.1 Why retrieval is still needed when a summary exists

    Durable memory is usually highly compressed. It can tell the agent what the conclusion was, but not necessarily why that conclusion was reached.

    When a user asks about the trade-offs behind a proposal, the source of a condition, or the reason for a change, the system needs to return to the historical session and recover the relevant discussion. That is the role of session retrieval.

    It is suited to questions such as:

    • Which options were rejected in the last discussion, and why?
    • At which stage did the user change the requirements?
    • Was a constraint explicitly confirmed, or only proposed?
    • Does the current task depend on a historical task?

    Session retrieval is not a replacement for durable memory. It supplies the evidence behind it.

    3.2 Splitting should preserve semantic relationships

    Mechanical splits by fixed length can separate a question from its answer, a conclusion from its conditions, or a proposal from the objections to it. The retrieved result then loses context.

    A safer reference for splitting is a continuous run of dialogue turns, a task stage, or a topical segment, while preserving necessary relationships between neighboring segments. Each segment should be associated with a session identifier, time, project ownership, and participant permissions.

    Discussions with multiple rounds of revision should also mark which content is an early version and which is the finally confirmed version. Otherwise, retrieval may return the older proposal with the most similar wording and miss the newer conclusion that is actually in effect.

    3.3 Retrieval cannot rely on semantic similarity alone

    Semantic retrieval can find content that is worded differently but close in meaning, which suits natural-language questions. Keyword retrieval is better for locating identifiers, field names, and exact terms. The two can be combined, but business filters are still required.

    A more complete retrieval process can include:

    1. Determine the current user, project, and task scope.
    2. Apply permission filters before searching for candidate segments.
    3. Combine semantic matching, keyword matching, and time conditions.
    4. Rank candidates by relevance.
    5. Check whether a newer version or a conflicting record exists.
    6. Extract the necessary segments and attach sources for later verification.

    Relevance is not the same as truth. Retrieval finds evidence that may be useful; it does not automatically prove that a statement in that evidence is still valid.

    4. Layer Three: External Extensions for Business Knowledge and Authoritative Data

    4.1 External access is not just more storage

    When information comes from a business database, a document repository, or a workflow system, memory stored inside the agent is often not enough. An external extension layer can reach those sources through controlled connections and supply more complete or more current information.

    The point of this layer is to let the agent obtain external knowledge relevant to the task, not to copy all enterprise data into internal memory.

    For example, a past session may record the owner of a resource, while organizational responsibilities have since changed. For a dynamic fact such as the current owner, an authorized authoritative source should be queried first rather than reusing the old session.

    4.2 Knowledge queries and business operations must be separated

    Reading a document and changing business state carry different risks. The external layer should separate read-only access from write operations:

    • Query operations should limit data scope, fields, and result size.
    • Write operations should require stricter authorization and parameter checks.
    • High-risk operations should add human confirmation or approval.
    • Repeated requests should have a mechanism to prevent duplicate execution.
    • Access and modification should leave audit records.

    Finding the sentence “you may proceed” in a historical session does not mean the current operation is authorized. Authorization must come from the permissions that are valid now and from an explicit operating process.

    4.3 External text should be treated as data, not as instructions

    Documents, past sessions, and external responses may contain text that looks like an instruction. The agent should treat that content as data to be analyzed. It must not be allowed to override system rules, expand access, or change operational boundaries.

    External integration therefore needs controls for authentication, permission mapping, call timeouts, failure handling, and filtering of sensitive information. Pluggable capabilities add flexibility, but they also enlarge the failure surface and the security boundary. A successful connection is not the only concern.

    5. How the Three Layers Work Together

    The architecture should not be reduced to “if the answer is not inside, query outside.” A better approach is to choose the information path according to the kind of question.

    Long-term user preferences can be read first from durable memory. Evidence for a past decision can be retrieved from sessions. Current business state should come from an authoritative external source.

    A task can follow this flow:

    1. Identify the request type, task scope, and data sensitivity.
    2. Load the long-term constraints that are valid in the current scope.
    3. Decide whether historical discussion is needed as supporting evidence.
    4. Decide whether the latest business data must be queried.
    5. Check permissions, freshness, and conflicts across sources.
    6. Keep only what is required to complete the task within the context budget.
    7. Produce the result and state the key basis, or any unresolved uncertainty.
    8. Submit newly produced stable information to the controlled memory-write process.

    Task output should not automatically become a new fact. Model inferences, suggestions the user has not confirmed, and operations that did not succeed should not be written directly into active long-term memory.

    6. Conflicts, Expiry, and Deletion

    6.1 “Newest record wins” is not enough

    A newer item may be only a tentative remark, while an older item may be a formally approved rule. Conflict handling should consider source authority, confirmation status, scope, and time together.

    If a project rule conflicts with a personal preference, the formal rule should normally take priority within that project. If two records share the same scope and it is impossible to tell which one is valid, the conflict should be retained and confirmation requested, rather than left to the model to choose.

    6.2 Different memories need different lifetimes

    Long-term output preferences and short-term task state change at different rates, so they should not share one expiry policy.

    Temporary environment state can have a short lifetime. Project decisions can be rechecked when a milestone changes. Long-term preferences can be kept longer, but users should still be able to view and change them. High-risk information should be confirmed again after it expires, not treated as still valid by default.

    6.3 Deletion must cover derived data

    Deleting an original record does not mean the related information has left the system. It may already be present in summaries, search indexes, caches, or other derived memories.

    The system therefore needs source relationships so that deletion and revocation can propagate to related data. Where backups exist, the restore process must reapply deletion markers so that old information does not re-enter the online system.

    7. How to Tell Whether Three-Layer Memory Is Actually Useful

    A memory system should not be judged only by retrieval speed or by how fluent the answers sound. Evaluation should use a test set built around real tasks.

    Useful dimensions include:

    • Constraint following: after a new session, does the agent still obey confirmed requirements?
    • Retrieval quality: can it find the necessary evidence while reducing irrelevant content?
    • Source traceability: can a key conclusion be traced to a valid source?
    • Update correctness: does revised information replace the old version?
    • Isolation: is there leakage across users or projects?
    • Deletion effectiveness: after deletion, can the information still be retrieved or cited?
    • Task benefit: does it reduce repeated explanation, rework, and manual checking?

    Test cases should include contradictory information, expired records, insufficient permissions, unavailable external services, and follow-up questions after deletion. Good behavior on the normal path does not show that the system is ready for long-term use.

    8. Implementation Advice: Set Boundaries Before Expanding

    There is no need to connect every data source at the start. Choose one task with a clear scope, establish a limited durable memory and traceable session retrieval, and add read-only external access only when it is needed.

    A practical order is to define memory types and scopes first, then write review and update rules, then retrieval and permission control, and finally external extensions, auditing, and exception handling. Each added capability should come with added tests, not only with another entry point.

    The value of a three-layer memory architecture is not that the agent remembers everything. It is that the agent uses the right information in the right situation. Durable memory holds stable background, session retrieval holds process evidence, and external extensions provide controlled access to business knowledge and changing facts. Only when update, deletion, permission, and evaluation mechanisms are added does memory stop being a convenient extra feature and become a reliable basis for long-running work.