Back to catalog / Agent state
Continue an agent conversation across requests with a persistent session
Associate a persistent session with the same user or task so later runs can use relevant history without mixing users.
Goal
Continue the correct conversation state across calls while isolating users’ records.
Steps
- Define session ID creation, ownership, expiration, and deletion rules. [openai-sessions] [openai-context]
- Create a stable conversation ID with
session=SQLiteSession("conversation_123", "conversations.db"); authorize session IDs when storage is shared. [openai-sessions] [openai-context] - Call
await Runner.run(agent, user_input, session=session)each turn; useRunConfig(session_settings=SessionSettings(limit=...))to bound history. [openai-sessions] [openai-context] - Delete expired sessions under a retention policy and minimize stored conversation data. [openai-sessions] [openai-context]
- Run a multi-turn test for two isolated users and confirm each sees only its own history. [openai-sessions] [openai-context]
How to verify
Multi-turn tests should preserve each user’s context and reject cross-user session access.
Troubleshooting
If history is missing or mixed, verify session-ID ownership and backend persistence before changing prompts.
Permissions
Prerequisites
- Python 3.10+, openai-agents compatible with the pinned revision, and authorized model-provider credentials (except local mock tests)
Permissions
- Use a local or isolated test environment; use least privilege and approval for external data or side effects
Limitations
`SQLiteSession` suits local persistence; multi-process deployments need a shared session backend. A Session cannot be combined with server-managed `conversation_id` or `previous_response_id`.
Pinned upstream source
- Repository
- openai/openai-agents-python
- File path
- docs/ref/memory/session.md
- Pinned commit
f53c62451c7f34c15f0c87fa745e05404025420f- Source checked
- 2026-10-14 · Reviewed against the pinned upstream source
Repository metrics
These values describe the upstream repository, not popularity or likes for an individual skill or playbook.
- Stars
- Not collected
- Forks
- Not collected
- Observed at
- Not collected
No metrics snapshot is available yet.
License: MIT
Main topic
Turn ecommerce campaign materials into a reviewable weekly brief