opentelemetry-instrumentation-genai-openai-agents: serialize tool calls as structured parts#101
Open
Jwrede wants to merge 2 commits into
Open
Conversation
ResponseFunctionToolCall objects in response.output were being stringified as text parts instead of serialized as structured tool_call parts with id, name, and arguments fields. This adds duck-type detection for tool call items and proper serialization following the GenAI semantic conventions. Assisted-by: Claude Opus 4.6
Assisted-by: Claude Opus 4.6
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR improves GenAI output message normalization by recognizing OpenAI Agents “function tool call” output items and emitting them as structured tool_call parts (instead of stringifying them), with accompanying tests and changelog entry.
Changes:
- Add tool-call detection + serialization for
response.outputitems into{type: "tool_call", id, name, arguments}parts. - Infer
finish_reason = "tool_calls"for response outputs containing tool-call items. - Add tests covering tool-call-only output, mixed text+tool-call output, and redaction behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| instrumentation/opentelemetry-instrumentation-genai-openai-agents/src/opentelemetry/instrumentation/genai/openai_agents/span_processor.py | Adds tool-call item detection/serialization and updates output-message normalization/finish-reason inference. |
| instrumentation/opentelemetry-instrumentation-genai-openai-agents/tests/test_tracer.py | Adds regression tests ensuring tool calls are serialized as structured parts and redacted correctly. |
| instrumentation/opentelemetry-instrumentation-genai-openai-agents/.changelog/0.fixed | Documents the behavioral fix in the changelog. |
| "type": "tool_call", | ||
| "id": getattr(item, "call_id", None), | ||
| "name": getattr(item, "name", None), | ||
| "arguments": "readacted", |
| return { | ||
| "type": "text", | ||
| "content": ( | ||
| "readacted" if not self.include_sensitive_data else txt |
| return { | ||
| "type": "text", | ||
| "content": ( | ||
| "readacted" if not self.include_sensitive_data else str(item) |
| self.id = "fc_redact" | ||
| self.status = "completed" | ||
|
|
||
| part = processor._output_item_to_part(_ToolCall()) |
Comment on lines
+970
to
+974
| if not finish_reason: | ||
| if self._is_tool_call_item(item): | ||
| status = getattr(item, "status", None) | ||
| if status in {"completed", "incomplete"}: | ||
| finish_reason = "tool_calls" |
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.
Description
Fix ResponseFunctionToolCall objects in response.output being stringified via str(), producing raw Python repr in gen_ai.output.messages. They are now serialized as structured tool_call parts with id, name, and arguments following the gen_ai semantic conventions.
Originally submitted as open-telemetry/opentelemetry-python-contrib#4630, closed per maintainer direction to resubmit here.
Fixes open-telemetry/opentelemetry-python-contrib#4185
Type of change
How has this been tested?
All 17 tests pass.
Checklist
Assisted-by: Claude Opus 4.6