Skip to content

Securing long-term agent memory on Databricks

Ivan VydrinUpdated 9 min readVoices

An agent's long-term memory is a write path into production. It deserves the same gate as any other write that changes what the next run does. A wrong report shows the wrong number once, to the person reading it. An agent that remembers a wrong fact repeats it in every later conversation with that person, until somebody finds the entry and deletes it.

We built that gate into Fabric, the software delivery platform we make, between 15 and 16 October. Every AI coding agent on a Fabric project reads the same shared memory (why it lives in Git), and agents can now add to it, through a narrow door on purpose. An agent can write only into folders a project administrator named, and every write waits for a person to review it unless an administrator chose otherwise for that folder. Fabric scans each write for secrets before admitting it. Some places can never take a memory write at all, such as the folders that hold the build's own configuration, because a note written there would become code that runs.

Databricks now gives agents a managed memory store backed by Lakebase, and memory pipelines that distil durable facts out of past conversations, both in Beta (agent memory, memory pipelines). We haven't run either on a client workload. For a company putting an agent in front of customers, the risk is a wrong answer nobody sees until a customer repeats it back. The first step costs nothing. Decide what the agent may write to memory before it writes anything. Most of the rules we wrote for Fabric carry over to Databricks.

The rule behind the write lane

The decision record for the lane, ADR-022, starts from one product rule: a person stands between one agent's edit and the next agent's read. Everything else follows from where we kept that rule and where we let it go.

Control in Fabric's write lane What it stops
Writes only into folders an administrator named, at most ten per sync An agent deciding for itself where its notes live
Pull request by default; direct push only by a project administrator's opt-in per folder The next agent reading something nobody reviewed
Never the repository root, a dot-folder such as .github, or a coding-instructions folder A memory write becoming a workflow file that runs with CI's privileges, or a rule every agent must follow
A secret scan, path and content rules at admission, then live re-checks before the commit A credential or a stale target slipping in between request and commit
Every commit carries a Fabric-Memory-Write trailer, plus Fabric-Agent when the agent connected through OAuth, and a message that spells either is refused A write nobody can trace back to its request and its agent
A folder can be store-only: kept and readable, never embedded or returned by search Thousands of task notes crowding what the agent retrieves

We accepted one gap knowingly. On a direct-push folder the next agent reads writes nobody reviewed. That's fine for working notes, because every change is a Git commit that can be reverted, and it's never allowed for coding instructions.

What Databricks agent memory stores

A memory store is a workspace-scoped container, and creating one provisions its Lakebase storage. Each entry holds free-form content, a short description used for retrieval, a required actor_id for whose memory it is, an optional session_id, and a required path such as /preferences/response-style.md. Retrieval either lists an actor's entries, filtered by session or path prefix, or searches them with a natural-language query ranked by relevance, combining BM25 full-text and semantic matching.

content is free text, so a sentence that's simply wrong is a valid entry. A schema check or a data-quality expectation checks a shape, not whether a sentence is true. And retrieval ranks on relevance, not truth. An entry that uses the user's own words ranks well whether or not it's true, and an entry phrased as an instruction competes on equal terms with entries phrased as facts.

User message or tool output

Session store holds the conversation

Memory pipeline distils durable facts

Merge and maintain under actor_id

Memory entry with content and path

Search in a later conversation

Answer the agent gives weeks later

How a sentence in one conversation becomes a durable memory entry and comes back weeks later in another.

How a wrong fact gets in and stays

Memory is written from untrusted input: what the user typed, and whatever text the agent's tools pulled back from a page or a ticket. A study of memory poisoning in LLM agents identifies four memory write channels and nine structural vulnerabilities. It finds that agents built to write and retrieve memory more aggressively are easier to exploit, and that existing prompt injection defences don't cover memory poisoning (Dash et al.). AgentPoison showed the attacker's side earlier, backdooring agents through a few malicious demonstrations in long-term memory, with no model training.

The failure I'd expect a client to hit first needs no attacker. "Use the finance team's current quarterly forecast sheet for revenue" is true in October and wrong in January. The pipelines are designed to skip live values, such as a table's row count, and record how to find them instead. That's the right instinct, and it doesn't cover a fact that was durable when it was captured and expired later.

Then there's maintenance. Each pipeline run distils an actor's new conversations, merges the facts into topic-based entries, and merges or splits that actor's entries as they grow. The docs say maintenance applies to every entry under an actor_id, including entries the agent saved directly, and a pipeline can rewrite, merge, split or delete any of them. A wrong fact that arrives as its own entry can be found and deleted. One that survives a merge can end up as a clause inside a well-written entry next to true ones, and the docs don't say which session_id the merged entry keeps. Git keeps the history of every change to Fabric's memory. A memory entry isn't a versioned table you can diff.

Carrying the write lane over to Databricks

Most of the pieces map across.

  • Identity from the application, never the model. Set actor_id in trusted application code from the verified end user, as the docs advise. If the model picks whose memory it reads or writes, there's no boundary, only a suggestion.
  • One governed function in front of the store. A memory store is workspace-scoped, and the agent memory docs say any principal that can reach a store can read and write every entry across all actors. So we'd route every write through a save_memory function governed as a tool under Unity Gateway, the way Fabric's lane is the only door into Living Memory. That one function is where we'd reject content that reads as an instruction, stamp a capture date into the text, and keep pricing, policy and entitlements out.
  • Folders become path prefixes. /preferences/ for what a user said about themselves and /projects/ for the work they're in the middle of give prefixes you can list, review and expire on separate schedules, as Fabric's write folders do.
  • Trace every entry to its session. We'd set session_id on every write and treat the optional field as required, because it's the nearest thing the store has to Fabric's commit trailers, even if a maintenance pass may not keep it.

What doesn't carry over is the pull request. Nothing in Databricks agent memory waits for a person between a write and the next read, so the review has to be a scheduled one, over a path prefix, after the fact.

The test we'd run before trusting it

MLflow's built-in RAG judges score retrieval with RetrievalRelevance, RetrievalGroundedness and RetrievalSufficiency, the last needing ground-truth expectations, and all three need traces with a span marked span_type="RETRIEVER" (MLflow RAG judges). Tracing the memory search as a retriever span is how we'd point them at memory.

An evaluation set built only from true expectations measures recall, though. The question that decides whether memory is safe is whether a wrong entry, once written, still steers an answer three conversations later. So we'd keep a held-out set of facts we know to be false, write them in deliberately on a test actor, run a pipeline over them, and check what the agent says afterwards. We haven't run that experiment yet, and it's the first thing we'd do on a pilot.

Where we'd use it, and where we wouldn't

We'd use managed memory for what an agent learns about a person: how they want results formatted and which project they're in the middle of. During the Beta you pay for the Lakebase instance that stores the entries, with no extra charge for agent memory itself, and pipeline runs bill as serverless compute plus Foundation Model Serving.

We wouldn't put anything an auditor would ask about into a free-text entry. Rates, eligibility, credit policy and clinical rules belong in tables with lineage, read through a governed tool on every request, the same way coding instructions in Fabric never live in a folder an agent can write to.

The first pipeline run is the reason we'd keep a person in the loop for now. It processes an actor's entire conversation history, so whatever was wrong across months of chat arrives consolidated, in well-written sentences, on day one. Decide your path prefixes and set session_id on every write before the store holds anything, then put the save_memory function in front of it.

Frequently asked questions

What is agent memory poisoning?

Agent memory poisoning is an attack in which adversarial content is written into an agent's long-term memory, so a single write influences the agent's behaviour in later, unrelated conversations. A systematic study identifies four memory write channels and nine structural vulnerabilities behind it, and finds that existing prompt injection defences don't cover it (Dash et al.).

Can a Databricks memory pipeline change entries an agent saved itself?

Yes. The Databricks documentation states that maintenance applies to all of an actor's memory entries, including entries the agent saved directly, and that a pipeline can rewrite, merge, split or delete any entry under an actor_id it processes.

Should every agent memory write be reviewed by a person?

Not every one, but the ones the next run will treat as rules should be. In Fabric, coding instructions can never be written by an agent at all, and memory folders open a pull request unless an administrator chose direct push for that folder. On Databricks, where writes land at once, we'd review by path prefix on a schedule and keep anything the business is accountable for in governed tables.