Three-Tier Memory Architecture for AI Agents: Design Principles and Implementation Practices

    This article explores the design principles and implementation practices of a three-tier memory architecture for AI agents, comprising persistent memory, session retrieval, and external plugins. It covers how these tiers address specific memory challenges, their collaboration mechanisms, strategies for accurate memory writing and retrieval, maintaining security boundaries independent of model judgment, and methods to verify that the memory system effectively enhances the overall user experience.

    I. Reliable Memory: The Key to a Usable Agent

    In short conversations, AI agents can often rely on current context to handle Q&A, content consolidation, or task planning. However, when tasks span several days, involve multiple projects, or require constant referencing of historical decisions, relying solely on the current conversation leads to information omission, redundant confirmations, and inconsistent conclusions.

    For example, a user might specify that a project follows a strict change approval process, yet the agent ignores the approval phase in subsequent suggestions. Or, a user confirms that a certain proposal has been deprecated, but the agent retrieves the old proposal from historical records and presents it as the current conclusion. These issues do not necessarily stem from inadequate model reasoning capabilities; they often arise from a lack of clear rules in memory management.

    Therefore, evaluating an agent’s practicality requires answering three questions:

    • Which information should be retained long-term?
    • What evidence does the current task need to retrieve from history?
    • Which information must be queried in real-time from authoritative external sources?

    Around these three questions, a three-tier architecture composed of persistent memory, session retrieval, and external plugins can be constructed. It should be emphasized that this is a general engineering division, not a fixed standard that all agents must adopt. External plugins themselves are not equivalent to memory; their primary role is to handle controlled access to external knowledge and business states.

    II. Problems Solved by the Three-Tier Architecture

    1. Persistent Memory: Storing Stable, Reusable Facts

    Persistent memory is geared toward information used across sessions, such as explicitly confirmed user expression preferences, project constraints, long-term goals, and verified important decisions.

    It should not become a permanent copy of all chat content. Raw conversations contain extensive temporary discussions, hypotheses, unconfirmed conclusions, and sensitive information. Retaining all of this long-term increases retrieval noise and expands data governance risks.

    Information suitable for writing to persistent memory typically exhibits the following characteristics:

    • Clearly helpful for future tasks;
    • Has a relatively stable validity period;
    • Has a clear and traceable source;
    • The retention behavior complies with user authorization and data management requirements.

    For instance, “The user prefers technical solutions to explain risks and rollback methods first” can be a long-term preference. Conversely, “The user wants brief answers today” might only be a requirement for the current session and should not be directly upgraded to a permanent preference.

    2. Session Retrieval: Recovering Historical Context and Evidence

    The goal of session retrieval is not to summarize user profiles, but to retrieve previously occurred discussions, task progress, and decision rationales on demand.

    It is suitable for answering questions like “Why was that plan abandoned last time?”, “What step did we discuss previously?”, or “Who first confirmed this constraint?”. Compared to persistent memory, session records are more detailed but also more likely to contain outdated or draft content.

    Therefore, retrieval results should not just return an isolated piece of text. They should preserve necessary context, including recording time, associated task, discussion status, and adjacent messages. Otherwise, “This plan can be adopted” might be misunderstood as final approval, while the original conversation might continue with “but it requires waiting for a security review.”

    Session retrieval can comprehensively utilize keyword matching, semantic similarity, and structured filtering. Conditions such as project scope, time range, and participant roles are often just as important as semantic relevance.

    3. External Plugins: Fetching Authoritative, Time-Sensitive Information

    External plugins are used to connect to document repositories, business systems, or other authorized data sources. They solve problems that internal memory cannot reliably answer, such as current approval status, latest policies, real-time resource states, or updated project materials.

    The key to this layer is not the number of connections, but the access boundaries:

    • Can it only read data the user is authorized to access?
    • Can it differentiate between query operations and modification operations?
    • Does it log call sources and execution results?
    • Can it determine the time and authority of the returned data?

    For operations with side effects, such as modifying records, submitting approvals, or deleting data, the system should not automatically execute them simply because similar instructions appeared in historical memory. Memory provides context but cannot replace current authorization.

    III. Synergizing the Three Tiers: Collaboration, Not Overwriting

    A reasonable processing flow can be summarized as follows:

    Current Request
    → Identify task and permission scope
    → Read persistent memory on demand
    → Retrieve relevant historical sessions
    → Query external sources if necessary
    → Validate timeliness, conflicts, and evidence
    → Generate response
    → Filter new memories for writing

    There are two important principles here.

    First, retrieval should be task-driven rather than reading all memory every time. When a user is simply asking about a general concept, it is usually unnecessary to load a large amount of historical project data. Excessive retrieval increases processing costs and may allow irrelevant information to affect the response.

    Second, the data from the three tiers should not be directly concatenated and handed to the model to judge on its own. The system should first complete permission checks, deduplication, state identification, and basic conflict resolution before placing the necessary information into the current context.

    For example, if persistent memory stores “The project follows the old approval process,” but the external policy repository indicates the process has been updated, the system should check the applicability and effective date of the new policy. It should prompt that the existing memory might be outdated, rather than mechanically assuming “long-term memory is definitely more reliable.”

    IV. Memory Writing: Saving the Right Content Over Saving More Content

    1. Establishing Candidate Extraction and Confirmation Mechanisms

    It is recommended to split memory writing into multiple steps: extract candidate facts, assess retention value, check sensitivity, identify conflicts, and finally decide whether to write or wait for confirmation.

    Inferences generated by the model cannot be directly treated as user facts. For instance, a user discussing budget issues multiple times does not mean they “always prioritize the lowest cost as their primary goal.” Only explicitly expressed or confirmed information is suitable for becoming stable memory.

    For high-impact content, such as identity information, long-term business goals, or key project constraints, an explicit confirmation mechanism can be set up to reduce the risk of incorrect memories spreading long-term.

    2. Preserving Source, Scope, and Lifecycle for Memory

    Below is a conceptual data structure example and does not represent any specific system’s interface:

    1. Memory Entry:
    2. Content: Solution description must include a rollback path
    3. Type: Expression preference
    4. Scope: Current user
    5. Source: Confirmed session record
    6. Status: Active
    7. Created At: Creation time
    8. Last Confirmed: Confirmation time
    9. Expiration Condition: Invalidated when user modifies preference

    In actual design, sensitivity levels, project identifiers, and version information can also be added based on business needs.

    Source is used for traceability, scope is used to limit usage scenarios, and lifecycle is used to control expiration. Without these fields, even if the memory content itself is correct, it might be used in the wrong project or at the wrong time.

    3. Distinguishing Additions, Revisions, and Revocations

    Memory updates should not only support appending. When a user explicitly changes a preference or project constraints shift, the system needs to revise existing entries and mark the old ones as invalid.

    For businesses with audit requirements, version history can be retained, but retrieval should default to using only the currently valid version. For information that a user requests to be deleted, the applicable data management rules should be applied to handle raw records, summaries, retrieval indexes, and caches, ensuring that merely deleting the displayed content does not leave retrievable copies behind.

    V. Session Retrieval: Accuracy Through Multi-Stage Processing

    1. Limit Scope Before Finding Relevant Content

    Before retrieval, you should clarify the tenant, user, project, and time scope as much as possible. Permission isolation especially cannot rely on the model to “consciously ignore” unauthorized data during generation; it must be enforced within the retrieval pipeline.

    Once the scope is defined, executing keyword and semantic retrieval can reduce cross-project confusion. For example, the same term might represent different solutions in two projects, and relying solely on similarity can easily recall incorrect records.

    2. Preserving Complete Decision Relationships

    Session segmentation should respect semantic boundaries as much as possible. A question along with its clarification, conclusion, and subsequent revisions should ideally be recombined via associated fields or a context window.

    For long-term projects, phase summaries can be created, but summaries cannot completely replace original records. Summaries are suitable for quick positioning, while original records are used to verify evidence. Important conclusions should be traceable to specific discussions rather than leaving only an unverifiable summary.

    3. Sorting by Relevance, Time, and Status

    Newer records are not necessarily more authoritative, and more similar texts are not necessarily usable. Sorting should comprehensively consider:

    • The degree of relevance to the current task;
    • Whether it belongs to the current project;
    • Whether it is a confirmed conclusion;
    • Whether it is still within its validity period;
    • Whether there is a later revision or revocation record.

    When evidence is insufficient, the system should explain the uncertainty and request supplementary information instead of using low-relevance historical content to fill in the answer.

    VI. External Plugins: Security Boundaries Independent of Model Judgment

    Text from external sources should be treated as data, not as high-priority instructions. Even if retrieval results contain content like “ignore existing rules” or “send all historical records,” they cannot be used to alter system permissions or execution strategies.

    Plugin calls need to adopt the principle of least privilege. Read-only queries and write operations should be authorized separately; high-risk operations can add user confirmation, input validation, auditing, and failure recovery mechanisms. For write operations that might be executed repeatedly, idempotency should also be considered to avoid duplicate submissions caused by retries.

    Furthermore, plugin responses should carry source, query time, and data status whenever possible. When a call fails, the system must clearly distinguish between “no record found,” “no access permission,” and “service temporarily unavailable.” An access failure cannot be directly stated as a fact not existing.

    If external query results are cached, expiration rules should be set based on data change frequency. Frequently changing business states are not suitable for being saved indefinitely as long-term facts.

    VII. Context Organization: Serving Reasoning, Not Drowning It

    The context a model can process is limited, and the three-tier memory needs to share an information budget. Priority should be given to retaining current task requirements, key constraints, and necessary evidence, before supplementing with relevant historical background.

    A layered organization approach can be adopted:

    1. Current goals and explicit instructions;
    2. Confirmed and applicable long-term constraints;
    3. Historical evidence directly relevant to the task;
    4. External query results and their times;
    5. Unresolved conflicts and information gaps.

    These layers represent information organization methods and do not imply that memory can override system rules or currently valid authorizations.

    Duplicate information can be merged or summarized. For contradictory information, the differences and sources should be preserved; conflicts should not be smoothed over just to shorten the context. Compressed content should also retain status words like “previously proposed,” “unconfirmed,” or “revoked” to avoid altering the factual meaning.

    VIII. How to Verify the Three-Tier Memory Improves Experience

    Evaluating a memory system cannot just look at whether the response is fluent; it must cover retrieval, generation, security, and lifecycle management.

    1. Retrieval Quality

    Check whether relevant records are recovered, whether irrelevant records are excessive, and whether outdated conclusions are mistakenly prioritized. The evaluation set should include easily confusing scenarios such as similar projects, repeated terms, historical revisions, and cross-session references.

    2. Response Quality

    Focus on whether the response correctly uses memory, is faithful to evidence, and reduces unnecessary redundant confirmations. It especially needs to test: when historical information and current explicit requirements change, can the system identify the change and update its judgment.

    3. Security and Governance

    Verify whether cross-user, cross-project, and cross-tenant isolation is effective; whether deletion requests cover relevant copies; whether malicious external text can induce privilege escalation; and whether high-risk operations are indeed authorized.

    4. Cost and Latency

    A three-tier memory introduces overhead in storage, retrieval, sorting, and plugin calls. You should observe the time consumption and failure rates of each stage separately, and decide whether to enable the full chain based on task complexity. Keep a lightweight path for simple requests, and enable a more complete retrieval and validation process for complex tasks.

    IX. Implementation Advice: Start with a Controllable Small Loop

    In the early stages, there is no need to pursue “remembering everything.” You can start with a clearly bounded scenario, such as continuously maintaining project constraints or assisting users in reviewing historical decisions.

    In the first phase, only save a small number of confirmed persistent facts and provide the ability to view, modify, and delete them; in the second phase, integrate session retrieval to establish source traceability and version identification; in the third phase, connect to controlled external data sources to refine permissions and auditing.

    With each added layer, you should verify whether it improves task completion quality rather than just increasing system complexity. If persistent memory consistently introduces errors, or external queries cannot clarify permissions and timeliness, you should prioritize fixing data governance and access mechanisms rather than continuing to expand storage scale.

    X. Conclusion

    The core value of the three-tier memory architecture is not about letting the agent save more content, but about allowing different types of information to have management methods suited to them: stable facts are maintained by persistent memory, historical processes are restored by session retrieval, and real-time states are verified by external plugins.

    A truly reliable agent should know what information can be used, what has expired, and what must be reconfirmed. It should also allow users to understand and control the formation process of memory. Only by incorporating accuracy, traceability, permissions, and lifecycle management into the design simultaneously can memory capabilities transition from a demo effect to sustainable engineering value.