CertSafari
    Databricks Certified Context Engineer Associate· Lessons

    Domain 4 · Lesson 21/45

    Memory type mismatch: session state vs cross-session memory

    Given a Databricks agent exhibiting degraded performance because its context is populated from an inappropriate memory source (e.g., retrieving from long-term storage when the information exists in the current session, or relying on session history when the needed context requires cross-session persistence), identify the mismatch between the memory type being used and the information need, and select the correct memory strategy.

    18 min read
    2.25% of exam
    8 sources
    Published 22 Oct 2026
    Docs as of 17 Oct 2026

    What you will be able to do

    • Classify any fact an agent needs as session state or cross-session memory using the future-conversation test
    • Recognise the two directions of a memory-type mismatch from an agent's symptoms
    • Choose the fix for each direction: answer from the session and write corrections back, or persist to a Lakebase-backed store keyed by actor_id
    • Describe Lakebase's role as the durable Postgres store behind agent sessions and agent memory
    • Decide which session facts should be distilled into memory before a session is dropped

    Key concept

    Session state vs cross-session memory — Session state is the working record of one conversation and is complete on its own; memory holds facts about a subject that must still be available in a later, separate conversation. You decide where a fact belongs by asking whether it would matter in a future, unrelated conversation.

    1.Two kinds of agent state and the test that separates them

    An agent that holds context needs two different things: the state of the conversation it is in right now, and what it knows from earlier conversations. Databricks keeps these in two separate managed stores. Agent sessions hold session state, most often the conversation history: the ordered record of messages, tool calls and results that the agent reads at the start of a turn and adds to as it runs. Agent memory holds durable facts, preferences and decisions that the agent recalls in later, separate conversations. When an agent pulls context from the wrong one of these stores, it gets worse at its job, and this lesson is about diagnosing exactly that.

    The two stores have different scopes. A session belongs to one interaction. It grows while the conversation goes on, it is complete on its own, and it is later cleared or ages out. A memory belongs to a subject, usually a user, and the agent recalls it whenever it is relevant, no matter which conversation it came from. The identifiers show the same split. session_id names one conversation so that a follow-up request can resume it. actor_id names whose conversations and memories they are, and both stores use it.

    To place a fact, ask one question: would this still matter in a future, unrelated conversation? A customer's timezone, a preferred contractor, or a decision to standardise on one cluster policy pass the test, so they belong in memory. The error message pasted three turns ago, the draft the agent is revising, or a label the user made up for this chat fail it, so they stay in the session. The guidance for agents that save memories applies the same test from the other direction: save only what will last, and leave out anything scoped to the current chat.

    Agent sessions and agent memory compared on the properties that decide which one a fact belongs in
    PropertyAgent sessions (session state)Agent memory (cross-session)
    Scoped toOne interactionA subject, such as a user
    Typical contentConversation transcript: messages, tool calls, resultsStable preferences, past decisions, ongoing projects
    Keyed byactor_id plus session_idactor_id plus path (session_id optional, for provenance)
    LifetimeGrows during the interaction, later cleared or ages outPersists after the session is deleted
    Read patternReplayed at the start of each turnRecalled when relevant, by search or by listing

    Checkpoint 1 of 9· Match them up

    Match each store or identifier to the role it plays in holding an agent's context

    Tap a term, then the definition that fits it.

    Sources123

    2.Direction one: querying memory for what the session already holds

    A memory-type mismatch can go two ways. In the first, the agent goes to long-term memory for information that is already in the current conversation. The memory store only knows what was saved in earlier sessions. Anything the user said in this conversation, or anything that changed today, is either missing from memory or stored there in an older version. An agent that searches memory first and trusts what it finds will apply an old answer even though the new one is in its own transcript.

    The fix has two parts, and a fix that does only one of them leaves a failure behind. First, the information in the conversation wins for the current turn. Memory guidance tells an agent to recall a fact when the answer depends on the user and it doesn't already have that fact from this conversation, and to skip memory when it already has what it needs. A correction the user just gave is something the agent already has. Second, if the correction passes the future-conversation test, the agent writes it back by updating or replacing the stored entry, not adding a second entry next to the old one. Without that write-back, the next conversation starts from the old value again.

    Each of the tempting alternatives breaks something:

    • Reading memory more often makes the problem worse, because the stored record is the out-of-date copy. A read before every response just applies the old fact more consistently.
    • Deleting the stored entry and relying only on the conversation turns direction one into direction two: the next conversation has nothing to recall.
    • Ignoring memory altogether drops the personalisation that the memory store exists to provide, which is the continuity it gives across conversations.

    Check how long the correction is meant to last before writing it back. 'I've moved to Denver' is a lasting change. 'Just for this trip, fly me out of Oakland' is scoped to this chat. The agent should use it in this conversation and should not save it.

    Checkpoint 2 of 9· Check yourself

    A support agent's memory store records that user-123 prefers email. Partway through today's conversation the user writes: 'For this ticket only, phone me instead.' What should the agent do?

    Checkpoint 3 of 9· Exam question

    A meal-planning agent has a persistent Lakebase record noting that a user is "vegetarian," written a month ago. In today's session, the user says "Actually, I've started eating fish again — please include seafood in tonight's suggestions." The agent's next recommendation still excludes seafood because it re-reads and applies the older persisted preference instead of the correction just given in the current turn. What is the correct fix?

    Sources3

    3.Direction two: relying on the session for facts that must outlive it

    The opposite failure comes from keeping a lasting fact only in session state. Suppose a renovation-planning assistant keeps everything in its in-context conversation buffer. On Monday the user names a preferred supplier. On Thursday the user opens a new conversation, and the agent asks for the supplier again. Nothing failed: the session was complete on its own and ended, and nothing carried the fact forward. A memory gives the agent continuity across conversations. A session only gives it continuity within one.

    The fix is to write the fact to a durable store keyed by the user's identity and to recall it when a new conversation starts. With agent memory, actor_id sets whose memory an entry is, so a fact saved under one user's actor_id on Monday can be found by searching that same actor_id on Thursday, in a different session. Set actor_id in trusted application code from the verified end-user identity, never from the model. If the model can choose it, the agent can read or write the wrong user's memories.

    Wrapping memory store search and add as agent tools, with actor_id fixed by the application rather than chosen by 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]

    Fixes that only change the session do not reach Thursday. A bigger context window lets one conversation hold more, but it starts empty in a new session. A scratchpad, or a summary added to the system prompt, lasts only as long as the conversation it was written in. Even a durable session store, which lets a conversation survive restarts and resume later, is keyed to that one conversation's session_id. A brand-new conversation does not replay it. The information has to be stored in memory, the store that is scoped to the subject.

    Checkpoint 4 of 9· Check yourself

    Which change lets the renovation assistant recall Monday's preferred supplier when the user opens a brand-new conversation on Thursday?

    Sources145

    4.Lakebase as the durable store behind both kinds of state

    Both stores run on Lakebase, Databricks' fully managed Postgres database. Creating a session store or a memory store provisions Lakebase storage for it automatically. Lakebase is what makes both kinds of state durable. A session store lets a conversation survive a restart. A memory store keeps facts after the conversation that produced them is gone. Lakebase-backed short-term memory captures context within one conversation using thread IDs and checkpointing. Long-term memory extracts key information across many conversations, and one agent can use both.

    Two common misunderstandings about Lakebase show up as wrong exam answers. Lakebase is not a cache that holds only the current turn: durable persistence is the point of using it. It is not a vector index used only for similarity search either. Agent memory can be retrieved by listing an actor's entries, filtered by session_id or path prefix, or by a natural-language search that ranks entries by full-text BM25 relevance. When an agent needs direct SQL access to its memories or a custom schema, the legacy self-managed approach puts memory in Lakebase tables that the team designs and runs itself.

    Checkpoint 5 of 9· Check yourself

    An architect is designing a Databricks agent that uses both a session store and a memory store. What does Lakebase provide in this design?

    Checkpoint 6 of 9· Exam question

    A scheduling assistant helps a user plan a multi-week home renovation. On Monday, the user tells the agent their preferred contractor is "BuildRight Co." When the user returns on Thursday to continue planning, in a brand-new conversation, the agent has no memory of the preferred contractor and asks the user to repeat it. The agent currently keeps all state only in the in-context conversation buffer, which is discarded when each session ends. What is the correct memory strategy to fix this?

    Checkpoint 7 of 9· Exam question

    Which statement accurately describes Lakebase's role in an agent memory architecture?

    Sources647

    5.Deciding what to distill before a session is dropped

    Long-running agents often save what matters and then start over with a clean context. That technique is covered in Distill to memory, then start a fresh context. The future-conversation test is how you decide what to save. Sessions and memories meet at the point where something in a conversation is worth keeping. An agent, the application, or a memory pipeline distills the durable facts into the memory store, and the session can then be cleared. The two stores are independent, so deleting a session or a whole session store does not delete memories already written from it.

    Memory pipelines distill on purpose. A pipeline captures durable domain knowledge, such as authoritative sources, metric definitions, terminology, team conventions, workflows and ongoing projects. It is designed to skip three kinds of session content that fail the test:

    • Values from live sources that change, such as a table's current row count. The pipeline records how to find or compute the value instead.
    • Details the agent can look up with its tools, such as a table's schema.
    • Secrets, such as passwords, API keys and tokens.

    A pipeline also catches facts the agent missed. An agent that saves memory during a conversation sees only that conversation, so facts it didn't think to save never reach memory. A pipeline runs afterwards with all of an actor's conversations and existing memory in view, so it can add what was missed and merge overlapping entries. If a session is dropped before anyone distills it, the facts that passed the test are lost.

    Checkpoint 8 of 9· Match them up

    A memory pipeline is processing a data-analysis session. Match each item from the conversation to how the pipeline handles it.

    Tap a term, then the definition that fits it.

    Checkpoint 9 of 9· Check yourself

    A memory pipeline has already distilled last quarter's support conversations into a memory store. To cut storage, the team then deletes the whole session store. What happens to the agent's memory?

    Sources185

    Sources

    (8)

    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 and the test that separates them
      “A session grows within the interaction and is complete on its own.”
      ↩︎ Two kinds of agent state and the test that separates them
      “sessions give the agent continuity within a conversation, and memory gives it continuity across conversations”
      ↩︎ Direction two: relying on the session for facts that must outlive it
      “The session is later cleared or ages out, but the memory persists.”
      ↩︎ Deciding what to distill before a session is dropped
      “the durable facts that should still matter in a future, unrelated conversation”
      ↩︎ Key concept
      “sessions give the agent continuity within a conversation, and memory gives it continuity across conversations”
      ↩︎ Exam trap 2
      “deleting a session, or an entire session store, does not delete memory retained in a memory store.”
      ↩︎ Checkpoint
    2. 2.
      “actor_id identifies whose conversations and memories they are.”
      ↩︎ Two kinds of agent state and the test that separates them
      “session_id identifies one conversation, so that a follow-up request resumes it.”
      ↩︎ Two kinds of agent state and the test that separates them
      “actor_id identifies whose conversations and memories they are. Both stores use it”
      ↩︎ Checkpoint
    3. 3.
      “Save only what will still matter in a future, unrelated conversation”
      ↩︎ Two kinds of agent state and the test that separates them
      “and you don't already have it from this conversation”
      ↩︎ Direction one: querying memory for what the session already holds
      “If the user's info changes or contradicts what's stored, update or replace it rather than keeping both”
      ↩︎ Direction one: querying memory for what the session already holds
      “If the user's info changes or contradicts what's stored, update or replace it rather than keeping both”
      ↩︎ Exam trap 1
      “Don't save your own suggestions or guesses, passing chatter, secrets, or anything scoped to this chat”
      ↩︎ Checkpoint
    4. 4.
      “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.”
      ↩︎ Direction two: relying on the session for facts that must outlive it
      “Search returns the most relevant entries ranked by a full-text (BM25) relevance score.”
      ↩︎ Lakebase as the durable store behind both kinds of state
    5. 5.
      “Persist an agent's conversation history so it survives restarts and can be resumed later.”
      ↩︎ Direction two: relying on the session for facts that must outlive it
      “Deleting a session or session store does not delete memory retained in a memory store.”
      ↩︎ Deciding what to distill before a session is dropped
      “Deleting a session or session store does not delete memory retained in a memory store.”
      ↩︎ Exam trap 4
    6. 6.
      “Lakebase provides a fully managed Postgres backend for storing agent state and memory”
      ↩︎ Lakebase as the durable store behind both kinds of state
      “Captures context within a single conversation session using thread IDs and checkpointing.”
      ↩︎ Lakebase as the durable store behind both kinds of state
      “Lakebase provides a fully managed Postgres backend for storing agent state and memory”
      ↩︎ Exam trap 3
    7. 7.
      “Self-managed agent memory uses Databricks Lakebase, a fully managed Postgres OLTP database, as a durable memory store for your agents.”
      ↩︎ Lakebase as the durable store behind both kinds of state
    8. 8.
      “Values from live sources that change over time, such as a table's current row count.”
      ↩︎ Deciding what to distill before a session is dropped
      “Details that the agent can look up with its tools, such as a table's schema.”
      ↩︎ Deciding what to distill before a session is dropped
      “A memory pipeline works after the fact, with all of an actor's conversations and existing memory in view”
      ↩︎ Deciding what to distill before a session is dropped
      “Values from live sources that change over time, such as a table's current row count. It records how to find or compute the value instead.”
      ↩︎ Checkpoint

    Ready to test yourself?

    Practise Databricks Certified Context Engineer Associate in quiz mode.

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