-
Notifications
You must be signed in to change notification settings - Fork 572
fix(integrations): openai/openai-agents: convert input message format #5248
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
base: master
Are you sure you want to change the base?
fix(integrations): openai/openai-agents: convert input message format #5248
Conversation
…he schema we expect for the `gen_ai.request.messages`
…ntent and update message handling
…nAI message handling
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Documentation 📚
Internal Changes 🔧Release
Other
🤖 This preview updates automatically when you update the PR. |
sentrivana
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ok to me, two things:
- Can we add a check to the tests that we're not modifying the user's messages? Either as a new test or just adding an assert to the tests added in this PR
- I assume there is no way to dedupe some of the trimming logic between OpenAI agents and OpenAI because the format is different?
Done
Looking into that. Cursor says no. But I'm not sure tbh |
… of full message dicts - Extract choice.message.content for gen_ai.response.text instead of model_dump() - Add separate gen_ai.response.tool_calls extraction for Chat Completions API - Handle audio transcripts in responses - Extract shared extract_response_output() to ai/utils.py for Responses API output - Refactor OpenAI and OpenAI Agents integrations to use shared utility
I did investigate that. I did eliminate code duplication for output messages, but input messages are actually different |
…AI messages Add transform_content_part() and transform_message_content() functions to standardize content part handling across all AI integrations. These functions transform various SDK-specific formats (OpenAI, Anthropic, Google, LangChain) into a unified format: - blob: base64-encoded binary data - uri: URL references (including file URIs) - file: file ID references Also adds get_modality_from_mime_type() helper to infer content modality (image/audio/video/document) from MIME types.
Replace local _convert_message_parts function with the shared transform_message_content function to deduplicate code across AI integrations.
| elif not isinstance(transformed, list): | ||
| transformed = [ | ||
| {"text": str(transformed), "type": "text"} | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None content converts to literal string "None"
Medium Severity
When processing message objects in invoke_agent_span, if a message has no content key or content is None, the code converts it to the literal string "None". This happens because msg.get("content") returns None, _transform_openai_agents_message_content(None) returns None, and then str(None) produces "None". A message with missing content would incorrectly display as having content "None" rather than being handled as empty or skipped.
Description
Convert messages to common
gen_ai.request.messagesstructureIssues
Closes https://linear.app/getsentry/issue/TET-1633/redact-images-openai-openai-agents
Closes https://linear.app/getsentry/issue/TET-1639/openai-output-not-rendered-nicely