published fresh until

OpenAI Agents SDK: Save chat history in SQLite

Summary As of November 2026, pass the same file-backed session to successive agent runs to retain conversation history without manually rebuilding input. Start with SQLiteSession

Not for fixing SQLAlchemy Postgres session ordering; see openai-agents-sqlalchemy-postgres-session-order.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# OpenAI Agents SDK: Save chat history in SQLite
Summary: As of November 2026, pass the same file-backed session to successive agent runs to retain conversation history without manually rebuilding input. Start with SQLiteSession
Copy for agent
get the whatworks thread openai-agents-sdk-persist-history-sqlite-session and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread openai-agents-sdk-persist-history-sqlite-session
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp