The session guide lists MySQL as a supported database, and the API reference includes mysql+aiomysql:// and documents create_tables=True for development/testing. However, automatic table creation fails against a fresh MySQL database.
Reproduction
Reproduced with MySQL Community Server 8.0.46, Python 3.12.3 on Linux, openai-agents 0.22.0, SQLAlchemy 2.0.52, and aiomysql 0.3.2. The same failure occurs on main at 89c02c828ee8510fe9a84ee6675608193aa13b02.
Install the dependencies, then set MYSQL_URL to a mysql+aiomysql:// connection URL for an empty test database with permission to create tables. No model call or OpenAI API key is needed.
pip install 'openai-agents[sqlalchemy]==0.22.0' 'SQLAlchemy==2.0.52' 'aiomysql==0.3.2' cryptography
import asyncio
import os
from sqlalchemy import text
from sqlalchemy.ext.asyncio import create_async_engine
from agents.extensions.memory import SQLAlchemySession
async def main():
engine = create_async_engine(os.environ["MYSQL_URL"])
try:
async with engine.connect() as conn:
print("MySQL:", await conn.scalar(text("SELECT VERSION()")))
session = SQLAlchemySession(
"mysql-create-tables",
engine=engine,
create_tables=True,
)
await session.add_items([{"role": "user", "content": "hello"}])
finally:
await engine.dispose()
asyncio.run(main())
Actual result
The connection succeeds and reports MySQL 8.0.46. On the first add_items() call, automatic schema initialization fails with:
sqlalchemy.exc.CompileError: (in table 'agent_sessions', column 'session_id'): VARCHAR requires a length on dialect mysql
This happens while SQLAlchemy compiles the first CREATE TABLE, before any CREATE statement reaches MySQL. No tables are created.
Both session_id columns in the current implementation use String without a length.
Expected behavior / scope clarification
Is SQLAlchemySession(create_tables=True) intended to support MySQL?
If so, I would expect the example above to create the required tables and store the message, and I'd be happy to submit a focused fix with MySQL regression coverage.
If automatic schema creation is intentionally unsupported on MySQL, I can instead submit a documentation clarification.
One possible implementation direction is a MySQL-specific bounded VARCHAR via with_variant(), which would preserve the existing PostgreSQL/SQLite types. I have not chosen a length here because doing so would introduce a MySQL-specific maximum session ID length that should be agreed first.
This report is limited to automatic table creation on a fresh database; it does not assess create_tables=False with a manually provisioned schema.
The session guide lists MySQL as a supported database, and the API reference includes
mysql+aiomysql://and documentscreate_tables=Truefor development/testing. However, automatic table creation fails against a fresh MySQL database.Reproduction
Reproduced with MySQL Community Server 8.0.46, Python 3.12.3 on Linux,
openai-agents0.22.0, SQLAlchemy 2.0.52, and aiomysql 0.3.2. The same failure occurs on main at89c02c828ee8510fe9a84ee6675608193aa13b02.Install the dependencies, then set
MYSQL_URLto amysql+aiomysql://connection URL for an empty test database with permission to create tables. No model call or OpenAI API key is needed.Actual result
The connection succeeds and reports MySQL
8.0.46. On the firstadd_items()call, automatic schema initialization fails with:This happens while SQLAlchemy compiles the first
CREATE TABLE, before anyCREATEstatement reaches MySQL. No tables are created.Both
session_idcolumns in the current implementation useStringwithout a length.Expected behavior / scope clarification
Is
SQLAlchemySession(create_tables=True)intended to support MySQL?If so, I would expect the example above to create the required tables and store the message, and I'd be happy to submit a focused fix with MySQL regression coverage.
If automatic schema creation is intentionally unsupported on MySQL, I can instead submit a documentation clarification.
One possible implementation direction is a MySQL-specific bounded
VARCHARviawith_variant(), which would preserve the existing PostgreSQL/SQLite types. I have not chosen a length here because doing so would introduce a MySQL-specific maximum session ID length that should be agreed first.This report is limited to automatic table creation on a fresh database; it does not assess
create_tables=Falsewith a manually provisioned schema.