-
Notifications
You must be signed in to change notification settings - Fork 583
Comments
fix(integrations): openai/openai-agents: convert input message format#5248
fix(integrations): openai/openai-agents: convert input message format #5248constantinius wants to merge 24 commits intomaster from
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 Preview
This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).
New Features ✨
- feat(anthropic): Set system instruction attribute by alexander-alderman-webb in
#5353 - feat(asyncio): Allow to turn task spans off by sentrivana in
#5367 - feat(gen_ai): add function
set_conversation_idand managing functions on the Scope and apply it on the Span on.finish()by constantinius in#5362 - feat(google-genai): Set system instruction attribute by alexander-alderman-webb in
#5354 - feat(integrations): openai-agents streaming support by constantinius in
#5291 - feat(langchain): Set system instruction attribute by alexander-alderman-webb in
#5357 - feat(openai-agents): Set system instruction attribute by alexander-alderman-webb in
#5355 - feat(pydantic-ai): Set system instruction attribute by alexander-alderman-webb in
#5356
Bug Fixes 🐛
- fix(integrations): openai/openai-agents: convert input message format by constantinius in
#5248
Internal Changes 🔧
- ci(release): Fix changelog-preview permissions by BYK in
#5368 - ci: Fix path in AI integration tests by alexander-alderman-webb in
#5347
🤖 This preview updates automatically when you update the PR.
@sentrivana
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?
constantinius
commented
Jan 14, 2026
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
Done
I assume there is no way to dedupe some of the trimming logic between OpenAI agents and OpenAI because the format is different?
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
constantinius
commented
Jan 15, 2026
I assume there is no way to dedupe some of the trimming logic between OpenAI agents and OpenAI because the format is different?
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.
Add dedicated transform functions for each AI SDK: - transform_openai_content_part() for OpenAI/LiteLLM image_url format - transform_anthropic_content_part() for Anthropic image/document format - transform_google_content_part() for Google GenAI inline_data/file_data - transform_generic_content_part() for LangChain-style generic format Refactor transform_content_part() to be a heuristic dispatcher that detects the format and delegates to the appropriate specific function. This allows integrations to use the specific function directly for better performance and clarity, while maintaining backward compatibility through the dispatcher for frameworks that can receive any format. Added 38 new unit tests for the SDK-specific functions.
Replace generic transform_message_content with the OpenAI-specific transform_openai_content_part function for better performance and clarity since we know OpenAI always uses the image_url format.
### Description Follow up for #5248 that was auto-merged too soon.
Uh oh!
There was an error while loading. Please reload this page.
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