CertSafari
    Databricks Certified Generative AI Engineer Associate· Lessons

    Domain 4 · Lesson 38/56

    Agent sessions and memory stores on Lakebase

    Configure a persistent datastore to store and retrieve intermediate memory or structured information.

    15 min read
    1.47% of exam
    5 sources
    Published 22 Oct 2026
    Docs as of 17 Oct 2026

    What you will be able to do

    • Tell session state apart from long-term memory, and pick the right store for each
    • Create a session store, then append, read, fork and delete conversation history
    • Save and search memory entries, and let an agent decide what to remember through tools
    • Partition memory with actor_id, and use separate stores to enforce isolation
    • Recognize the legacy Unity Catalog memory store and when its governance model is what a requirement asks for

    Key concept

    Sessions versus memory — A session holds the working state of a single interaction, usually the ordered conversation transcript, and the agent replays it to continue that interaction. Memory holds durable facts about a subject, such as a user's preferences, and the agent recalls them in later, unrelated conversations.

    1.Two kinds of agent state

    An LLM call has no memory of its own. If a support agent is to answer "and what about the second cluster?" or remember next week that a customer prefers email, that context has to be written to a datastore and read back. Databricks offers two managed stores for this. Both run on Lakebase, its managed Postgres, and both work with agents built on any framework.

    Agent sessions hold one interaction's state. Usually that means the transcript of messages, tool calls and results, though it can be any state a framework persists, such as a LangGraph graph. The agent reads the session at the start of a turn and appends to it as it runs. Agent memory holds durable facts, preferences and decisions. The agent finds them by search in later, separate conversations.

    The two differ in scope. A session belongs to one conversation and is complete in itself. A memory belongs to a subject, usually a user or a team, and it still matters when that subject starts an unrelated conversation. Most agents use both: sessions keep a conversation coherent, and memory carries knowledge from one conversation to the next. Sessions alone are enough when the agent only needs in-interaction state. Memory alone fits when the framework already manages session state.

    There are three ways for a fact to move from a session into memory: the agent writes it, the application writes it, or a memory pipeline distills it. A pipeline reads the conversations in a session store, pulls out the durable facts, and writes them to a memory store. It can run on demand or on a schedule, so the agent needs no memory-writing tools. Once a fact is in memory, it no longer depends on the session it came from. The session can be cleared or age out and the fact remains. This is the reason the two stores are independent.

    Checkpoint 1 of 7· Match them up

    Match each agent requirement to the store setup it calls for.

    Tap a term, then the definition that fits it.

    Sources1

    2.Session stores, sessions and items

    Agent sessions are organized in three levels.

    • A session store is the workspace-scoped container. Creating one provisions its Lakebase storage automatically, and its name must be unique in the workspace and 3 to 63 characters long.
    • A session is one durable interaction, typically a conversation thread. It carries a required actor_id (who it belongs to), an optional session_id (generated by the service if you omit it), and an optional parent_session_id (the session it was forked from).
    • A session item is one entry in the session's ordered history. It holds an opaque, JSON-compatible value such as a message, tool call, tool result or reasoning block.

    The service gives each item an item_id and a create_time but never inspects or validates the contents. Items cannot be changed after they are appended.

    Create a session store and a memory store once, then reuse them for every conversationpython
    from databricks.sdk import WorkspaceClient
    from databricks_agentkit import AgentKitClient
    
    client = AgentKitClient(WorkspaceClient())
    client.session_stores.create("support-agent-sessions", description="Support agent conversations")
    client.memory_stores.create("support-agent-memory", description="Support agent long-term memory")

    A turn follows the same pattern in most frameworks. The agent reads the history, runs, and appends the new items. One detail catches people out: list_items returns the newest item first, so to rebuild context in conversation order you have to request order_by="create_time asc". The example below also checks ownership, because looking up a session by session_id is not scoped to an actor. Without that check, any user who knows another user's conversation ID could resume it.

    Resume a conversation: verify the owner, rebuild history oldest-first, append the new turnpython
    def handle_message(user_id: str, conversation_id: str, message: str) -> str:
        session = session_store.get(conversation_id)
        if session.actor_id != user_id:
            raise PermissionError("This conversation belongs to a different user.")
    
        # Rebuild context from the stored history, oldest first.
        history = [item.data for item in session.list_items(order_by="create_time asc")]
        user_item = {"type": "message", "role": "user", "content": message}
        reply = run_agent([*history, user_item])  # Your framework or model call.
    
        session.append_items([user_item, {"type": "message", "role": "assistant", "content": reply}])
        return reply
    How framework history operations map onto the session store
    Framework operationSession store call
    Read historylist_items in chronological order (order_by="create_time asc")
    Add turn itemsappend the new items
    Undo last itempop the most recent item
    Clear the threadclear the session's items

    Branching and deletion are built on the parent link. Forking a conversation produces an independent copy, optionally cut off at a specific item, and the new session's parent_session_id points back to the original. That is how a UI can let a user retry from an earlier turn. Because of these links, deleting a session that has children fails unless you pass a force option, for example session.delete(force=True), which cascades the delete to the children.

    The store keeps whatever the framework appends, and nothing more. Runs, checkpoints and approvals are not first-class resources. A framework that serializes that kind of state can still persist it as items.

    Checkpoint 2 of 7· Check yourself

    A per-user support app creates each session with actor_id set to the verified user. A handler loads a conversation with session_store.get(conversation_id), using an ID taken from the request, and then appends the new turn. If user B sends user A's conversation ID, what happens?

    Checkpoint 3 of 7· Fill the gap

    This line rebuilds a session's history so the agent can replay the conversation in the order it happened. Which value completes it?

    history = [item.data for item in session.list_items(order_by=" ? ")]

    Sources23

    3.Saving and searching memory entries

    A memory store is the workspace-scoped container for long-term memory. As with session stores, creating one provisions its Lakebase storage, and Databricks runs the indexing and search. The store's display_name must be 3 to 56 characters: lowercase letters, numbers and hyphens, starting with a lowercase letter and ending with a letter or number. A name like Support_Memory is rejected.

    Each memory entry has free-form content and a short description that improves retrieval. Its fields are a required actor_id (whose memory it is), an optional session_id (which session it came from, for provenance), and a required path that organizes entries within an actor, such as /preferences/communication.md. The combination of actor_id, session_id and path uniquely identifies an entry.

    Entries can be retrieved in two ways, and both are scoped to one actor. List returns an actor's entries, optionally filtered by session_id or a path prefix, which suits a page showing everything the agent knows about a user. Search takes a natural-language query and ranks the actor's entries by full-text BM25 relevance. Use search at answer time, when the agent needs whatever bears on the current question.

    To let the agent decide what to remember, wrap search and add as tools and use the system prompt to say when to call them. The important part is what the tools leave out: actor_id is bound in application code when the tools are built, so the model can choose the query, path and content but never whose memory it reads or writes. The same wrapping works for the OpenAI Agents SDK, the Claude Agent SDK and other frameworks.

    Memory exposed as agent tools, with actor_id fixed by trusted code rather than the modelpython
    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."""
            memory_store.add(actor_id=actor_id, path=path, content=content, description=description)
            return f"Saved memory at {path}"
    
        return [search_memory, save_memory]

    Checkpoint 4 of 7· Check yourself

    Your team is giving a multi-user support agent search_memory and save_memory tools so it can decide for itself what to remember. Which design stops the model from reading or writing another user's memories?

    Sources4

    4.Partitioning with actor_id and securing the store

    In both stores, actor_id decides whose data a read returns, and every list and search covers a single actor. Choose the value according to who should share what.

    actor_id strategies for a memory store
    Strategyactor_id valueExample
    Private memory for each userThe verified end-user identityA support agent remembers one user's communication preferences and past tickets
    Shared memory for a groupA fixed key such as a team, project or organization IDA team agent remembers a shared glossary of company terms
    Memory split by something elseA composite such as {tenant}:{user}Each customer's users in a multi-tenant app stay isolated from one another

    Set actor_id in application code from trusted request context, never from model output or a value the user typed. If your strategy depends on an end-user identity and a request arrives without one, reject the request. Do not fall back to a shared actor_id. A fallback like that quietly puts anonymous users' facts into one pool that every one of them can read.

    actor_id organizes data. It does not grant or restrict access, in either store. Both store types are workspace-scoped and authorize access at the store level, so any principal that can reach a store can read and write every entry for every actor. The store is the security boundary. When tenants must be strictly isolated, give each tenant its own store, or its own pair of session and memory stores. To let a principal such as the agent's service principal use a store, call that store's grant-permission operation: memory_store.grant_permission(principal_id) or session_store.grant_permission(principal_id).

    Checkpoint 5 of 7· Match them up

    Several teams are designing their agents' memory. Pair each requirement with the setup that meets it.

    Tap a term, then the definition that fits it.

    Sources423

    5.The Unity Catalog memory store

    Before the Lakebase-backed agent memory, Databricks offered a managed memory store governed by Unity Catalog. It is now deprecated for new agents. It still matters because its governance model differs from the current store's. In that design, a memory store is a Unity Catalog securable that acts as a container for entries, created under a schema by a principal holding the CREATE MEMORY STORE privilege on that schema. Like any Unity Catalog asset, it inherits governance, access control and lineage. Agents across different projects can share it, and Unity Catalog decides who can reach it.

    Entries in the legacy store are identified by a scope and a path. The scope plays the role actor_id plays now: the application sets it on every read and write, and a search only returns entries with a matching scope. A scope keeps one user's memories private or shares them across a group, but nothing beyond that. It does not make a user's private entries visible to other agents.

    Which memory store fits which governance requirement
    RequirementAgent memory (Lakebase-backed)Managed agent memory (legacy, Unity Catalog)
    What the store isWorkspace-scoped container addressed by display_nameUnity Catalog securable under a schema
    Who may create oneAny principal able to create stores in the workspaceA principal with CREATE MEMORY STORE on the parent schema
    How access is controlledStore-level grant via grant_permissionUnity Catalog governance, access control and lineage
    Partition key inside the storeactor_idscope

    Checkpoint 6 of 7· Check yourself

    Durable knowledge must be shared by agents across several projects, and governance requires Unity Catalog to enforce access control and record lineage for it. Which store meets that requirement?

    Checkpoint 7 of 7· Exam question

    A platform team wants multiple agents across different projects to share durable, long-term knowledge about company policies, and they need Unity Catalog to enforce access control and lineage on that knowledge. Which persistence approach satisfies these requirements?

    Sources51

    Sources

    (5)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “Sessions are scoped to one interaction: the working state the agent replays to continue that interaction, such as its conversation transcript.”
      ↩︎ Two kinds of agent state
      “A memory pipeline reads the conversations in a session store, extracts the durable facts, and writes them to a memory store”
      ↩︎ Two kinds of agent state
      “Managed agent memory (legacy): the earlier managed memory store, governed by Unity Catalog.”
      ↩︎ The Unity Catalog memory store
      “Memories are scoped to a subject, not an interaction”
      ↩︎ Key concept
      “deleting a session, or an entire session store, does not delete memory retained in a memory store.”
      ↩︎ Exam trap 2
      “deleting a session, or an entire session store, does not delete memory retained in a memory store.”
      ↩︎ Prediction
      “Use sessions alone when you only need in-interaction state, or memory alone when your framework already manages session state.”
      ↩︎ Checkpoint
    2. 2.
      “parent_session_id (optional): links a session to the one it was forked from, to represent branched conversations.”
      ↩︎ Session stores, sessions and items
      “Items are immutable after they are appended.”
      ↩︎ Session stores, sessions and items
      “list_items defaults to newest-first and auto-pages”
      ↩︎ Session stores, sessions and items
      “Deleting a session that has child sessions requires a force option to cascade the deletion to them”
      ↩︎ Session stores, sessions and items
      “The actor_id and metadata fields support grouping and filtering only; they do not grant or restrict access.”
      ↩︎ Partitioning with actor_id and securing the store
    3. 3.
      “Looking up a session by session_id isn't scoped to an actor”
      ↩︎ Session stores, sessions and items
      “A session store name must be 3 to 63 characters.”
      ↩︎ Session stores, sessions and items
      “The store is the security boundary: any principal with access to a store can read and write all of its entries.”
      ↩︎ Partitioning with actor_id and securing the store
      “Looking up a session by session_id isn't scoped to an actor, so check that the session belongs to the requesting user before you resume it.”
      ↩︎ Checkpoint
    4. 4.
      “An entry is uniquely identified by the combination of actor_id, session_id, and path.”
      ↩︎ Saving and searching memory entries
      “Search returns the most relevant entries ranked by a full-text (BM25) relevance score.”
      ↩︎ Saving and searching memory entries
      “Never let the model choose whose memory to read or write.”
      ↩︎ Saving and searching memory entries
      “the pipeline can rewrite, merge, split, or delete the entries your agent saves for any actor it processes.”
      ↩︎ Saving and searching memory entries
      “reject requests that don't carry one rather than falling back to a shared actor_id.”
      ↩︎ Partitioning with actor_id and securing the store
      “actor_id separates memories, but it is not an access control.”
      ↩︎ Exam trap 1
      “For strict isolation between tenants or users, create a separate memory store per boundary.”
      ↩︎ Checkpoint
    5. 5.
      “This is an earlier version of the managed agent memory store and is deprecated.”
      ↩︎ The Unity Catalog memory store
      “The CREATE MEMORY STORE privilege on the parent schema to create memory stores.”
      ↩︎ The Unity Catalog memory store
      “a search only returns entries with a matching scope”
      ↩︎ The Unity Catalog memory store
      “A memory store inherits the same governance, access control, and lineage as any other Unity Catalog asset.”
      ↩︎ Exam trap 3

    Continue to part 2 of 2

    Lakebase persistence for LangGraph agents on Databricks Apps

    Spotted a mistake, or was something unclear? Tell us.