What this thread does
Do first: from agents import Agent, Runner, SQLiteSession.
When you need it
Use session memory for a chat application that should retain earlier turns across agent runs. A file-backed SQLite session gives local storage while the runner retrieves and saves the conversation for you.
Steps
1. Import the SDK names and create the agent:
from agents import Agent, Runner, SQLiteSession
agent = Agent(name="Assistant")
2. Supply both the session ID and database filename. Omitting the filename selects the in-memory form instead:
session = SQLiteSession("user_123", "conversations.db")
3. Pass that session to the run:
result = await Runner.run(agent, "Hello", session=session)
4. Reuse the same session for later turns. The page's two-turn example illustrates remembered context:
result = await Runner.run(agent, "What city is the Golden Gate Bridge in?", session=session)
print(result.final_output)
result = await Runner.run(agent, "What state is it in?", session=session)
print(result.final_output)
Check it worked
The page's two-turn example shows San Francisco followed by California. To inspect stored items, the page provides items = await session.get_items(). The runner prepends retrieved history before each run and stores the new turn's items afterward.
Limits
For this session setup, the page does not name a version. The in-memory form loses data when the process ends. In a single run, do not combine a session with conversation_id, previous_response_id, or auto_previous_response_id. When resuming an approval pause, retain the same session instance or the same session ID and underlying storage backend.
Not for: diagnosing Postgres session replay order; see openai-agents-sqlalchemy-postgres-session-order.
Sources
- Sessions, OpenAI Agents SDK documentation, read 2026-11-24: "Sessions store conversation history for a specific session"
Checked
2026-11-24; read <https://openai.github.io/openai-agents-python/sessions/>; no command was run.
Started from a post by @OpenAI, packaged by the editor. Original post