How do I persist conversation state across AI agent sessions?
Summary
- Move conversation history out of process memory into a durable store keyed by who the conversation belongs to and which conversation it is. Read the history at the start of each turn, append new items at the end, and resume by ID after a restart.
- Persist the full transcript, including tool calls and results, not only the text replies, so a follow-up request can rebuild the agent's complete context.
- Keep two layers: session state continues one conversation, while long-term memory carries durable facts into new, separate conversations.
- On Databricks, agent sessions (Beta) is a managed, framework-agnostic session store that runs on Lakebase. For LangGraph, a drop-in checkpointer stores full graph state, including human-in-the-loop interrupts.
- Set the user key from your app's verified identity, and check that a session belongs to the requesting user before you resume it.
How do I persist conversation state across AI agent sessions?
Store each conversation's state in a durable session store instead of the agent's process, keyed by a user ID and a conversation ID. At the start of every turn, the agent reloads that history. As it runs, it appends the new user message, model output and tool items. After a restart, the next request picks up where the conversation left off. For knowledge that should outlive a single conversation, such as a user's preferences, write it to long-term memory as well.
On Databricks, the managed option is agent sessions, which is in Beta and runs on Lakebase.
What is conversation state?
Conversation state is what an agent or framework keeps for one interaction. The agent sessions docs describe it as most often "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 framework state, such as a serialized LangGraph graph.
That is different from long-term memory, which holds facts about a user or team that the agent recalls in later, unrelated conversations. Sessions give continuity within a conversation; memory gives continuity across conversations.
What a conversation-state store needs
| Requirement | Why it matters |
|---|---|
| Durable storage outside the process | History survives restarts and can be resumed later |
| Ordered, immutable items | The agent replays turns in a deterministic order |
| Full-fidelity items | Tool calls, results and reasoning are kept, not only text replies |
| User and conversation keys | You can list a user's threads and resume any one of them |
| Ownership checks | One user can't resume another user's conversation by guessing an ID |
| Undo, clear and fork | Your UI can retry a turn, reset a thread or branch it |
| Store-level access control | Access is granted per store, so you can limit transcripts to the agent and approved principals |
| A path to long-term memory | Durable facts can be distilled out before a session is cleared |
How to persist conversation state on Databricks
Agent sessions give agents a durable, framework-agnostic store for session state, and Databricks manages the Lakebase storage behind it. A session store holds sessions, each identified by an actor_id and an optional session_id. Sessions hold ordered, immutable items, and parent_session_id links a sub-agent's conversation to its parent.
- Install the SDK.
pip install --upgrade "databricks-agentbricks>=0.6.0"installs the AgentKit SDK, the Agent Bricks CLI (Beta) and framework adapters. - Create a store one time.
client.session_stores.create("support-agent-sessions", description="Support agent conversations"), or theagentbricks sessions stores createCLI command. - Choose the keys. Set
actor_idfrom trusted request context, such as the signed-in user's verified identity, and use your app's existing thread ID or a new UUID as thesession_id. - Swap in the managed checkpointer (LangGraph). LangGraph persists graph state through a checkpointer keyed by a thread ID, so you replace your current checkpointer:
from langchain.agents import create_agent
from databricks_agentkit.langgraph import checkpointer, thread_config
agent = create_agent(model=model, tools=tools, checkpointer=checkpointer(store="support-agent-sessions"))
async def handle_message(user_id: str, conversation_id: str, message: str) -> str:
result = await agent.ainvoke(
{"messages": [{"role": "user", "content": message}]},
config=thread_config(conversation_id, actor=user_id),
)
return result["messages"][-1].content
If you build a StateGraph directly, pass checkpointer() to compile(). For other frameworks, call session.list_items(order_by="create_time asc") to read history and session.append_items([...]) to add each turn.
5. Check ownership. Looking up a session by session_id isn't scoped to an actor, so confirm session.actor_id matches the requesting user before resuming.
6. Grant the deployed agent access. A deployed agent usually runs as a service principal. Grant it access with grant_permission(sp_client_id), or pass permission="READ" for read-only access.
Carrying facts into new conversations. Pair the session store with agent memory (Beta) and a memory pipeline (Beta) that distills conversations into long-term memory. One LangGraph caveat from the tutorial: the checkpointer stores serialized checkpoints that a pipeline can't read, so also append each turn's user and assistant messages to a separate transcript store and point the pipeline there.
FAQs
Does the LangGraph checkpointer keep human-in-the-loop interrupts?
Yes. The managed checkpointer stores full graph state, including human-in-the-loop interrupts, so a paused run can resume after a restart.
Will switching to agent sessions move my existing conversations?
No. Conversations stored elsewhere stay there. To carry one over, append its items to a new session.
Can I undo a turn or branch a conversation?
Yes. The clients can remove the most recent item, clear a session's items, and fork a conversation into an independent copy, optionally up to a specific item.
Does deleting a session delete what the agent remembers?
No. Agent sessions and agent memory are independent, so deleting a session or a whole session store leaves memory entries in place.
Is agent sessions generally available?
No. Agent sessions is in Beta, as are agent memory and memory pipelines.
The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.