---
title: Agent sessions
description: Agent sessions store an agent's conversation history in Lakebase, so agents built with any framework can read from and append to it across turns.
canonical_url: https://docs.databricks.com/gcp/en/agents/agent-memory/managed-sessions
---

# Agent sessions

> [!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 sessions give your agents a durable, framework-agnostic store for session state: the state an agent or framework keeps for one interaction. Most commonly this is the conversation history, the ordered transcript of messages, tool calls, and results that an agent reads at the start of a turn and appends to as it runs. It can also be any other state a framework persists for the interaction, such as a LangGraph graph. Databricks stores it in [Lakebase](https://docs.databricks.com/gcp/en/oltp/projects/index.md) and manages the storage for you, so you don't build or operate the database.

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

Use agent sessions when you want to:

* Persist an agent's conversation history so it survives restarts and can be resumed later.
* Reconstruct full context (including tool calls and reasoning) on a follow-up message.
* List, resume, and branch past conversations from your own UI.

Agent sessions hold the state of a single interaction (short-term, in-session state). For long-term memory that persists *across* conversations, use [agent memory](https://docs.databricks.com/gcp/en/agents/agent-memory/managed-memory.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-sessions.md#get-started) directly from any language, with no Python requirement.
* To use the REST API examples, install the [Databricks CLI](https://docs.databricks.com/gcp/en/dev-tools/cli/install.md) (to generate an OAuth token), `curl`, and `jq`.

## How agent sessions work

![Agent sessions resource hierarchy: a session store contains many sessions, and each session contains many ordered session items.](https://docs.databricks.com/gcp/en/images/generative-ai/agent-platform/managed-sessions-hierarchy.svg)

Agent sessions have three levels:

* A **session store** is the workspace-scoped container for an agent's sessions. Creating a store provisions the backing Lakebase storage automatically. You choose a workspace-unique store ID and use it to refer to the store in later calls. Pass the store ID as:
  * The `name` argument in the AgentKit SDK.
  * The `session_store_id` query parameter in the REST API.
* A **session** is one durable interaction (typically a conversation thread) within a store. A session is identified by:
  * `actor_id` (required): who the session belongs to, such as an end user or another agent. It groups all of one subject's sessions so you can list and filter them together. When you build a per-user app, set `actor_id` to the user's ID (for example, the verified end-user identity from your app's authentication) so each user's sessions stay grouped. Set it from trusted application context, never a model- or user-supplied value.
  * `session_id` (optional): a caller-chosen ID for the interaction. The service generates one when you omit it.
  * `parent_session_id` (optional): makes the session a child of another session in the store, such as a sub-agent's conversation. Set it when you create the session.
* A **session item** is one entry in a session's ordered history. Each item holds an opaque, JSON-compatible `data` value, such as a message, tool call, tool result, or reasoning block. Databricks assigns each item an `item_id` and a `create_time` and does not inspect or validate its contents. Items are immutable after they are appended.

The service maintains a deterministic order for a session's items and authorizes every operation against the session store.

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

These examples set up agent sessions for a support agent: they create a session store, start a session for one conversation, append the conversation's turns, and read the history back on a later request. Choose the client that fits your project.

Store IDs are unique within a workspace. If you run both tabs, or the ID is already taken, choose a different ID or delete the existing store first. Store responses also include a service-assigned UUID in `session_store_id`. Later calls use the store ID you chose.

### 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
   ```

   The `databricks-agentbricks` package provides the `databricks_agentkit` Python module.

2. Create a session store, then start a session for one conversation. `actor_id` is who the conversation belongs to; the optional `session_id` uniquely identifies this conversation:

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

   client = AgentKitClient(WorkspaceClient())
   session_store = client.session_stores.create("support-agent-sessions-sdk")
   session = session_store.add(actor_id="customer-123", session_id="case-456")
   ```

3. Append the conversation's turns as the agent runs. Each item is any JSON-compatible value:

   ```python
   session.append_items(
       [
           {"type": "message", "role": "user", "content": "I need help with my cluster."},
           {"type": "message", "role": "assistant", "content": "Let's take a look."},
       ]
   )
   ```

4. On a follow-up request, reload the session and read its full history to rebuild context:

   ```python
   session = session_store.get("case-456")
   # Request chronological order; list_items defaults to newest-first and auto-pages.
   history = [item.data for item in session.list_items(order_by="create_time asc")]
   ```

### REST API

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

1. Set `DATABRICKS_HOST` to your workspace URL, including `https://`, and then generate an OAuth token with the Databricks CLI:

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

2. Create a session store for your agent:

   ```bash
   curl -X POST "${DATABRICKS_HOST}/api/2.0/agents/session-stores?session_store_id=support-agent-sessions-rest" \
     -H "Authorization: Bearer ${DATABRICKS_TOKEN}" -H "Content-Type: application/json" \
     -d '{"description": "Support agent conversation history"}'
   ```

3. Start a session for one conversation. `actor_id` is who it belongs to; `session_id` uniquely identifies this conversation:

   ```bash
   curl -X POST "${DATABRICKS_HOST}/api/2.0/agents/session-stores/support-agent-sessions-rest/sessions?session_id=case-456" \
     -H "Authorization: Bearer ${DATABRICKS_TOKEN}" -H "Content-Type: application/json" \
     -d '{"actor_id": "customer-123"}'
   ```

4. Append a conversation turn as the agent runs:

   ```bash
   curl -X POST "${DATABRICKS_HOST}/api/2.0/agents/session-stores/support-agent-sessions-rest/sessions/case-456/items:append" \
     -H "Authorization: Bearer ${DATABRICKS_TOKEN}" -H "Content-Type: application/json" \
     -d '{"items": [{"data": {"type": "message", "role": "user", "content": "I need help with my cluster."}}]}'
   ```

5. Read the history back in chronological order to rebuild context:

   ```bash
   curl -G "${DATABRICKS_HOST}/api/2.0/agents/session-stores/support-agent-sessions-rest/sessions/case-456/items" \
     -H "Authorization: Bearer ${DATABRICKS_TOKEN}" --data-urlencode "order_by=create_time asc"
   ```

   The response returns items in `session_items`, up to `page_size` per request (default 10, maximum 100). When more items remain, it includes `next_page_token`. Pass that value as `page_token` and repeat until the response has no `next_page_token`. The AgentKit SDK's `list_items` pages for you.

   For example, this loop reads the full history 100 items at a time:

   ```bash
   PAGE_TOKEN=""
   while true; do
     RESPONSE=$(curl -s -G "${DATABRICKS_HOST}/api/2.0/agents/session-stores/support-agent-sessions-rest/sessions/case-456/items" \
       -H "Authorization: Bearer ${DATABRICKS_TOKEN}" \
       --data-urlencode "order_by=create_time asc" --data-urlencode "page_size=100" \
       ${PAGE_TOKEN:+--data-urlencode "page_token=${PAGE_TOKEN}"})
     echo "${RESPONSE}" | jq -c '.session_items[]?.data'
     PAGE_TOKEN=$(echo "${RESPONSE}" | jq -r '.next_page_token // empty')
     [ -z "${PAGE_TOKEN}" ] && break
   done
   ```

The clients also support removing the most recent item, clearing a session's items, and forking a conversation into an independent copy (optionally up to a specific item). A fork has no parent session, and deleting the source session doesn't delete it. Deleting a session always deletes its child sessions and their items.

## Back an agent framework's session with agent sessions

Agent frameworks such as the OpenAI Agents SDK and the Claude Agent SDK read conversation history at the start of a run and append new items at the end. The session store maps directly onto that pattern:

| Framework operation | AgentKit SDK call                        |
| :------------------ | :--------------------------------------- |
| Read history        | `list_items(order_by="create_time asc")` |
| Add turn items      | `append_items(items)`                    |
| Undo last item      | `pop_item()`                             |
| Clear the thread    | `clear_items()`                          |

## Scope and access

Agent sessions store a session's items as opaque, JSON-compatible values: the service persists and returns whatever your agent or framework appends, without interpreting it. It doesn't add execution-control resources such as runs, checkpoints, or approvals as first-class concepts, though a framework that serializes such state can persist it as items.

Session stores are workspace-scoped, and access is authorized at the store level. Store access control covers a store's sessions. Any workspace user can list and get session stores, including their IDs and descriptions. The `actor_id` and `metadata` fields support grouping and filtering only; they do not grant or restrict access. Set the `actor_id` from trusted application context rather than a model- or user-supplied value.

To let another principal, such as your agent's service principal, use a store, grant it access with the store's grant-permission operation (`session_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.

Agent sessions and [agent memory](https://docs.databricks.com/gcp/en/agents/agent-memory/managed-memory.md) are independent. Deleting a session or session store does not delete memory retained in a memory store. To build long-term memory from the sessions in a store, create a [memory pipeline](https://docs.databricks.com/gcp/en/agents/agent-memory/memory-pipelines.md).

## Next steps

* [Agent memory](https://docs.databricks.com/gcp/en/agents/agent-memory/managed-memory.md)
* [Agent memory pipelines](https://docs.databricks.com/gcp/en/agents/agent-memory/memory-pipelines.md)
* [Agent API reference](https://docs.databricks.com/api/workspace/)
