Agent Memory Architecture: From Vector Retrieval to Reasoning-Enhanced Recall

    This article explains why session-scoped agents lose context between conversations and why vector similarity search alone is not enough. It presents a three-part memory design—retain, recall, and reflect—a four-layer memory model, and the engineering essentials for storage, interfaces, concurrency, observability, and privacy, along with common pitfalls and how to evaluate a memory system.

    1. Where the Problem Starts: Why Agents “Forget” After a Session Ends

    Most agents today behave as stateless systems at the interaction layer. When a session ends, the context window is released, and the user identity, prior conclusions, and confirmed facts all reset to zero. The next conversation has to rebuild context from scratch. This is not just a shortcut in implementation; it is a fundamental limit on capability. Breaking that limit requires a persistent memory layer whose lifecycle is independent of any single session.

    A memory layer is not only about “storing things.” It has to answer three questions: what to store, how to retrieve, and how to use what was retrieved. Solve only the first and the system degrades into an expensive log repository. Solve only the second and it degrades into a similarity matcher. Usable memory must cover write policy, recall policy, and reasoning policy at the same time.

    2. Why Vector Similarity Retrieval Is Not Enough

    The common industry approach is to chunk text, encode it into vectors, store it, and recall by similarity. It performs well on approximate semantic matching, but it has three structural weaknesses.

    The first is the missing time dimension. A vector space has no built-in timeline, so “a decision made last month” and “a decision made yesterday” may be nearly equivalent in similarity, which leads the agent to cite outdated conclusions.

    The second is disconnected facts. If a user says “fire gives off light” and later says “fire is hot,” the two facts become separate points in the vector space and are not necessarily close to each other. The agent therefore struggles to derive a conclusion that requires combining facts across records, such as “something that glows may also be hot.” When the relationships between facts are not expressed explicitly, reasoning has nothing to work on.

    The third is weak handling of updates and invalidation. Facts change: addresses move, preferences shift, conclusions get overturned. A pure vector approach can usually only append, and cannot express “the new value replaces the old one” or “this fact is no longer valid.” The result is a recall set full of mutually contradictory fragments.

    3. Target Architecture: Retain, Recall, Reflect

    Practical memory capability can be abstracted into three core operations: retain, recall, and reflect. All three operate on an independent memory space bound to a business entity. That space is decoupled from any single session, and its lifecycle is determined by business policy.

    1. Session input
    2. │
    3. ├─ retain(content, metadata) → fact extraction / deduplication / conflict resolution / layered storage
    4. │
    5. ├─ recall(query, constraints) → multi-path recall / time filtering / permission filtering / reranking
    6. │
    7. └─ reflect(question, context) → relation composition / temporal reasoning / conclusion generation / write-back of new facts

    The key to the write stage is not “store everything” but extraction and governance: turn raw conversation into structured fact entries carrying the entity identifier, timestamp, source, confidence, and lifecycle status. Merge duplicate information, and mark conflicting information explicitly rather than silently overwriting it.

    The key to the recall stage is “multiple paths plus constraints.” Semantic recall handles approximate matching, while structured recall handles exact conditions such as time ranges, entities, categories, and status. Results from both paths are merged and then reranked together. Permission and tenant isolation must be enforced in the recall layer, not left to the application layer to “remember to filter.”

    The reflect stage is the key addition. It lets the model perform multi-hop composition and temporal comparison on top of retrieved results, then writes the new conclusions back as new memory entries, forming a positive feedback loop.

    4. A Layered Memory Model: Making “Memory” Governable

    It helps to split memory into four layers, each with its own write and eviction policy.

    Working memory holds the current session context. It is small, short-lived, and released when the session ends. Episodic memory records “what happened,” organized by event with time and entity preserved, and serves as the basis for temporal reasoning. Semantic memory accumulates “what is true,” meaning confirmed facts and preferences, and must support updates and invalidation. Procedural memory stores “how to do it,” meaning reusable operating procedures and tool-invocation patterns, usually held as structured templates.

    The direct benefit of layering is control. Capacity and cost are allocated per layer: hot data stays in the low-latency layer while cold data sinks to cheaper storage. Governance rules are also defined per layer—semantic memory requires conflict resolution, while episodic memory only requires immutability and traceability.

    5. Engineering Implementation Notes

    For storage, a combination of a structured database, a vector index, and object storage works well. The structured database holds metadata and lifecycle status, the vector index holds semantic retrieval, and object storage holds raw payloads and audit material. Data consistency across the three is aligned through a unified write identifier.

    For interface design, keep the semantics of the three core operations stable while allowing the internal implementation to be replaced:

    1. def retain(memory_bank_id: str, content: str, meta: dict) -> str:
    2. """Extract facts, deduplicate, resolve conflicts, write to the given memory
    3. space, and return the entry identifier."""
    4. ...
    5. def recall(memory_bank_id: str, query: str,
    6. time_range: tuple | None = None,
    7. top_k: int = 8) -> list[dict]:
    8. """Run multi-path recall, rerank by relevance and recency, and return entries
    9. with source and time."""
    10. ...
    11. def reflect(memory_bank_id: str, question: str) -> dict:
    12. """Perform multi-hop and/or temporal reasoning over recall results, return the
    13. conclusion with its evidence chain, and write back new facts."""
    14. ...

    For consistency and concurrency, writes for the same entity should be serialized or use optimistic concurrency control with version numbers, so concurrent updates do not scramble facts. For observability, every recall should log the query, the matched entries, the rerank scores, and the final citations, so it is possible to trace back why the agent answered the way it did. For privacy and compliance, support per-entity memory export and complete deletion; deletion must cover the vector index and caches, not just the primary database record.

    6. Common Pitfalls and How to Evaluate

    Pitfall one: treating “store more” as “remember better.” Ungoverned appending makes recall quality decline monotonically over time. Pitfall two: leaving recency to the model’s own judgment. Time filtering must be enforced by retrieval conditions. Pitfall three: skipping evaluation. Build an evaluation set covering temporal questions, multi-hop composition questions, and conflict-update questions, and measure recall hit rate, reasoning accuracy, and stale-citation rate separately.

    7. Conclusion

    The essence of cross-session memory is making both facts and the relationships between facts first-class citizens. Vector retrieval handles approximate matching, structured constraints handle time and status, and the reflection mechanism handles relationships and reasoning. Only when the three are combined can an agent move from “starting from zero every time” to sustainable accumulation. To build this on Baidu AI Cloud, the layered memory system above can be assembled from general capabilities such as object storage, container platforms, log services, and monitoring and alerting, keeping the interfaces neutral and the implementation replaceable to avoid tight coupling to a single solution.