Agent Memory: A Survey of Cognitive Modeling and Long-Term Evolution

    This article summarizes recent research on agent memory, framing it as a cognitive modeling problem rather than a storage component. It clarifies the boundaries between agent memory and model-level memory optimization, retrieval-augmented generation, and context engineering, then presents a layered architecture, write and forgetting strategies, retrieval workflows, and evaluation metrics for building memory systems that persist and evolve across sessions.

    1. Background: Why Memory Has Become the Key Bottleneck for Agents

    A recent survey from several leading research institutions identifies agent memory as the core dividing line between a model that can answer questions and a system that can take on long-running tasks. The reason is straightforward: improvements in single-pass reasoning have been heavily engineered, while maintaining state across sessions and cycles still lacks a unified paradigm. An agent that starts from zero in every interaction cannot accumulate user preferences, correct its strategy after failures, or stay aligned with a goal over long horizons.

    The key point is that memory is not a storage component problem but a cognitive modeling problem. Storage is only the carrier. The hard part is deciding what is worth remembering, in what form, when it should be retrieved, and when it should be revised or discarded. This article uses three contrasts from the source material as its backbone and reorganizes them into a practical technical guide.

    2. Three Conceptual Distinctions: Drawing Clear Boundaries

    2.1 Agent Memory vs. Model-Level Memory Optimization

    On the model side, so-called “memory” is essentially an engineering optimization at the level of inference efficiency and capacity: reusing key-value caches to reduce repeated computation, or using new sequence modeling architectures to extend the context length that can be processed. Its metrics are GPU memory usage, throughput, and latency. Its scope is limited to a single inference pass, and it is released when the session ends.

    Agent memory is a persistent, dynamically evolving cognitive state that exists across multiple interaction cycles. It carries at least three types of content: identity and role settings (“who I am and what task I am executing”), experience and event traces (“what I have done and what the results were”), and object-level preferences and constraints (“what the user likes and which approaches have been explicitly rejected”).

    The key difference can be summarized as follows: the former optimizes how fast and how cheaply this one pass runs, while the latter addresses whether the next interaction can build on history.

    2.2 Agent Memory vs. Retrieval-Augmented Generation

    Retrieval-augmented generation typically appears as bolt-on, static knowledge access. Common forms in the industry include modular retrieval, graph-based retrieval, and agent-driven retrieval pipelines. It targets the knowledge base problem: the document collection is relatively fixed, retrieval mostly serves a single task, and the knowledge itself is rarely rewritten by interactions.

    Agent memory grows dynamically. Every interaction can trigger three types of write operations: adding new experience entries, revising existing knowledge, and decaying and forgetting information that is no longer important. It therefore emphasizes interaction history and experience accumulation, with the write path as important as the retrieval path. A practical rule of thumb: if the knowledge does not change because “you talked to it,” it is a retrieval store; if it does change, it is memory.

    2.3 Agent Memory vs. Context Engineering

    Context engineering is a resource management technique. Under a limited window capacity, it uses prompt compression, importance filtering, structured reordering, and similar methods to fit the most valuable information into limited space. It answers the question of how to fit things in.

    Agent memory is cognitive modeling, and it answers what should be included and why it is worth retaining long term. The two are complementary: memory generates and governs the candidate set, while context engineering performs optimal assembly under a given budget. Without memory, context engineering can only optimize over fragments from the current session; without context engineering, even complete memory cannot be used effectively within a limited window.

    3. A Layered Architecture for Memory

    A sound engineering practice is to use layers rather than putting all information into one large table:

    • Working memory: intermediate state for the current task, tool call results, to-dos, and assumptions. It has a short lifecycle and is archived or discarded when the task ends.
    • Episodic memory: records events as units, capturing “what was done, the trigger conditions, the result, and the failure reason.” It is the main source of experience reuse.
    • Semantic memory: stable conclusions distilled from multiple episodes, such as user preferences, domain conventions, and common knowledge about system topology.
    • Procedural memory: reusable strategies and process templates, expressed as “when encountering a certain class of problem, follow certain steps.”

    The core value of layering is that write and forgetting strategies can be differentiated: working memory is evicted by capacity, episodic memory decays by time and utility, semantic memory requires conflict resolution, and procedural memory requires version management.

    4. Writing, Consolidation, Forgetting, and Retrieval

    4.1 Write Decisions

    Not every conversation is worth persisting. Practical decision dimensions include: whether a new user constraint is produced, whether it contains a verifiable result, whether it revises an existing entry, and whether it has cross-session reuse value. Example logic:

    1. def should_write(turn, existing_memory):
    2. if turn.has_user_constraint: # explicit preference or prohibition
    3. return "semantic"
    4. if turn.task_succeeded or turn.failed: # a result worth reviewing
    5. return "episodic"
    6. if conflicts_with(turn, existing_memory):
    7. return "semantic_update" # go through conflict resolution
    8. return None # do not write, avoid noise buildup

    4.2 Consolidation and Conflict Resolution

    When the same fact appears multiple times, it should be merged with a confidence update rather than appended indefinitely. A common strategy is to keep the source and timestamp, weight old and new conclusions by credibility, and downgrade to “pending confirmation” when a conflict cannot be resolved automatically, proactively clarifying in later interactions.

    4.3 Forgetting

    Forgetting is a feature, not a defect. It can be governed by three curves: time decay, access frequency, and a utility score (whether the memory actually changed the output after being retrieved). Low-utility entries should be compressed into summaries or archived to cold storage to control retrieval noise and cost.

    4.4 Retrieval

    Retrieval needs to be coordinated with the context budget: first a coarse filter (vector or keyword recall), then re-ranking (weighting relevance and recency), and finally assembly according to the remaining window. A sound practice is to attach metadata to memory entries (source, time, confidence, applicable scope) so the model can judge whether a given piece of experience applies to the current scenario.

    5. Evaluation and Observability

    A memory system must be measurable, otherwise it cannot be iterated on. At a minimum, cover four categories of metrics: recall quality (whether what should be remembered was remembered), write precision (the noise ratio), reuse benefit (changes in task success rate and step count after referencing memory), and timeliness (whether expired information is correctly decayed). Also make memory reads and writes traceable logs, with monitoring and alerting, to help determine whether something was “remembered incorrectly” or “retrieved incorrectly.”

    6. Implementation Recommendations

    When building on general-purpose cloud capabilities, object storage can carry cold memory archives, a message queue can decouple the write pipeline, a container platform can host the memory service and retrieval service, and the logging and monitoring system can handle observability; on the model side, rely on general long-context and caching optimization capabilities. Baidu AI Cloud provides a complete set of foundational capabilities in these general categories, making it easier to build the memory layer as an independently evolvable module rather than coupling it with business logic.

    In summary, the difficulty of agent memory lies not in storage but in governance. Drawing the conceptual boundaries clearly, defining the layered structure, making write and forgetting strategies solid, and closing the evaluation loop are what allow an agent to genuinely grow across cycles.