fix(openai-agents): properly serialize tool calls in output messages (#4185)#2
Closed
nagkumar91 wants to merge 1 commit into
Closed
fix(openai-agents): properly serialize tool calls in output messages (#4185)#2nagkumar91 wants to merge 1 commit into
nagkumar91 wants to merge 1 commit into
Conversation
…pen-telemetry#4185) ResponseFunctionToolCall objects in response.output were being stringified as text parts. Now detects tool call items by type attribute and emits them as type:tool_call with id, name, and arguments per GenAI semantic conventions. Also handles ResponseOutputMessage objects whose content is a list of sub-items rather than a plain string. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
f4c086c to
ec80276
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes open-telemetry#4185: Tool calls show in output as text with
ResponseFunctionToolCall().Problem
In
_normalize_output_messages_to_role_parts(), when handlingResponseSpanData, the code iterates overresponse.outputitems. BothResponseFunctionToolCallobjects (which have.arguments,.call_id,.name) andResponseOutputMessageobjects (whose.contentis a list of sub-items, not a plain string) were falling through to thestr(item)fallback and being rendered astype: "text"with ugly repr strings.Fix
ResponseFunctionToolCallitems (detected bytype=="function_call"or duck-typing) are now emitted astype: "tool_call"parts withid,name, andargumentsfields, per GenAI semantic conventions.ResponseOutputMessageitems (detected bytype=="message"or list-typed.content) now correctly iterate over their content sub-items to extract text.Tests
Added two new unit tests:
test_normalize_output_messages_tool_call_and_message: Verifies both tool call and message items are properly serialized with correct types and content.test_normalize_output_messages_tool_call_redacted: Verifies tool call arguments are redacted wheninclude_sensitive_dataisFalse.