Cert EspressoLearn. Practise. Find your flow.

A LITTLE FOCUS.
A BIG NEXT STEP.

Your pace. Your space.
Databricks · Databricks Context Engineer Associate

Session State and Long-Term Memory in Lakebase

Databricks Context Engineer Associate · Lesson 10 of 18 · 1:11:47

YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗

Learning with these videos? Subscribe for new courses and exam-style questions.

In this lesson

Prepare for the Databricks Certified Context Engineer Associate exam. In this lesson: session state versus long-term memory, matching the memory type to the information need, configuring persistent memory across sessions in Lakebase (memory stores, entries, actor IDs, paths, memory pipelines), and writing memories safely. Includes three original practice questions.

Study notes

The text of this lesson, to read at your own pace. Information as of November 2026.

Forgetful, and too eager to remember

Thistledown's tenant agent forgets that a tenant prefers email, and asks again in every new conversation. Yet within one conversation, it searches its long term memory for a unit number the tenant gave a minute ago, and finds the unit of an old lease. This lesson covers the two kinds of agent state, how to match memory to the information need, and how to configure persistent memory in Lakebase.

Two kinds of state

An agent holds two kinds of state. Session state belongs to one interaction: the ordered history of messages, tool calls, and results, which the agent reads at the start of each turn, and appends to as it runs. Long term memory belongs to a subject, like a tenant: durable facts, preferences, and decisions that still matter in a future, unrelated conversation. On Databricks, agent sessions and agent memory are both managed stores, backed by Lakebase. And they are independent: deleting a session does not delete the memories drawn from it.

Matching memory to the need

Most memory failures are a mismatch between where the information is kept, and where the agent looks. If the answer was given earlier in this conversation, take it from the session, since long term memory may return an older, conflicting fact. If it must survive the end of the conversation, like a preference or a past decision, save it to long term memory, since a session is replayed only within its own interaction. So ask two questions: does this need outlive the conversation, and is it about the subject, or about this one task?

Persistent memory in Lakebase

To configure persistent memory, create a memory store, a workspace container whose Lakebase storage, indexing, and search are managed for you. Each memory entry has its content, a short description used for retrieval, an actor ID for whose memory it is, and a path that organizes it, like a preferences folder. Leave the session ID unset for memory that applies across all of the actor's sessions, since a session filter only returns entries saved with that session. The agent recalls entries with a natural language search, or lists them by path. And a memory pipeline can distill sessions into memories, on demand or on a schedule, without memory writing tools in the agent.

Writing memories safely

When the agent saves and recalls memories itself, wrap the store's operations as tools, and say in the system prompt when to use them. Set the actor ID in trusted application code, from the verified identity of the user, and never let the model choose whose memory to read or write. Save durable facts, not every message, so the store stays useful for search. And provide a way to forget, when a user asks the agent to delete what it knows.

Recap

Let's recap. Session state is one interaction's history, while long term memory holds a subject's durable facts across conversations. Take from the session what this conversation already said, and save to memory what must outlive it. A memory store in Lakebase holds entries with content, a description, an actor ID, and a path. Memory pipelines distill sessions into memories, and the two stores are independent. And set the actor ID in trusted code, never from the model.

Quick checks for this lesson

The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.

  1. Two messages ago, a tenant gave the unit number for a repair. The agent now searches long-term memory for it, and finds the unit of the tenant’s previous lease. What should it do instead?

    • Search memory with a higher relevance threshold
    • Save every message to long-term memory
    • Take the unit from the current session history
    • Ask the tenant to start a new conversation
    Show the answer

    Take the unit from the current session history

    The unit number is in the current session, so the agent should take it from the session history, not from long term memory. “Search memory with a higher relevance threshold” is wrong, since a stricter search still looks in the wrong store. “Save every message to long-term memory” is wrong, since saving every message pollutes memory with details that only matter today. And “Ask the tenant to start a new conversation” is wrong, since a new conversation loses the very history that holds the answer.

  2. Tenants complain the agent asks for their preferred contact channel in every new conversation, although they gave it before. The agent only replays session history. Which change fits?

    • Load the last ten sessions into every prompt
    • Save the preference to a memory store, recalled by search
    • Use a model with a larger context window
    • Keep each conversation open for months
    Show the answer

    Save the preference to a memory store, recalled by search

    A durable preference belongs in long term memory, saved for the tenant's actor ID, and recalled in any later conversation. “Load the last ten sessions into every prompt” is wrong, since replaying old sessions wastes tokens, and still misses the older ones. “Use a model with a larger context window” is wrong, since a larger window does not carry anything from one conversation to the next. And “Keep each conversation open for months” is wrong, since one endless session grows without limit, and is the wrong place for durable facts.

  3. The tenant agent has a save memory tool that takes the actor ID as an argument, filled in by the model. What is the main risk?

    • Entries are saved without a description
    • Memories expire when the session ends
    • Search only works within one session
    • The model reaches another tenant’s memory
    Show the answer

    The model reaches another tenant’s memory

    If the model chooses the actor ID, a confused or manipulated prompt can reach another tenant's memory, so set it in trusted code from the verified identity. “Entries are saved without a description” is wrong, since descriptions improve retrieval, but their absence is not the main risk. “Memories expire when the session ends” is wrong, since memories outlive sessions, and the two stores are independent. And “Search only works within one session” is wrong, since search covers all of the actor's entries, unless a session filter is set.