OpenAI Agents SDK Memory: Sessions and Cross-Session Context
Use native session storage for conversation history and an explicit memory service for selected context shared across conversations.

The OpenAI Agents SDK supports session storage for conversation history. A memory service can complement that history by retrieving selected facts across conversations. Choose between them by the information you need to preserve: a transcript, a preference, a document, or the state of a completed business action.
The OpenAI API client and the Agents SDK are separate packages. This guide concerns the Python Agents SDK, installed as openai-agents and imported as agents. It does not rely on an alleged universal Memory() primitive.
Prove native session persistence first
The Agents SDK session guide documents persistent backends, including SQLite. A file-backed session can retain items independently of a running agent process. This example exercises session storage directly and makes no model call.
import asyncio
from agents import SQLiteSession
async def check_sessions(path):
first = SQLiteSession("demo-user:thread-a", path)
await first.clear_session()
await first.add_items([
{"role": "user", "content": "My demo project is called Cedar."}
])
reopened = SQLiteSession("demo-user:thread-a", path)
items = await reopened.get_items()
assert items[0]["content"] == "My demo project is called Cedar."
other = SQLiteSession("demo-user:thread-b", path)
assert await other.get_items() == []
await reopened.clear_session()
if __name__ == "__main__":
import tempfile
from pathlib import Path
with tempfile.TemporaryDirectory() as directory:
asyncio.run(check_sessions(str(Path(directory) / "sessions.db")))
The second thread starts empty because session history is scoped by the session ID. Use IDs created from server-authorized identity and conversation records. An unpredictable session ID is not a substitute for checking that the caller owns the session.
When session history is enough
If users continue the same conversation and the transcript remains manageable, native session storage may meet the requirement. Configure the agent run to use that session and test your deployment's restart behavior. Do not add another memory system merely because the model API does not independently remember each earlier request.
Long histories still require a context policy. Compaction reduces what is sent to the model; it does not establish that every earlier constraint remains recoverable. Test exact names, corrections, decisions, and unresolved actions after compaction.
When to retrieve shared user context
A preference that should apply across several sessions belongs to a broader authorized user scope. The Supermemory Agents SDK guide describes retrieving profiles and related memories before a run. Keep the application sequence explicit:
- Resolve the user's tenant and identity on the server.
- Retrieve relevant background using that scope.
- Put the bounded background into the request as untrusted contextual data.
- Run the agent with its conversation session.
- Save only permitted new facts or source material, keeping their provenance.
Do not save every assistant answer as a confirmed fact. An agent can speculate, quote another person, or suggest an option that the user rejects. Your persistence policy must distinguish these cases.
Avoid double-counting the conversation
If both the session and the memory service return the same recent messages, context can grow without adding evidence. Use sessions for conversation continuity and define what the external retrieval stage contributes: older preferences, facts from other conversations, or relevant documents. Keep a budget for each source.
Similarly, deleting a session and deleting user memory are different operations. A user-facing deletion flow should name its scope and execute the relevant storage operations. The lifecycle guide provides a useful acceptance checklist.
Test the combined path
The local session example checks file persistence and conversation separation. A live integration test should additionally save one fictional preference, wait for readiness, open a different session for the same user, and verify that retrieval supplies the preference. A different user must not receive it. Repeat after correction and deletion.
Record retrieval evidence separately from the agent's final answer. If the correct fact was retrieved but ignored, investigate request assembly and generation. If it was never retrieved, investigate ingestion, scope, and search. Neither outcome supports a general accuracy or latency claim without a defined evaluation.
Local API check: Python 3.12 and openai-agents 0.22.3. The test exercises SQLite session storage without a model request.
Try cross-session context alongside native session history: get your Supermemory API key and wire retrieval into one agent. Use two sessions for a fictional user to check the preference, correction, and deletion sequence above.