Skip to content

Conversation

@Jash271
Copy link

@Jash271 Jash271 commented Oct 20, 2025

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.

Feat: #1938

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
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines 451 to 457
# 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"),
},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@seratch
Copy link
Member

seratch commented Oct 20, 2025

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.

@seratch seratch marked this pull request as draft October 20, 2025 02:15
Jash Shah and others added 2 commits October 19, 2025 22:19
MySQL uses on_duplicate_key_update() instead of on_conflict_do_update().
This fixes AttributeError when using set_metadata() with MySQL databases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants