Add session metadata support to SQLAlchemySession#1939
Add session metadata support to SQLAlchemySession#1939Jash271 wants to merge 3 commits intoopenai:mainfrom
Conversation
Adds the ability to store and query metadata for sessions using a new agent_sessions_metadata table. This allows applications to associate metadata like owner_id, title, or tags with sessions. New methods: - set_metadata() - store metadata key-value pairs - get_metadata() - retrieve metadata for a session - delete_metadata() - remove metadata - find_sessions_by_metadata() - find sessions by metadata values Also updates clear_session() to clean up metadata when clearing a session. Fixes openai#1938
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| # Use dialect-specific UPSERT | ||
| stmt = stmt.on_conflict_do_update( | ||
| index_elements=["session_id", "key"], | ||
| set_={ | ||
| "value": stmt.excluded.value, | ||
| "updated_at": sql_text("CURRENT_TIMESTAMP"), | ||
| }, |
There was a problem hiding this comment.
Use MySQL-compatible UPSERT in set_metadata
The new metadata UPSERT unconditionally calls insert(...).on_conflict_do_update(...) after importing the MySQL dialect’s insert. The MySQL insert construct doesn’t implement on_conflict_do_update; it only exposes on_duplicate_key_update. As a result, set_metadata() raises AttributeError for any MySQL-backed session and metadata cannot be written. Consider branching to on_duplicate_key_update for MySQL instead of calling the PostgreSQL/SQLite API.
Useful? React with 👍 / 👎.
|
Thanks for sending this code change. It may work but we still hesitate having this change as it could be a specific change for your use case (see #1938 (comment) for more details on what I think). So, for now, please inherit the built-in class and add these functionalities on your own sub class. |
MySQL uses on_duplicate_key_update() instead of on_conflict_do_update(). This fixes AttributeError when using set_metadata() with MySQL databases.
|
This PR is stale because it has been open for 10 days with no activity. |
|
This PR was closed because it has been inactive for 7 days since being marked as stale. |
Adds the ability to store and query metadata for sessions using a new agent_sessions_metadata table. This allows applications to associate metadata like owner_id, title, or tags with sessions.
New methods:
Also updates clear_session() to clean up metadata when clearing a session.
Feat: #1938