AI Agents

An AI agent is a system that uses a model to choose actions in an environment. Agents often combine reasoning, memory, tools, retrieval, and feedback so they can complete multi-step tasks.

How does an agent decide what information to forget?

An AI agent should forget information when keeping it no longer provides enough future value to justify the cost, risk, or confusion of retaining it . Good memory systems do not only decide what to remember. They also remove, expire, replace, or deprioritize memories that are no longer useful. 1. Forget information that is no longer relevant Some information matters only for a temporary task. For example: a one time search result an intermediate calculation a temporary error message a completed task's retry count Once the task ends, these details may have little future value. They can usually be removed instead of becoming durable memory. 2. Forget stale information Memories can become outdated. For example: Old memory: Project uses PostgreSQL 14. Later: New information: Project upgraded to PostgreSQL 16. The old memory should be replaced or invalidated so it does not continue influencing future decisions. 3. Remove duplicate memories Keeping many versions of the same fact can make retrieval noisy. Instead of storing: User prefers Python. User likes Python examples. Use Python for code examples. the system can preserve one clear memory: Preferred code language: Python Deduplication keeps memory smaller and easier to retrieve. 4. Expire time sensitive memories Some information is useful only for a limited period. Examples include: temporary availability short lived preferences expiring credentials metadata temporary project assignments session specific constraints These memories can be given an expiration time. After that point, they should either be removed or treated as needing fresh verification. 5. Forget memories that are rarely useful A memory that is repeatedly stored but almost never retrieved may not justify permanent retention. A system may track signals such as: last time the memory was used how often it is retrieved whether it improved decisions whether newer information has replaced it Low value memories can then be removed or archived. 6. Remove memories that are incorrect An agent may sometimes store a wrong inference. For example: Stored memory: User always wants PDF output. Later the user says: Correction: Use CSV unless I specifically ask for PDF. The incorrect memory should not remain active. Memory should be correctable. 7. Prefer replacement over keeping conflicting versions When a newer authoritative fact supersedes an older one, keeping both can create confusion. For example: Old: Deployment region = us east 1 New: Deployment region = ap south 1 If the new value is confirmed, the old one should normally be replaced rather than retrieved alongside it. In some systems, the old version may remain in an audit history while no longer being treated as active memory. 8. Forget information that creates unnecessary privacy risk Some information may be technically useful but inappropriate to retain. A memory system should consider: whether the information is sensitive whether retention is necessary whether the user or organization permits storage how long it should be retained who is allowed to access it Data minimization is an important part of memory design. 9. Forget information outside its valid scope A memory may become invalid when its scope ends. For example: A temporary project preference should not remain active after the project is finished. Similarly, information belonging to one user, tenant, or project should not be reused outside that scope. 10. Summarize instead of keeping every detail For long histories, forgetting does not always mean deleting everything. Several detailed memories can sometimes be compressed into one useful summary. For example, instead of storing ten separate troubleshooting episodes, the system might retain: Summary: Most failures were caused by expired credentials; credential validation should happen early. This preserves the useful lesson while removing unnecessary detail. 11. Use importance and confidence Important, high confidence memories may deserve longer retention. Low confidence or weakly inferred memories may expire sooner. For example: High confidence: The user explicitly stated a permanent preference. Low confidence: The agent inferred a preference from one interaction. Retention policy can reflect this difference. 12. Forgetting may mean deletion, expiration, or lower retrieval priority Not every memory system uses literal deletion. A memory may be: permanently deleted marked expired replaced by a newer version archived assigned lower retrieval priority kept only for audit history The important point is that outdated or low value information should stop influencing normal agent decisions. A practical forgetting decision A memory system can periodically ask: Is this information still relevant? Is it still correct? Has newer information replaced it? Has it expired? Is it duplicated elsewhere? Is it sensitive and no longer necessary? Has it been useful recently? Does retaining it improve future decisions? If the answer is mostly no, the memory is a candidate for removal or deactivation. In short An agent should forget information when it becomes stale, irrelevant, duplicated, incorrect, expired, unnecessarily sensitive, or no longer useful enough to influence future tasks. Effective forgetting keeps memory accurate, compact, safe, and relevant instead of allowing old information to accumulate forever.

What is memory retrieval in an AI agent?

Memory retrieval in an AI agent is the process of finding relevant stored memories and bringing the most useful ones into the agent's current context. An agent may store many memories, but only a small subset should normally be retrieved for the task at hand. Why retrieval is needed Stored memory has value only if the agent can find the right information when it becomes useful. For example, an agent may remember: user preferences previous decisions project facts past task outcomes reusable procedures When a new task begins, the system needs to determine which of those memories are relevant. Example Suppose an agent receives: Task: Prepare a technical report. The memory system may retrieve: preferred format: concise preferred code language: Python include executive summary It should not retrieve unrelated memories about travel planning or an old billing issue. The goal is relevance, not volume. Retrieval usually starts from the current task The current request, goal, or workflow state can be used as the retrieval query. For example: Current task: Deploy Project Alpha. The system may search memory for information related to: Project Alpha deployment procedure deployment constraints previous deployment issues This helps the agent bring useful past knowledge into the current decision. Memory can be retrieved in different ways Depending on the architecture, retrieval may use: exact key lookup metadata filters keyword search semantic similarity vector search recency importance scores user or project scope Many systems combine several signals. Scope should be applied before relevance The system should first ensure that the memory belongs to the correct: user project tenant organization workflow Only then should it rank memories for relevance. This prevents unrelated or unauthorized memories from being considered. Relevance is usually the main ranking signal A retrieved memory should help answer the current task. For example: Current task: Debug a database timeout. Useful memories may include: database type previous timeout incidents known connection pool limits troubleshooting procedure A memory about report formatting is probably irrelevant. Recency can matter When two memories describe the same information, the newer one may be more useful. For example: Older memory: Project uses PostgreSQL 14. Newer memory: Project upgraded to PostgreSQL 16. The retrieval system should normally prefer the newer valid memory. Recency is useful, but newer does not automatically mean more authoritative in every case. Importance can matter Some memories may deserve higher retrieval priority because they strongly affect decisions. Examples include: safety constraints approval requirements important user preferences critical project rules These can be weighted more heavily than minor historical details. Similarity alone is not enough A semantically similar memory may still be wrong for the current scope. For example, a deployment procedure for Project B may look very similar to a procedure for Project A. If the projects have different approval rules, blindly retrieving the closest match could cause an error. Good retrieval combines relevance with metadata and scope. Retrieved memories become part of context The model can only use a memory if the system makes it available during the current step. A common flow is: 1. Receive current task. 2. Search stored memories. 3. Filter by scope. 4. Rank by relevance. 5. Select the best few memories. 6. Add them to the active context. 7. Let the agent reason using them. The full memory store does not need to be placed into the prompt. Retrieval should be selective Too many retrieved memories can hurt performance. They can create: noisy context conflicting information higher token usage weaker focus increased latency It is usually better to retrieve a small set of highly relevant memories than a large set of loosely related ones. Retrieved memories may need validation Memory should not always be treated as current truth. Before using an important memory, the agent may need to check: whether it is stale whether a newer memory exists whether the source is trustworthy whether the fact should be verified externally For example, a stored shipping address may need confirmation if the user provides a different address in the current request. Retrieval can happen more than once An agent does not need to retrieve every useful memory at the start of a workflow. It can retrieve memory when the current step requires it. For example: Planning step: Retrieve project constraints. Tool selection step: Retrieve known tool preferences or failures. Final response step: Retrieve output format preference. This keeps context focused. Memory retrieval vs. memory storage Memory storage decides what information should be saved. Memory retrieval decides which saved information should be brought back when needed. A good memory system needs both. Storing everything without good retrieval creates noise. Having excellent retrieval with poor quality memories still produces poor results. In short Memory retrieval in an AI agent is the process of finding, filtering, ranking, and selecting stored memories that are relevant to the current task, then adding them to active context. Effective retrieval considers relevance, scope, recency, importance, and validity so the agent uses useful past information without flooding its context with unnecessary memory.

What is memory consolidation in agent systems?

Memory consolidation in agent systems is the process of turning raw, repeated, or fragmented memories into cleaner, more stable, and reusable knowledge. Instead of keeping every past event as a separate memory forever, the system can combine related information and preserve the most useful result. Why consolidation is needed Over time, an agent may accumulate many memories: repeated user preferences similar task outcomes multiple observations about the same project several troubleshooting episodes old and new versions of the same fact If all of these remain separate, retrieval can become noisy and inefficient. Consolidation reduces that clutter. Example Suppose an agent has these memories: Deployment failed because an environment variable was missing. Another deployment failed because configuration validation was skipped. A third deployment succeeded after validating environment variables first. Instead of keeping only three isolated episodes, the system may consolidate them into: Reusable knowledge: Validate required environment variables before deployment. The individual episodes may still be retained for audit or detailed history, but the consolidated memory is easier to reuse. Consolidation can summarize repeated experiences A group of episodic memories can sometimes be converted into more general knowledge. For example: Episodes API timed out during a large batch. API timed out again during another large batch. Smaller batches completed successfully. Consolidated memory Use smaller batches with this API to reduce timeout risk. This turns repeated experience into a reusable lesson. Consolidation can merge duplicate memories An agent may store similar versions of the same fact. For example: User prefers concise reports. User likes short technical reports. User asked multiple times to avoid long explanations. These can be consolidated into: Preference: Keep technical reports concise. This makes later retrieval cleaner. Consolidation can resolve newer and older facts Memories can change over time. For example: Older memory: Project uses PostgreSQL 14. Newer memory: Project upgraded to PostgreSQL 16. A consolidation process can keep the current fact active and mark the older version as historical rather than retrieving both as if they were equally valid. Consolidation can create higher level knowledge Raw memories are often specific. Consolidation can extract the useful pattern. For example: Raw memories Tool A failed twice for a particular data source. Tool B succeeded repeatedly. Consolidated knowledge Prefer Tool B for this data source. This is more useful for future planning and tool selection. Consolidation should preserve important distinctions Not every similar memory should be merged. For example: Project A requires manual deployment approval. Project B allows automatic deployment. These should remain separate because they apply to different scopes. Good consolidation respects: user project tenant domain time source confidence Consolidation can reduce retrieval noise Without consolidation, a retrieval system may return many nearly identical memories. That can: waste context space increase token usage create duplicated signals make conflicts harder to detect A consolidated memory gives the agent a smaller, clearer representation. Consolidation can be periodic or event driven A system may consolidate memories: after a workflow completes after several similar memories appear when memory storage becomes large on a scheduled maintenance cycle when conflicting memories are detected The best timing depends on the application. Consolidation may keep source links A useful design is to let a consolidated memory point back to the memories it came from. For example: Consolidated memory: Validate environment variables before deployment. Derived from: Episodes 104, 122, and 137. This preserves traceability while still giving the agent a compact memory for everyday retrieval. Consolidation is not the same as forgetting Forgetting removes or deactivates information that no longer has enough value. Consolidation combines useful information into a better representation. For example: Forgetting: Remove an expired temporary preference. Consolidation: Merge five similar deployment lessons into one reusable rule. The two processes can work together. Consolidation is not the same as retrieval Retrieval selects useful memories for the current task. Consolidation improves how memories are stored over time. Better consolidation can make retrieval more accurate because the memory store contains fewer duplicates and clearer knowledge. Consolidation should handle uncertainty carefully An agent should not convert one weak observation into a strong general rule. For example: One failed API call does not necessarily justify: Rule: This API is unreliable. A better system may require: repeated evidence strong confidence authoritative confirmation human review for important knowledge This prevents incorrect generalizations. In short Memory consolidation in agent systems is the process of merging, summarizing, updating, and generalizing stored memories so the memory store becomes more compact, consistent, and useful over time. It can turn repeated experiences into reusable knowledge, remove duplication, preserve the latest valid facts, and improve future memory retrieval.

How can stale memory affect an AI agent?

Stale memory can hurt an AI agent by making it rely on information that was once correct but is no longer valid. Because retrieved memories can influence planning, tool use, and final decisions, outdated information can quietly push the agent in the wrong direction. Example Suppose an agent remembers: Deployment region: us east 1 Later, the project moves to: Deployment region: ap south 1 If the old memory is still retrieved, the agent may prepare the wrong deployment plan or call tools with incorrect parameters. The problem is not that the memory was originally wrong. It became wrong over time. Stale memory can cause incorrect decisions An outdated memory may affect: planning recommendations tool selection tool arguments routing approvals final responses For example, an agent may remember an old pricing plan and recommend an option that is no longer available. It can conflict with current information A common problem is when memory says one thing while the current context says another. For example: Memory: User prefers PDF. Current request: Export this as CSV. The current instruction should normally take priority. If the system does not handle conflicts properly, the stale memory may override fresher information. It can cause repeated mistakes Suppose a memory says: Preferred API endpoint: v1/orders But the system has migrated to: Current endpoint: v2/orders If that memory is repeatedly retrieved, the agent may keep generating invalid calls. This turns one outdated fact into a recurring failure. Stale procedural memory is especially risky Procedural memory describes how to perform tasks. If the process changes but the stored procedure does not, the agent may continue following an obsolete workflow. For example: Old procedure: Deploy directly after tests pass. New procedure: Human approval is required before production deployment. Using the old procedure could bypass an important control. Stale episodic memory can mislead reasoning Past experiences may no longer represent the current environment. For example: A previous incident may have been solved by restarting a service. Months later, the architecture changes. Retrieving the old episode may still be useful as background, but the agent should not assume the same fix will work now. Stale semantic memory can spread incorrect facts Semantic memory often contains reusable facts. Examples include: project technology region ownership policies preferences configuration If these facts are outdated, many future tasks can be affected because the same memory may be reused repeatedly. Recency alone is not always enough The newest memory is often more useful, but newer does not automatically mean correct. A good system may also consider: source authority confidence scope timestamp explicit user correction whether the information has been verified For example, an authoritative project configuration may be more reliable than a newer weak inference. Important memories may need revalidation Some memories should be checked before use when the cost of being wrong is high. Examples include: permissions deployment settings financial limits account status security policies current addresses pricing credentials related metadata The more time sensitive or high impact the information is, the more useful fresh verification becomes. Memories should support replacement or invalidation When new information supersedes old information, the system should not simply keep both as equally active memories. It may: update the existing memory mark the old memory as expired lower its retrieval priority preserve it only as historical information attach a validity period This helps retrieval prefer the currently valid fact. Expiration can reduce staleness Some memories can include a time to live or review date. For example: Memory: Temporary project owner = Alex Valid until: End of quarter After expiration, the agent should either stop using the memory or verify it before relying on it. Current context should usually outrank stale memory If the user or an authoritative tool provides fresh information, that information should generally take precedence over older memory. For example: Stored memory: Preferred language = Python Current request: Use TypeScript for this example. The current request should control the immediate task. Memory retrieval should consider freshness A retrieval system can use freshness as one ranking signal. Instead of ranking only by semantic similarity, it may also consider: relevance recency confidence source authority scope validity status This reduces the chance that an old but highly similar memory dominates the result. In short Stale memory can cause an AI agent to make incorrect decisions, follow outdated procedures, use wrong tool parameters, or conflict with current information. Reliable memory systems should support timestamps, replacement, invalidation, expiration, and revalidation so old information does not continue influencing the agent after it stops being true.

How can conflicting memories be handled by an agent?

Conflicting memories occur when an AI agent has two or more stored memories that disagree about the same fact, preference, rule, or past outcome. A reliable agent should not simply pick one at random. It should compare the memories using signals such as freshness, source authority, confidence, and scope. Example Suppose the agent stores: Memory A: Project Alpha uses PostgreSQL 14. Later it stores: Memory B: Project Alpha uses PostgreSQL 16. If both are retrieved, the agent needs to determine which one is currently valid. In this case, the newer confirmed memory may replace the older one. 1. Check whether the memories really conflict Two memories may look contradictory but apply to different contexts. For example: Memory A: Project Alpha uses Python. Memory B: Project Beta uses TypeScript. These are not conflicting because they belong to different projects. Before resolving a conflict, the agent should check scope such as: user project tenant environment time period task 2. Prefer newer information when appropriate If the same fact changed over time, the newer memory is often more relevant. For example: Old: Deployment region = us east 1 New: Deployment region = ap south 1 The older value can be marked historical while the newer value remains active. However, newer should not automatically win if its source is unreliable. 3. Prefer more authoritative sources Source quality can matter more than recency. For example: Memory A: The agent inferred that production approval is optional. Memory B: The organization's deployment policy explicitly says approval is required. The policy should take priority because it is more authoritative. 4. Use confidence levels Memories can carry confidence information. For example: High confidence: User explicitly stated, “Always use CSV.” Low confidence: Agent inferred a CSV preference from one previous interaction. If these conflict, the explicit statement should normally take priority. 5. Current instructions usually override old memory The current request is often the freshest source of user intent. For example: Stored memory: User prefers Python examples. Current request: Show this example in Java. The agent should follow the current request for this task rather than forcing the old preference. 6. Replace or invalidate outdated memories Once a conflict is resolved, the system should avoid repeatedly retrieving both memories as if they were equally valid. It may: update the existing memory mark the older memory as inactive lower its retrieval priority add a validity period keep it only as historical information This prevents the same conflict from appearing again. 7. Preserve history when it matters Resolving a conflict does not always mean deleting the old memory. For audit or historical analysis, a system may keep: Previous value: PostgreSQL 14 Current value: PostgreSQL 16 Only the current value should normally influence current tasks. 8. Ask for clarification when the conflict cannot be resolved Sometimes there is not enough evidence to choose safely. For example: Memory A: Preferred report format = PDF Memory B: Preferred report format = DOCX If both are recent, equally reliable, and the current task depends on the answer, the agent may ask the user which preference is current. This is better than silently guessing. 9. Treat high impact conflicts more carefully Conflicts involving high impact information should often require fresh verification. Examples include: financial limits access permissions security policies deployment approval requirements account ownership legal or compliance rules The cost of choosing the wrong memory is higher in these cases. A practical conflict resolution order An agent can evaluate conflicting memories using this sequence: 1. Check whether they belong to the same scope. 2. Check whether one is explicitly newer. 3. Compare source authority. 4. Compare confidence. 5. Consider current instructions or live data. 6. Validate externally when the fact is important. 7. Ask for clarification if the conflict remains unresolved. 8. Update or invalidate the losing memory. In short Conflicting memories should be resolved using scope, freshness, source authority, confidence, and current evidence rather than arbitrary selection. When the conflict cannot be resolved reliably, the agent should avoid guessing and seek clarification or fresh verification before acting.

How can agent memory be scoped to a user or session?

Agent memory can be scoped by attaching each memory to the identity or execution boundary it belongs to, such as a specific user, session, project, or tenant. This ensures the agent retrieves only memories that are valid for the current context. User scoped memory User scoped memory belongs to one specific user and may remain available across multiple sessions. Examples include: preferred language preferred output format recurring instructions stable preferences user specific project facts A memory record may include a field such as: user id = user 123 When the agent retrieves memory for that user, it filters by the same user identifier. This prevents another user's memories from appearing in the result. Session scoped memory Session scoped memory belongs only to a particular conversation or execution session. Examples include: temporary goals current discussion context one time constraints recent choices intermediate conclusions A session scoped memory may include: session id = session 456 When the session ends, these memories may expire or become inaccessible to future sessions. Example Suppose a user says: “For this conversation, use Java.” That may be session scoped. Later the same user starts a new conversation. The agent should not automatically assume Java is still preferred. But if the user says: “I always prefer Python examples.” that may be appropriate as user scoped memory because it is intended to persist across sessions. Scope should be stored explicitly A memory record can include metadata such as: user id session id project id tenant id memory type created time expiration time For example: user id: user 123 session id: session 456 project id: project alpha This makes filtering predictable. Retrieval should filter by scope first Before ranking memories by relevance, the system should restrict the search to memories the current agent run is allowed to use. A common retrieval flow is: 1. Identify the current user. 2. Identify the current session. 3. Identify project or tenant if relevant. 4. Filter memories by those identifiers. 5. Rank only the remaining memories for relevance. This is safer than searching the entire memory store first and trying to remove unrelated results afterward. User scoped and session scoped memory can coexist An agent may use both at the same time. For example: User memory: Prefers concise responses. Session memory: Currently comparing cloud providers for Project Alpha. The agent can combine both when responding. The user preference persists across sessions, while the current comparison belongs only to this session. Project or tenant scope may also matter User and session scope are not always enough. A user may work across several projects. For example: Project A: Python backend. Project B: TypeScript backend. A project specific memory should not automatically apply to every project owned by the same user. Similarly, in multi tenant systems, every memory should usually be associated with the correct tenant boundary. Session scope is useful for temporary information Session memory is a good place for information that should not become a permanent profile. Examples include: temporary task preferences one time assumptions intermediate findings a temporary working hypothesis This avoids polluting long term user memory. User scope is useful for durable personalization User scoped memory is appropriate when information is likely to remain useful across sessions. Examples include: preferred response style preferred programming language recurring accessibility needs stable workflow preferences These memories should still be updateable if the user's preference changes. Expiration can strengthen scope Session memories may have explicit expiration. For example: session id: session 456 expires at: session end Temporary user or project memories can also have time limits. This prevents old scoped memory from remaining active indefinitely. Scope is also a security boundary Memory scoping is not only about relevance. It also helps prevent information leakage. An agent should never retrieve another user's or tenant's memory simply because it is semantically similar to the current request. Access controls and retrieval filters should enforce the boundary. A useful rule Think of memory scope as answering: Who does this memory belong to, and for how long is it valid? Typical answers are: this user across sessions this session only this project this tenant this workflow run The narrower the memory's validity, the narrower its scope should be. In short Agent memory should be scoped by attaching explicit identifiers such as user ID, session ID, project ID, or tenant ID and filtering retrieval using those boundaries. User scoped memory supports durable personalization across sessions, while session scoped memory keeps temporary context isolated to the current interaction.

How do you prevent memory leakage between users?

Memory leakage between users happens when an AI agent accidentally retrieves or uses information that belongs to a different user. The main defense is strict isolation: every memory must be associated with the correct identity and retrieval must enforce that boundary before relevance search happens. 1. Attach an owner to every memory Each stored memory should include ownership metadata such as: user id tenant id session id project id For example: user id: user 123 tenant id: tenant A memory: Prefers Python examples The memory should never be treated as globally available unless it was intentionally created as shared knowledge. 2. Filter by identity before semantic search A common mistake is searching the entire memory store and then trying to remove unrelated results afterward. A safer flow is: 1. Authenticate the current user. 2. Determine the current tenant or project. 3. restrict the candidate memory set to that scope. 4. perform keyword or vector similarity search only inside that allowed set. 5. return the most relevant memories. This prevents another user's semantically similar memory from entering the candidate set. 3. Do not trust user supplied identifiers blindly The system should not let a request simply provide: user id = someone else and use that value for retrieval. The user or tenant identity should come from trusted authentication and authorization context. The application should derive the effective identity from the authenticated session rather than from arbitrary model generated or user provided parameters. 4. Enforce isolation in storage Application level filters are useful, but important memory stores should also enforce access boundaries at the data layer where possible. Examples include: row level access policies tenant specific partitions separate namespaces separate indexes isolated databases for high security environments Defense in depth is safer than relying on a single prompt or retrieval rule. 5. Scope vector search correctly Vector databases can also leak information if embeddings from all users share one unrestricted search space. Safer designs use: per user namespaces per tenant namespaces mandatory metadata filters separate collections when stronger isolation is required Similarity should never override ownership. A memory can be extremely relevant and still be unauthorized. 6. Keep session memory isolated Temporary session memory should include a session identifier. For example: user id: user 123 session id: session 789 Another session should not automatically receive those temporary details unless the system intentionally promotes them into longer term user memory. This avoids accidental cross session contamination. 7. Separate shared memory from private memory Some information may legitimately be shared. For example: public product documentation organization wide procedures shared team policies Private user memories should be stored or labeled separately from shared knowledge. The retrieval system should know whether a memory is: private project shared tenant shared organization shared public This prevents private information from being mistaken for shared knowledge. 8. Validate tool and memory access separately Even if the agent itself behaves correctly, a memory tool can expose data if its API accepts unrestricted identifiers. For example, a tool like: get memories(user id) is risky if the model can choose any user ID. A safer interface is one where the backend automatically applies the authenticated user's identity and exposes only memories the caller is authorized to access. 9. Avoid caching across users without strong keys Caching can create leakage if responses or retrieved memories are reused across requests without including the correct identity in the cache key. A cache key may need to include values such as: user ID tenant ID project ID session ID permission scope Otherwise, one user's retrieved memory could be returned to another user. 10. Test explicitly for cross user leakage Memory isolation should be tested, not assumed. Useful tests include: User A cannot retrieve User B's memories. Similar embeddings from different users do not cross boundaries. Session A cannot access Session B's temporary memory. Tenant A cannot access Tenant B's memory. Cached retrieval results remain isolated. Background workers preserve the correct identity and tenant context. These tests are especially important in multi tenant systems. 11. Log memory access Memory retrieval and updates can be audited using information such as: requesting user tenant memory IDs retrieved retrieval time operation performed authorization result Audit logs help detect unexpected access patterns and investigate possible leakage. 12. Keep identity separate from model reasoning The model may decide what kind of memory it needs, but it should not be responsible for enforcing the security boundary. For example: Model decision: Retrieve deployment preferences. Backend enforcement: Only search memories authorized for the authenticated user and tenant. Security boundaries should be enforced by deterministic application and storage controls. A simple rule When retrieving memory: Authorization first, relevance second. The system should first determine which memories the current user is allowed to access. Only then should it ask which of those memories are most relevant. In short Preventing memory leakage between users requires strict ownership metadata, trusted identity, retrieval time filtering, storage level access controls, isolated vector search scopes, and explicit cross user tests. The agent should never be able to access another user's memory simply because that memory is semantically relevant.

How should sensitive information be handled in agent memory?

Sensitive information in agent memory should be minimized, protected, tightly scoped, and retained only when there is a clear reason to keep it. A memory system should not store sensitive data simply because it appeared in a conversation. Start with data minimization The safest sensitive memory is information that was never stored unnecessarily. Before persisting information, the system should ask: Is this information actually needed later? Can the task work without storing it? Can a less sensitive summary be stored instead? How long does it need to remain available? For example, an agent may need to remember that a user prefers email communication, but it may not need to store the full contents of every email. Avoid storing secrets in memory Credentials and authentication secrets generally should not become normal agent memory. Examples include: passwords API keys access tokens private keys session secrets These belong in dedicated secret management systems with controlled access. The agent can reference a credential indirectly when needed without placing the secret itself into conversational or semantic memory. Classify sensitive information Different information may require different controls. Examples include: personal information financial information health information confidential business data authentication data internal security details Classification helps determine whether the information may be stored, who can access it, and how long it should be retained. Use the narrowest possible scope Sensitive memories should be attached to the exact scope where they are valid. For example: user session project tenant organization A user specific sensitive memory should never become globally searchable. The narrower the scope, the lower the risk of accidental exposure. Enforce access control before retrieval The memory system should determine what the current user or agent is authorized to access before performing relevance search. A safe retrieval flow is: 1. Identify the authenticated user and tenant. 2. Apply authorization rules. 3. Restrict the allowed memory set. 4. Search only within that set. 5. Return the minimum information needed. Authorization should not depend on the model remembering to apply a filter. Encrypt sensitive memory Sensitive memory should normally be protected: in transit at rest For particularly sensitive fields, systems may also use field level encryption or tokenization. Encryption reduces exposure if storage or backups are accessed improperly, although it does not replace access control. Redact unnecessary details Sometimes the agent needs the meaning of sensitive information without needing the exact raw value. For example, instead of storing: Full card number: 4111 1111 1111 1111 the system should generally avoid storing the number at all and use a safe reference such as: Payment method: card ending in 1111 Similarly, logs and traces should avoid copying sensitive memory unnecessarily. Limit retention Sensitive information should not remain in memory forever by default. Retention controls may include: expiration time review date automatic deletion session only storage purpose based retention When the information is no longer needed, it should be removed or made inaccessible according to the applicable policy. Separate memory from audit history Operational memory and audit records serve different purposes. The agent may no longer need a sensitive fact for reasoning even if the organization must retain a controlled audit record for compliance. Keeping these systems separate allows normal memory retrieval to remain minimal while audit data remains protected under stricter access rules. Do not send sensitive memory to every model call Even authorized information should only be added to context when it is necessary for the current task. For example, a stored billing address should not be included while the agent is answering an unrelated coding question. Selective retrieval reduces unnecessary exposure. Be careful with embeddings Sensitive text can also be exposed through vector search systems if embeddings and their source data are not scoped correctly. A vector memory system should use: user or tenant isolation metadata filters access controls protected source records Embedding based similarity must never bypass authorization. Support correction and deletion Users or administrators may need to: correct stored information revoke consent delete memory update outdated information change retention preferences A memory system should support these operations rather than treating memory as permanent. Protect backups, logs, and traces Deleting a memory from the primary store is not enough if the same sensitive information remains copied into: application logs model traces caches analytics systems backups Sensitive data handling should consider the full data lifecycle. Monitor access For important memory stores, access may be logged with information such as: who accessed the memory when it was accessed what operation occurred which tenant or project was involved whether access was allowed or denied This helps detect misuse and investigate incidents. Use stronger controls for higher risk data The more sensitive the information, the stricter the handling should be. For highly sensitive memory, a system may require: explicit consent shorter retention stronger encryption narrower access additional approval fresh verification before use Not every memory should receive the same treatment. A useful principle Before storing sensitive information, ask: Do we need to remember this exact data, or only enough information to complete future tasks safely? Often the safer answer is to store less. In short Sensitive information in agent memory should be minimized, explicitly scoped, access controlled, encrypted, selectively retrieved, and removed when no longer needed. Secrets should generally stay in dedicated secret stores, while agent memory should retain only the smallest amount of sensitive information required for legitimate future use.

When should agent memory be persisted?

Agent memory should be persisted when information is likely to remain useful beyond the current step, session, or workflow and there is a clear reason to retain it. Not every piece of context deserves durable storage. Persist information with future value Good candidates for persistent memory include: stable user preferences important project facts reusable procedures recurring constraints decisions that affect future work lessons from previous tasks useful summaries of past interactions For example: Preference: The user prefers concise technical explanations. If that preference is likely to matter in future sessions, persisting it can improve continuity. Do not persist temporary execution details Some information is important only while the current workflow is running. Examples include: retry count current workflow node temporary tool result intermediate calculation short lived error message one time assumption These usually belong in agent state or short term memory rather than durable memory. Persist after useful information is confirmed An agent does not always need to write memory immediately. For example, if the user selects Python once, that may not be enough evidence for a permanent preference. If the user explicitly says: “Always use Python examples.” that is a much stronger candidate for persistence. Waiting for sufficient confidence can reduce incorrect memories. Persist important outcomes after a task A completed workflow may produce useful information that should survive the run. For example: a confirmed project decision a successful troubleshooting approach a new reusable procedure an updated user preference The system may evaluate these outcomes at the end of the workflow and decide which ones deserve long term memory. Persist when losing the information would create repeated work A useful test is: Would forgetting this force the agent or user to rediscover the same information later? If yes, persistence may be valuable. For example: Project database: PostgreSQL Deployment requires: Human approval These facts may affect many future tasks. Persist only within the correct scope Before saving memory, the system should determine where it belongs. Possible scopes include: user session project tenant organization For example, a preference that applies only to Project A should not automatically become a global user preference. Sensitive information needs a higher threshold Even if information might be useful later, persistence may not be appropriate if the information is sensitive. Before saving it, the system should consider: whether storage is necessary whether the user or organization permits retention whether a less sensitive representation would work how long the information should remain stored who should be allowed to retrieve it Useful does not automatically mean safe to persist. Some memories should expire Persistence does not always mean permanent storage. A memory may be useful for: one session one project several days a contract period until a specific event occurs Adding expiration or review rules helps prevent temporary information from becoming stale long term memory. Persist updates instead of duplicates If a memory already exists, new information may need to update it rather than create another copy. For example: Existing memory: Preferred output format = PDF Later: New preference: Preferred output format = CSV The system should normally update or supersede the old memory instead of keeping both as equally active facts. Persistence can happen at different points Depending on the system, memory may be persisted: immediately after an explicit preference after a significant decision after successful task completion when a repeated pattern becomes clear during memory consolidation at the end of a session when a workflow checkpoint promotes useful information The timing depends on how important and reliable the information is. Persistence should be selective Persisting everything can create: unnecessary storage noisy retrieval stale memories privacy risk conflicting facts higher maintenance cost A smaller set of high value memories is usually more useful than a large archive of every interaction detail. A practical persistence check Before writing durable memory, an agent system can ask: Will this likely be useful again? Is it stable enough to retain? Is it important enough to matter? Is the information sufficiently reliable? Is it safe and permitted to store? What scope does it belong to? Should it expire? Does an existing memory need to be updated instead? If these conditions are satisfied, persistence is usually justified. In short Agent memory should be persisted when information has clear future value, is reliable enough to reuse, belongs to a well defined scope, and is appropriate to retain beyond the current task or session. Temporary execution details should stay in state or short term memory, while durable facts, preferences, lessons, and procedures can be promoted into persistent memory when justified.

How do you evaluate whether agent memory is useful?

Agent memory is useful when retrieving it improves the agent's decisions, task success, consistency, or efficiency compared with running the same task without that memory. The goal is not simply to store and retrieve more information. The goal is to retrieve information that actually helps. Start with a simple comparison A practical way to evaluate memory is to compare two versions of the same agent: Without memory: The agent handles the task using only the current context. With memory: The agent can retrieve relevant stored information. Then measure whether memory improves the outcome. 1. Measure task success The most important question is: Does memory help the agent complete tasks more successfully? For example, if an agent remembers project constraints, does it produce fewer invalid plans? If task success does not improve, the memory may not be useful even if retrieval itself appears technically accurate. 2. Measure retrieval relevance Retrieved memories should actually help with the current task. You can evaluate: how often retrieved memories are relevant whether important memories are missed whether irrelevant memories enter the context For example: Task: Deploy Project Alpha. Useful retrieval: deployment region approval requirement deployment procedure Poor retrieval: unrelated billing preference old travel conversation another project's configuration 3. Check whether memory reduces repeated work Useful memory should prevent the agent or user from repeatedly rediscovering the same information. For example, without memory the user may need to say: “Use Python examples.” in every session. If memory removes that repetition while remaining correct, it is providing clear value. 4. Measure personalization quality For user facing agents, memory may improve consistency and personalization. You can evaluate whether the agent correctly remembers: preferred formats communication style recurring constraints project preferences The important word is correctly. Remembering the wrong preference is worse than remembering nothing. 5. Measure decision quality Memory should help the agent make better choices. For example: An incident response agent remembers that a particular service frequently fails because of connection pool exhaustion. When a similar incident occurs, does retrieving that memory help the agent investigate the right area faster? If yes, the memory is useful. 6. Measure efficiency Memory can also be valuable if it reduces unnecessary work. Possible signals include: fewer tool calls fewer reasoning steps shorter task completion time fewer clarification questions lower token usage less repeated research For example, remembering a project's deployment procedure may save the agent from reconstructing the process every time. 7. Measure harmful retrieval Memory can also hurt performance. Track cases where retrieved memory causes: wrong assumptions outdated decisions irrelevant context excessive token usage conflicting instructions unnecessary personalization A useful memory system should improve outcomes more often than it introduces these problems. 8. Evaluate freshness A memory can be relevant but stale. For example: Stored memory: Deployment region = us east 1. Current reality: Deployment region = ap south 1. Retrieval may appear successful because the memory matches the topic, but using it makes the agent worse. Evaluation therefore needs to consider correctness and freshness, not only retrieval similarity. 9. Evaluate whether the right memory is retrieved at the right time An agent does not need every useful memory in every step. For example: A deployment approval rule may be important immediately before production deployment but unnecessary during code formatting. Useful memory systems retrieve information when it becomes relevant rather than flooding every prompt with everything known. 10. Test with realistic scenarios Memory evaluation should include scenarios where: a relevant memory exists no useful memory exists multiple similar memories exist a memory is stale memories conflict the correct memory belongs to another user a memory should have expired These cases reveal whether the memory system behaves reliably, not just whether it works in ideal conditions. 11. Compare memory enabled and memory disabled runs A/B style evaluation is especially useful. For the same test set, compare: Agent A: Memory disabled Agent B: Memory enabled Then measure differences in: task success correctness latency cost number of tool calls user corrections clarification requests This shows whether memory adds measurable value. 12. Track memory precision and recall You can think of retrieval quality in two directions. Precision: Of the memories retrieved, how many were actually useful? Recall: Of the memories that should have been retrieved, how many were found? High recall with poor precision may overload the agent with irrelevant context. High precision with poor recall may cause the agent to miss important information. 13. Evaluate downstream impact, not retrieval alone A memory can be relevant but still not improve the final task. For example, the system may retrieve the correct preference, but the agent may ignore it. So evaluation should include both: retrieval quality downstream task performance This helps identify whether the problem is memory search or how the agent uses retrieved memory. A practical evaluation set For each test case, record: current task memories available memories that should be retrieved memories actually retrieved final agent outcome whether memory improved or hurt the result Over many cases, this gives a clearer picture of whether memory is providing real value. In short Agent memory is useful when it consistently improves task success, decision quality, personalization, and efficiency without introducing excessive noise, stale information, or privacy risk. The best evaluation compares memory enabled and memory disabled runs and measures both retrieval quality and the downstream effect on the agent's final behavior.