Skip to content

opentelemetry-instrumentation-genai-openai-agents: serialize tool calls as structured parts#101

Open
Jwrede wants to merge 2 commits into
open-telemetry:mainfrom
Jwrede:fix/tool-call-output-serialization
Open

opentelemetry-instrumentation-genai-openai-agents: serialize tool calls as structured parts#101
Jwrede wants to merge 2 commits into
open-telemetry:mainfrom
Jwrede:fix/tool-call-output-serialization

Conversation

@Jwrede

@Jwrede Jwrede commented May 30, 2026

Copy link
Copy Markdown
Contributor

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

  • Bug fix (non-breaking change which fixes an issue)

How has this been tested?

  • tool-call-only output test
  • mixed text + tool_call output test
  • redaction test when sensitive data is disabled

All 17 tests pass.

Checklist

  • Followed the style guidelines of this project
  • Changelog updated if the change requires an entry
  • Unit tests added
  • Documentation updated

Assisted-by: Claude Opus 4.6

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
Copilot AI review requested due to automatic review settings May 30, 2026 12:44
@Jwrede Jwrede requested a review from a team as a code owner May 30, 2026 12:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.output items 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"
@github-actions

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment.
If you're still working on this, please add a comment or push new commits.

@github-actions github-actions Bot added the Stale Issue or PR has been inactive label Jun 14, 2026

@lmolkova lmolkova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the contribution! Could you please check if this is already covered with this PR - #90? would appreciate your review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Stale Issue or PR has been inactive

Development

Successfully merging this pull request may close these issues.

[OpenAI Agents] Tool calls show in output as text with ResponseFunctionToolCall()

3 participants