Sessions store conversation history between runs, so a multi-turn chat works without manual history handling. The SDK offers SQLiteSession and other session types: the session holds the messages, and each run with the same session continues from them.
Before you start
You need a working OpenAI Agents SDK agent. Decide the session scope first: one session per user or per conversation is the standard pattern, and a shared session mixes two users together.
Create a session and pass it to the run
Create a session, for example a SQLiteSession with a session ID, and pass it when you run the agent. The runner stores the conversation history in the session after each run, so the next run with the same session sees it.
Test with a follow-up that needs the first run
Run the agent with a first message that names a detail, then run it again with the same session and a follow-up that only makes sense if the detail is remembered. Then run it with a new session and check it starts fresh.
Worked example: Two sessions for a fictional bookshop agent
Maple Books is a fictional bookshop. Its agent uses one session per customer. The table shows two sessions.
| Session | Messages | Agent remembers? |
|---|---|---|
| session-ana | Wants a bicycle repair book under 30 dollars | Yes, within this session |
| session-ben | Asks about cookbooks | Yes, but only the cookbook topic |
Expected result (UNTESTED): the follow-up in session-ana is answered without repeating the topic or the budget, while session-ben starts fresh. We checked the OpenAI Agents SDK guides, which describe sessions and SQLiteSession, but we did not run the agent on this machine.
Limits
A session holds the full history, so a long conversation grows the context on every run. For long chats, trim or summarise the history before the session gets too large. Keep session IDs private: a session ID is access to that conversation.
