Skip to content
Ylabator

Shared Memory Without Shared Exposure

Agents can share task state without sharing exposure, if memory is stored as typed records with an owner, a source and a policy check on every read.

Topics
Secure AI Agents
Level
Founder / builder
Read
4 min
Published
2026-11-12
Reviewed
2026-11-12
Week 4

The problem

OpenAI's help center for ChatGPT memory states that saved memories are stored separately from chat history, and that deleting a chat does not delete a memory created from it. To remove the information fully, a user deletes both the memory and the original chat [1]. Memory is a derived store with its own life.

The same property shows up in every product that gives agents memory, and it becomes a privacy problem as soon as several agents or several users share one store. Anthropic's memory tool makes the ownership explicit: it runs client side, Claude only requests file operations, and the application maps the /memories path onto real storage, such as a per-user directory or keys in a database [2]. Whether one user's memory is visible to another agent, user or tenant is the application's decision.

Most teams make that decision by accident. The first version of a multi-agent product puts everything into one shared store, because agents need to coordinate. A sales agent and a finance agent work the same customer account. Then a marketing agent is added, reads the same store, and finds a confidential payment dispute in the account history. OWASP describes this class of failure as context leakage between users or queries that share a vector database [3].

Deleting the source document rarely fixes it. A summary or an extracted fact written to memory before the deletion keeps answering questions after the source is gone.

How it works

Separate what agents need to share from what they must not. The diagram for this article uses four memory classes:

  • Shared task state. Identifiers and the facts relevant to the current task: account ID, open ticket, next step. This is what agents exchange.
  • Private user memories. Preferences and history scoped to one owner. Readable only by agents acting for that owner.
  • Tool credentials. OAuth tokens and API keys. Never stored in memory that a model can read, and never shared between agents.
  • Raw documents. The source files. Their original access lists apply, as in permission-aware retrieval.

Every read and write goes through one policy-aware layer with per-record ownership and provenance. The layer is ordinary code. It receives the calling agent's identity and the user it acts for from the orchestrator, never from the model's output.

Each memory record is a structured claim, not a blob of text. It carries a source reference, tenant, subject, sensitivity, visibility, timestamp, time to live and a revocation link back to the source. Those fields let the policy layer answer three questions on every access. May this agent see records of this sensitivity for this subject? Is the record still within its time to live? Is the source it came from still valid?

Handoffs between agents carry identifiers and the relevant facts, not transcripts. When the sales agent passes an account to finance, the handoff says "account 4411, renewal due December 1, contact is the CFO," and finance reads the rest under its own permissions.

The revocation link is what makes deletion work. When a source document is deleted or unshared, the layer finds every record derived from it and removes or re-scopes them in the same transaction. Summaries are derivatives. They inherit the most restrictive visibility of their sources.

OWASP's Top 10 for Agentic Applications, published in December 2025, treats memory as an attack surface in its own right [4]. The same structure that limits exposure also limits poisoning, because every record names where it came from.

Shared coordination, separated exposure

Fig. 04
  • Sales agent
  • Finance agent
  • Marketing agentNo access to payment disputes
Policy-aware read and writePer-record ownership and provenance
  • Shared task stateIdentifiers and relevant facts
  • Private user memoriesOwner-scoped
  • Tool credentialsNever shared
  • Raw documentsSource ACLs apply
Agents coordinate through typed memory classes. Every read is policy-aware, so a marketing agent can share task state without seeing a payment dispute.
Technical detail

Store memory as structured claims carrying source reference, tenant, subject, sensitivity, visibility, timestamp, TTL and a revocation link. Limit handoffs to identifiers and relevant facts.

By the numbers

file operations the memory tool asks an application to run on its own storage [2]
6
of AI-related security incidents led to compromised data [5]
60%
of organizations with a breach of AI models or apps had no AI access controls [5]
97%
organizations reported a breach due to shadow AI [5]
1 in 5
Memory classOwnerDefault visibilityDeleted when
Shared task stateTaskAgents assigned to the taskTask closes, plus time to live
Private user memoryOne userAgents acting for that userUser deletes it or the account closes
Tool credentialsServiceNo agent. Held by the tool gatewayToken expires or is revoked
Raw documentsSource systemSource access listSource deletes it
Derived summariesInheritedMost restrictive sourceAny source is revoked
Memory classes and default rules, following the partitioning guidance in OWASP LLM08 and the memory tool documentation [2][3]

The IBM figures describe the general pattern: most AI incidents ended in compromised data, and nearly all breached organizations lacked AI access controls [5]. A shared memory store with no ownership model is a direct way to recreate that gap.

The memory tool's six operations (view, create, str_replace, insert, delete, rename) are all file operations your code runs [2]. That makes the handler the right place for the policy check, and the right place to stop a path such as /memories/../../secrets.env, which the documentation warns about explicitly.

Implementation

The store below is a minimal policy layer. Agents never query the database directly. They call read and write with an identity supplied by the orchestrator.

memory_store.pypython
"""Typed memory records with per-record ownership and policy-aware reads."""
from dataclasses import dataclass, field
from datetime import datetime, timedelta, timezone

SENSITIVITY = {"public": 0, "internal": 1, "confidential": 2}


@dataclass(frozen=True)
class Record:
    id: str
    tenant: str
    subject: str            # e.g. "account:4411"
    memory_class: str       # task_state | user_memory | derived_summary
    sensitivity: str
    visible_to: frozenset   # agent roles allowed to read
    sources: tuple          # revocation links to source documents
    text: str
    created: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
    ttl: timedelta = timedelta(days=30)


@dataclass(frozen=True)
class Caller:
    tenant: str
    role: str               # "sales", "finance", "marketing"
    clearance: str          # highest sensitivity this role may read


class MemoryStore:
    def __init__(self) -> None:
        self._records: dict[str, Record] = {}

    def write(self, rec: Record) -> None:
        if rec.memory_class == "credential":
            raise PermissionError("credentials never go into model-readable memory")
        self._records[rec.id] = rec

    def read(self, caller: Caller, subject: str) -> list[Record]:
        now = datetime.now(timezone.utc)
        return [
            r for r in self._records.values()
            if r.tenant == caller.tenant and r.subject == subject
            and caller.role in r.visible_to
            and SENSITIVITY[r.sensitivity] <= SENSITIVITY[caller.clearance]
            and now < r.created + r.ttl
        ]

    def revoke_source(self, source_id: str) -> int:
        # Remove every record derived from the source, summaries included.
        doomed = [k for k, r in self._records.items() if source_id in r.sources]
        for k in doomed:
            del self._records[k]
        return len(doomed)

In production the same fields live in a database table with row-level security, and revoke_source runs from the same queue that handles source permission changes. If you use Anthropic's memory tool, map /memories to a per-user, per-tenant prefix and resolve every path before use. The documentation recommends Python's pathlib.Path.resolve() and relative_to() for the check [2].

Test it

Two tests carry most of the risk: a restricted agent querying protected records, and a deleted source whose summary survives.

test_memory_policy.pypython
from dataclasses import replace
from datetime import timedelta

from memory_store import Caller, MemoryStore, Record

DISPUTE = Record(
    id="m1", tenant="t1", subject="account:4411", memory_class="task_state",
    sensitivity="confidential", visible_to=frozenset({"finance"}),
    sources=("doc:dispute-0927",), text="Customer disputes the September invoice.",
)
SUMMARY = Record(
    id="m2", tenant="t1", subject="account:4411", memory_class="derived_summary",
    sensitivity="confidential", visible_to=frozenset({"finance", "sales"}),
    sources=("doc:dispute-0927", "doc:renewal-terms"), text="Renewal at risk: open dispute.",
)


def make_store() -> MemoryStore:
    store = MemoryStore()
    store.write(DISPUTE)
    store.write(SUMMARY)
    return store


def test_marketing_cannot_read_payment_dispute():
    marketing = Caller(tenant="t1", role="marketing", clearance="internal")
    assert make_store().read(marketing, "account:4411") == []


def test_other_tenant_sees_nothing():
    finance_t2 = Caller(tenant="t2", role="finance", clearance="confidential")
    assert make_store().read(finance_t2, "account:4411") == []


def test_deleting_source_removes_summary():
    store = make_store()
    assert store.revoke_source("doc:dispute-0927") == 2
    finance = Caller(tenant="t1", role="finance", clearance="confidential")
    assert store.read(finance, "account:4411") == []


def test_expired_record_is_not_returned():
    store = MemoryStore()
    store.write(replace(DISPUTE, id="m3", ttl=timedelta(seconds=-1)))
    finance = Caller(tenant="t1", role="finance", clearance="confidential")
    assert store.read(finance, "account:4411") == []

Expected result: four passes. Then extend the suite against the real system:

  • Call the memory handler with /memories/../../secrets.env and a URL-encoded variant. Expected: rejected before any file system call.
  • Delete a source in the source system and measure how long its derived records remain readable.
  • Log every denied read with caller, subject and rule. A sudden rise in denials is often a misassigned role, and sometimes an agent probing.

Decision

Give agents a shared layer for task state, and give every record an owner, a source and a policy check.

  • Start with the four classes and the record fields above. Adding ownership after the store holds a year of untyped memory means re-deriving it.
  • Keep credentials out of model-readable memory entirely. The tool gateway holds them.
  • Make deletion cascade through summaries. Test it with a real source deletion, not a unit test alone.
  • Cost: the policy layer is a few days of work. The revocation queue and its monitoring are the ongoing cost, and they are shared with permission-aware retrieval.

Sources

  1. [1]Memory FAQ (opens in a new tab)OpenAI Help Center, November 2026
  2. [2]Memory tool (opens in a new tab)Anthropic, November 2026
  3. [3]LLM08:2025 Vector and Embedding Weaknesses (opens in a new tab)OWASP GenAI Security Project, 2025
  4. [4]OWASP Top 10 for Agentic Applications for 2026 (opens in a new tab)OWASP GenAI Security Project, December 2025
  5. [5]IBM Report: 13% of organizations reported breaches of AI models or applications, 97% of which reported lacking proper AI access controls (opens in a new tab)IBM Newsroom, July 2025

Technical guidance, not security certification or legal advice.

All Private AI articles