Skip to content

Add SQLAlchemy session backend for conversation history management #1357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

habema
Copy link
Contributor

@habema habema commented Aug 3, 2025

This PR introduces SQLAlchemySession, providing a production-grade session storage backend that can connect to any database supported by SQLAlchemy (e.g., PostgreSQL, MySQL).

This implementation is based on the discussion in Issue #1328 and follows the agreed-upon architectural pattern:

  • The new session store is located in src/agents/extensions/memory/.
  • SQLAlchemy is added as an optional dependency, available via the [sqlalchemy] extra.
  • This is a non-breaking, purely additive change.

A test has been added.

Resolves #1328.

@habema
Copy link
Contributor Author

habema commented Aug 3, 2025

@seratch

The new SQLAlchemySession feature introduces an optional dependency on sqlalchemy. This creates a conflict between two goals:

  1. Keeping sqlalchemy as an optional dependency that users don't need to install if they are not using SQLAlchemySession.
  2. Ensuring the SQLAlchemySession feature is tested in all our CI environments, including old_version_tests.

The old_version_tests CI job does not install optional extras by default. As a result, directly importing SQLAlchemySession in the top-level agents package causes an ImportError and breaks that CI job.

Temporary Solution

As a temporary measure to allow the feature to be merged without breaking the build, the following changes have been made:

  1. No Top-Level Import: SQLAlchemySession is no longer imported in the root __init__.py of the agents package. Code that uses it must now import it directly from agents.extensions.memory.sqlalchemy_session.
  2. Conditional Tests: The tests for SQLAlchemySession are now skipped in environments where sqlalchemy is not installed, using pytest.importorskip("sqlalchemy").

Next Steps

This solution is a trade-off. It prevents the CI from breaking, but it means that the SQLAlchemySession feature is not currently tested in the old_version_tests environment.

I think the correct long-term fix is to update make old_version_tests to install the [sqlalchemy] extra (and any other extra dependencies needed) for all test jobs. This will allow the tests to run everywhere and provide full test coverage for the new feature.

Let me know what you think.

@seratch seratch added feature:sessions enhancement New feature or request labels Aug 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature:sessions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SQLAlchemy Session Store for Production Databases
2 participants