---
type: email
from: Kazuhiro Sera <notifications@github.com>
subject: Re: [openai/openai-agents-python] Add SQLAlchemy session backend for

 conversation history management (PR #1357)
received: 2026-03-05 10:13:01
date_header: Wed, 20 Aug 2025 21:53:18 -0700
priority: normal
status: awaiting_approval
uid: 28239
---

## Email Content

**From:** Kazuhiro Sera <notifications@github.com>
**Subject:** Re: [openai/openai-agents-python] Add SQLAlchemy session backend for

 conversation history management (PR #1357)
**Date:** Wed, 20 Aug 2025 21:53:18 -0700

### Body (preview)

@seratch requested changes on this pull request.



Thanks for this PR! Overall, it already looks great, but I have a few minor suggestions. Let me know what you think!



```diff

diff --git a/src/agents/extensions/memory/sqlalchemy_session.py b/src/agents/extensions/memory/sqlalchemy_session.py

index 038f845..20f0555 100644

--- a/src/agents/extensions/memory/sqlalchemy_session.py

+++ b/src/agents/extensions/memory/sqlalchemy_session.py

@@ -31,6 +31,7 @@ from sqlalchemy import (

     TIMESTAMP,

     Column,

     ForeignKey,

+    Index,

     Integer,

     MetaData,

     String,

@@ -122,18 +123,10 @@ class SQLAlchemySession(SessionABC):

                 server_default=sql_text("CURRENT_TIMESTAMP"),

                 nullable=False,

             ),

+            Index(f"idx_{messages_table}_session_time", "session_id", "created_at"),

             sqlite_autoincrement=True,

         )

 

-        # Index for efficient retrieval of messages per session ordered by time

-        from sqlalchemy import Index

-

-        Index(

-            f"idx_{messages_table}_session_time",

-            self._messages.c.session_id,

-            self._messages.c.created_at,

-        )

-

         # Async session factory

         self._session_factory = async_sessionmaker(

             self._engine, expire_on_commit=False

@@ -180,21 +173,28 @@ class SQLAlchemySession(SessionABC):

                 await conn.run_sync(self._metadata.create_all)

             self._create_tables = False  # Only create once

 

+    async def _serialize_message_data(self, item: TResponseInputItem) -> str:

+        return json.dumps(item, separators=(",", ":"))

+

+    async def _deserialize_message_data(self, item: str) -> TResponseInputItem:

+        return json.loads(item)

+

     async def get_items(self, limit: int | None = None) -> list[TResponseInputItem]:

         await self._ensure_tables()

         async with self._session_factory() as sess:

-            if limit is

---

## Suggested Actions
- [ ] Reply
- [ ] Archive
- [ ] Escalate
