---
title: Agent memory
description: Give agents long-term memory backed by Lakebase. Save and search entries per user, or distill them from conversation history with a memory pipeline.
canonical_url: https://docs.databricks.com/gcp/en/agents/agent-memory/managed-memory
---

# Agent memory

> [!NOTE]
> **Beta**
>
> This feature is in [Beta](https://docs.databricks.com/gcp/en/release-notes/release-types.md). To use it, a workspace admin must turn on **Agent Memory Sessions** from the **Previews** page. See [Manage Databricks previews](https://docs.databricks.com/gcp/en/admin/workspace-settings/manage-previews.md).

Agent memory gives your agents long-term memory that persists across conversations. Databricks stores the memory in [Lakebase](https://docs.databricks.com/gcp/en/oltp/projects/index.md) and manages the storage, indexing, and search for you, so your agents can remember user preferences, past decisions, and accumulated context without you operating a database.

> [!NOTE]
>
> During the preview, you are billed for the underlying Lakebase instance that stores your memory entries. No additional charges apply for agent memory itself. Pricing is subject to change as the preview progresses.

Use agent memory when you want your agents to:

* Remember user preferences, facts, and decisions across separate conversations.
* Personalize responses based on what an agent learned in earlier sessions.
* Share accumulated knowledge across agents and projects.
* Improve in accuracy and efficiency over time.

Agent memory works with agents built on any framework. For short-term conversation history within a single interaction, use [agent sessions](https://docs.databricks.com/gcp/en/agents/agent-memory/managed-sessions.md). For an overview of how sessions, memory, and memory pipelines fit together, see [Agent memory and sessions](https://docs.databricks.com/gcp/en/agents/custom-agents/stateful-agents.md).

## Requirements

* Install **Python 3.10 or above**, to use the [AgentKit SDK](https://github.com/databricks/databricks-ai-bridge/tree/main/integrations/agentbricks). AgentKit SDK is the Databricks Python client for agent APIs which the examples below use. You can also call the [REST API](https://docs.databricks.com/gcp/en/agents/agent-memory/managed-memory.md#get-started) directly from any language, with no Python requirement.
* To use `memory_store.put()` or `memory_store.list(path=...)`, install `databricks-agentbricks` 0.6.0 and above.

## How agent memory works

![Agent memory resource hierarchy: a memory store contains many memory entries, each identified by actor\_id, optional session\_id, and path, and holding content and a description.](https://docs.databricks.com/gcp/en/images/generative-ai/agent-platform/managed-memory-hierarchy.svg)

Agent memory has two levels:

* A **memory store** is the workspace-scoped container for an agent's memories. Creating a store provisions the backing Lakebase storage automatically. You address a store by its store ID, which you choose when you create the store.
* A **memory entry** is an individual piece of content in a store. Each entry has a free-form text `content`, a short `description` used for retrieval, and a set of fields that organize and partition it:
  * `actor_id` (required): who the memory belongs to, such as an end user or another agent.
  * `session_id` (optional): the session that the memory belongs to. Leave it unset for memory that applies across the actor's sessions.
  * `path` (required): a filesystem-like path that organizes entries within an actor, such as `/preferences/response-style.md`.

An entry is uniquely identified by the combination of `actor_id`, `session_id`, and `path`. The same path under two different sessions, or under a session and without one, holds two separate entries.

Entries get into a store in two ways: your agent or application writes them directly, or a [memory pipeline](https://docs.databricks.com/gcp/en/agents/agent-memory/memory-pipelines.md) distills them from the conversations in a session store.

### Retrieval

Retrieve memory two ways:

* **List** entries for an actor, optionally filtered by `session_id`, a `path` prefix, or an exact `path`. Use this to browse or render an index of what an agent knows.
* **Search** entries for an actor with a natural-language query. Search returns the most relevant entries ranked by relevance score.

A `session_id` filter on either operation returns only the entries saved with that session. It doesn't return entries saved without a session.

## <a id="get-started" />Get started

The AgentKit SDK and REST API examples set up agent memory for a support agent: they create a memory store, save a user's preference, and recall it in a later conversation. The Agent Bricks CLI example connects a memory store to an agent that you build and deploy with the CLI. Choose the client that fits your project. A memory store ID must be 3 to 56 characters, start with a lowercase letter, end with a letter or number, and contain only lowercase letters, numbers, and hyphens.

### AgentKit SDK

The [AgentKit SDK](https://github.com/databricks/databricks-ai-bridge/tree/main/integrations/agentbricks) is the Databricks Python client for agent APIs, distributed in the `databricks-agentbricks` package. It authenticates with the Databricks SDK's [`WorkspaceClient`](https://docs.databricks.com/gcp/en/dev-tools/sdk-python.md).

1. Install the AgentKit SDK:

   ```bash
   pip install databricks-agentbricks
   ```

2. Create a memory store for your agent. `AgentKitClient` authenticates with your `WorkspaceClient` credentials:

   ```python
   from databricks.sdk import WorkspaceClient
   from databricks_agentkit import AgentKitClient

   client = AgentKitClient(WorkspaceClient())
   memory_store = client.memory_stores.create("support-agent-memory")
   ```

   `create()` fails if the store already exists. In later sessions, open the existing store instead:

   ```python
   memory_store = client.memory_stores.get("support-agent-memory")
   ```

3. Save a memory after the agent learns something durable about a user. `actor_id` is whose memory this is, `path` organizes it within that actor, and `description` improves retrieval:

   ```python
   memory_store.add(
       actor_id="user-123",
       path="/preferences/communication.md",
       content="Prefers email over phone. Timezone: PST. Enterprise subscription.",
       description="User 123 communication preferences",
   )
   ```

   `add()` fails with `ALREADY_EXISTS` if an entry already exists at that path. To create the entry or update the existing one, call `memory_store.put()` with the same arguments.

4. Recall the user's memories in a later conversation with a natural-language search:

   ```python
   results = memory_store.search(actor_id="user-123", query="communication preferences", limit=10)
   ```

5. Delete the memories saved at that path when you no longer need them:

   ```python
   for memory in memory_store.list(actor_id="user-123", path="/preferences/communication.md"):
       memory.delete()
   ```

### REST API

The clients call the REST API under `/api/2.0/agents/memory-stores`. Call it directly for languages other than Python.

1. Set your workspace hostname, without `https://`, and generate an OAuth token with the Databricks CLI:

   ```bash
   export DATABRICKS_HOST=<workspace-hostname>
   databricks auth login --host https://${DATABRICKS_HOST}
   export DATABRICKS_TOKEN=$(databricks auth token | jq -r .access_token)
   ```

2. Create a memory store for your agent:

   ```bash
   curl -X POST "https://${DATABRICKS_HOST}/api/2.0/agents/memory-stores?managed_memory_store_id=support-agent-memory" \
     -H "Authorization: Bearer ${DATABRICKS_TOKEN}" -H "Content-Type: application/json" \
     -d '{"description": "Support agent memory"}'
   ```

3. Save a memory entry for a user. `actor_id` is whose memory this is, `path` organizes it, and `description` improves retrieval:

   ```bash
   curl -X POST "https://${DATABRICKS_HOST}/api/2.0/agents/memory-stores/support-agent-memory/entries" \
     -H "Authorization: Bearer ${DATABRICKS_TOKEN}" -H "Content-Type: application/json" \
     -d '{"actor_id": "user-123", "path": "/preferences/communication.md", "content": "Prefers email over phone.", "description": "Communication preferences"}'
   ```

   If an entry already exists at that path, the request fails with `ALREADY_EXISTS` (HTTP 409). To update the existing entry instead, look it up by path. The lookup returns the path's entries for every session in a `managed_memory_entries` array:

   ```json
   {
     "managed_memory_entries": [
       {
         "name": "memory-stores/support-agent-memory/entries/<entry-id>",
         "actor_id": "user-123",
         "path": "/preferences/communication.md",
         "content": "Prefers email over phone.",
         "description": "Communication preferences",
         "create_time": "2026-11-08T01:20:05Z",
         "update_time": "2026-11-08T01:20:05Z"
       }
     ]
   }
   ```

   To match a session, compare `session_id`. An entry saved without a session has no `session_id` field, so select the entry that has none. The last segment of the entry's `name` is the entry ID. The following command looks up the entry saved without a session and stores its ID in `EID`:

   ```bash
   EID=$(curl -s -G "https://${DATABRICKS_HOST}/api/2.0/agents/memory-stores/support-agent-memory/entries" \
     -H "Authorization: Bearer ${DATABRICKS_TOKEN}" \
     --data-urlencode "actor_id=user-123" --data-urlencode "path=/preferences/communication.md" \
     | jq -r '.managed_memory_entries[] | select(.session_id == null) | .name | split("/") | last')
   ```

   Then update the entry's content by its ID:

   ```bash
   curl -X PATCH "https://${DATABRICKS_HOST}/api/2.0/agents/memory-stores/support-agent-memory/entries/${EID}?update_mask=content" \
     -H "Authorization: Bearer ${DATABRICKS_TOKEN}" -H "Content-Type: application/json" \
     -d '{"content": "Prefers email over phone. Timezone: PST."}'
   ```

4. Recall the user's memories with a natural-language search:

   ```bash
   curl -X POST "https://${DATABRICKS_HOST}/api/2.0/agents/memory-stores/support-agent-memory/entries:search" \
     -H "Authorization: Bearer ${DATABRICKS_TOKEN}" -H "Content-Type: application/json" \
     -d '{"actor_id": "user-123", "query": "communication preferences"}'
   ```

   Ranked hits are in `results`, most relevant first. Each result has a `managed_memory_entry` and a relevance `score`, where a higher score is more relevant. The response also repeats the same entries, in the same order and without scores, in a top-level `managed_memory_entries` array. That array is deprecated, so read `results`:

   ```json
   {
     "results": [
       {
         "managed_memory_entry": {
           "name": "memory-stores/support-agent-memory/entries/<entry-id>",
           "actor_id": "user-123",
           "path": "/preferences/communication.md",
           "content": "Prefers email over phone. Timezone: PST.",
           "description": "Communication preferences"
         },
         "score": 0.87
       }
     ],
     "managed_memory_entries": [
       {
         "name": "memory-stores/support-agent-memory/entries/<entry-id>",
         "actor_id": "user-123",
         "path": "/preferences/communication.md",
         "content": "Prefers email over phone. Timezone: PST.",
         "description": "Communication preferences"
       }
     ]
   }
   ```

5. Delete the entry when you no longer need it. Look it up by path again, then delete it by ID:

   ```bash
   EID=$(curl -s -G "https://${DATABRICKS_HOST}/api/2.0/agents/memory-stores/support-agent-memory/entries" \
     -H "Authorization: Bearer ${DATABRICKS_TOKEN}" \
     --data-urlencode "actor_id=user-123" --data-urlencode "path=/preferences/communication.md" \
     | jq -r '.managed_memory_entries[] | select(.session_id == null) | .name | split("/") | last')

   curl -X DELETE "https://${DATABRICKS_HOST}/api/2.0/agents/memory-stores/support-agent-memory/entries/${EID}" \
     -H "Authorization: Bearer ${DATABRICKS_TOKEN}"
   ```

### Agent Bricks

If you build your agent with the [Agent Bricks CLI](https://docs.databricks.com/gcp/en/agents/custom-agents/agent-bricks-cli.md), `agentbricks init` declares a memory store in `agent.toml`. `agentbricks deploy` creates the store if it doesn't already exist and grants the deployed agent access to it.

Choose a path:

* **Start empty (most agents)**: Deploy the agent. `agentbricks deploy` creates the memory store that `agentbricks init` declared. To deploy an agent named `my-agent`, run the following:

  ```bash
  agentbricks deploy my-agent
  ```

* **Start with memories already in the store**: Create the store first, add entries, then bind the store to the agent and deploy.
  1. To create a store named `my-agent-memory`, run the following. The output includes the store ID, a generated identifier that's separate from the store name:

     ```bash
     agentbricks memory stores create --name my-agent-memory
     ```

  2. To add an entry, run the following, replacing `<store-id>` with the store ID from the previous step:

     ```bash
     agentbricks memory entries create --store <store-id> --actor-id you@example.com \
       --path /preferences/style.md --content "Prefers Python and concise answers with code examples."
     ```

  3. To bind the store and deploy the agent, run the following. `agentbricks memory bind` replaces the store name in `agent.toml`, and `agentbricks deploy` finds the existing store by name and uses it instead of creating a new one:

     ```bash
     agentbricks memory bind my-agent-memory
     agentbricks deploy my-agent
     ```

`--path` is the entry's key inside the store, not a file on your machine. `--actor-id` is the user the memory belongs to. A deployed agent uses the signed-in user's email as the actor ID, so seed each entry with the email of the user who chats with the agent.

In the Agent Bricks CLI, `memory bind` and `agentbricks deploy` refer to a store by its name. Commands that act on a single store, such as `memory entries create`, take the generated store ID.

### <a id="give-your-agent-memory-tools" />Give your agent memory tools

To let an agent decide when to save and recall memory, wrap the client operations as tools and instruct the agent on when to use them in its system prompt. Set the `actor_id` in trusted application code from the verified end-user identity. Never let the model choose whose memory to read or write.

The following example wraps the AgentKit SDK `memory_store` from [Get started](https://docs.databricks.com/gcp/en/agents/agent-memory/managed-memory.md#get-started) as tools for the OpenAI Agents SDK.

```python
from agents import Agent, function_tool

def make_memory_tools(memory_store, actor_id: str):
    @function_tool
    def search_memory(query: str) -> str:
        """Search long-term memory for relevant facts about the user."""
        results = memory_store.search(actor_id=actor_id, query=query, limit=10)
        return "\n\n".join(f"{r.memory.path}: {r.memory.content}" for r in results) or "No memory found."

    @function_tool
    def save_memory(path: str, content: str, description: str = "") -> str:
        """Save a durable, long-term memory about the user, replacing any memory at the same path."""
        memory_store.put(actor_id=actor_id, path=path, content=content, description=description or None)
        return f"Saved memory at {path}"

    @function_tool
    def list_memories() -> str:
        """List the paths and descriptions of the user's long-term memories."""
        memories = memory_store.list(actor_id=actor_id)
        return "\n".join(f"{m.path}: {m.description}" if m.description else m.path for m in memories) or "No memory found."

    @function_tool
    def forget_memory(path: str) -> str:
        """Delete the long-term memory at a path, such as when the user asks you to forget it."""
        memories = list(memory_store.list(actor_id=actor_id, path=path))
        for memory in memories:
            memory.delete()
        return f"Forgot memory at {path}" if memories else f"No memory at {path}"

    return [search_memory, save_memory, list_memories, forget_memory]

agent = Agent(
    name="Support agent",
    instructions="Save durable user preferences, recall them when relevant, and forget them when the user asks.",
    tools=make_memory_tools(memory_store, actor_id="user-123"),
)
```

`put()` creates the entry, or replaces the content of the entry already at that path. To add the content as new lines instead, pass `append=True`. `put()` isn't atomic, so concurrent writes to the same path can overwrite each other. `list(path=...)` returns the entries at that exact path in every session, so `forget_memory` also deletes any entry saved at the path under a session.

The same pattern works with the Claude Agent SDK and other frameworks: wrap the store's search, put, list, and delete operations as the framework's tool type.

If you also run a [memory pipeline](https://docs.databricks.com/gcp/en/agents/agent-memory/memory-pipelines.md) on the same memory store, the pipeline can rewrite, merge, split, or delete the entries your agent saves for any actor it processes.

## <a id="partition-and-secure-memory" />Partition and secure memory

Within a store, `actor_id` is how you separate whose memories are whose. Every list and search is scoped to a single `actor_id`, so pick the strategy that matches what your agent needs to remember:

* **Private memory for each user:** Set `actor_id` to the verified end-user identity. Each user gets their own partition, and the agent only recalls that user's entries.
  * *Example:* A support agent remembers one user's communication preferences and past tickets.
* **Shared memory for a group:** Set `actor_id` to a fixed key you choose, such as a team, project, or organization ID. Everyone reads and writes the same memories.
  * *Example:* A team agent remembers a shared glossary of company terms and internal conventions.
* **Memory split by something else:** Build `actor_id` from your own values, such as a tenant ID or a `user:project` composite.
  * *Example:* A multi-tenant app sets `actor_id` to `{tenant}:{user}` so each customer's users stay isolated from one another.

Set `actor_id` in your application code from trusted caller context: the verified end-user identity for per-user memory, or a trusted team or project key for shared memory. Never let the model choose it. If your strategy depends on an end-user identity, reject requests that don't carry one rather than falling back to a shared `actor_id`.

> [!WARNING]
>
> `actor_id` separates memories, but it is not an access control. Memory stores are workspace-scoped, so any principal that can reach a store can read and write every entry across all actors. The store, not the actor, is the security boundary. For strict isolation between tenants or users, create a separate memory store per boundary.

To let another principal, such as your agent's service principal, use a store, grant it access with the store's grant-permission operation (`memory_store.grant_permission(principal_id)` in the AgentKit SDK). Only the store's creator or a workspace admin can grant access. See [Manage permissions for agent memory and session stores](https://docs.databricks.com/gcp/en/agents/agent-memory/store-permissions.md) for permission levels, supported operations, and examples.

## Limitations

* Agent memory provides long-term memory only. For short-term conversation history, see [agent sessions](https://docs.databricks.com/gcp/en/agents/agent-memory/managed-sessions.md).
* Search ranks entries by relevance, combining full-text (BM25) and semantic matching over each entry's content and description. It returns up to 100 entries and doesn't support pagination.
* Access control is enforced at the store level. Per-entry and per-actor access control are not available.
* Store access control covers a store's entries. Any workspace user can list and get memory stores, including their IDs and descriptions.
* You can't change a store's ID after you create it. Only `description` can be updated.
* A workspace can have at most 50 memory stores. To increase this limit, contact your Databricks representative.

## Next steps

* [Agent memory and sessions](https://docs.databricks.com/gcp/en/agents/custom-agents/stateful-agents.md): Learn when to use sessions, memory, or both.
* [Agent sessions](https://docs.databricks.com/gcp/en/agents/agent-memory/managed-sessions.md): Store short-term conversation history within one interaction.
* [Agent memory pipelines](https://docs.databricks.com/gcp/en/agents/agent-memory/memory-pipelines.md): Distill memories automatically from the conversations in a session store.
* [Manage permissions for agent memory and session stores](https://docs.databricks.com/gcp/en/agents/agent-memory/store-permissions.md): Grant your deployed agent's service principal access to a memory store.
* [Agent API reference](https://docs.databricks.com/api/workspace/): Call the memory store REST API.
