Skip to content

Commit ee70841

Browse files
authored
update tool call output trace format (#44002)
* update tool call output format * updating changelog
1 parent 76e58ee commit ee70841

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

sdk/ai/azure-ai-projects/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Breaking changes
88

99
* `get_openai_client()` method on the asynchronous AIProjectClient is no longer an "async" method.
10+
* tracing: tool call output event content format updated to be in line with other events
1011

1112
### Bugs Fixed
1213

sdk/ai/azure-ai-projects/azure/ai/projects/telemetry/_responses_instrumentor.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ def _add_tool_message_events(
527527
event_body: Dict[str, Any] = {}
528528

529529
if _trace_responses_content and tool_outputs:
530-
tool_call_outputs = []
530+
content_items = []
531531
for output_item in tool_outputs:
532532
try:
533533
tool_output: Dict[str, Any] = {}
@@ -573,14 +573,15 @@ def _add_tool_message_events(
573573
else:
574574
tool_output["output"] = output_value
575575

576-
tool_call_outputs.append(tool_output)
576+
# Use standard content format: {"type": "tool_call_output", "tool_call_output": {...}}
577+
content_items.append({"type": "tool_call_output", "tool_call_output": tool_output})
577578
except Exception: # pylint: disable=broad-exception-caught
578579
# Skip items that can't be processed
579580
logger.debug("Failed to process tool output item: %s", output_item, exc_info=True)
580581
continue
581582

582-
if tool_call_outputs:
583-
event_body["tool_call_outputs"] = tool_call_outputs
583+
if content_items:
584+
event_body["content"] = content_items
584585

585586
attributes = self._create_event_attributes(
586587
conversation_id=conversation_id,
@@ -2925,7 +2926,7 @@ def _add_conversation_item_event( # pylint: disable=too-many-branches,too-many-
29252926

29262927
# Handle different item types
29272928
if item_type == "function_call_output":
2928-
# Function tool output - use tool_call_outputs format
2929+
# Function tool output - use standard content format
29292930
role = "tool" # Override role for tool outputs
29302931
if _trace_responses_content:
29312932
tool_output: Dict[str, Any] = {
@@ -2949,7 +2950,8 @@ def _add_conversation_item_event( # pylint: disable=too-many-branches,too-many-
29492950
else:
29502951
tool_output["output"] = output_value
29512952

2952-
event_body["tool_call_outputs"] = [tool_output]
2953+
# Use standard content format: {"type": "tool_call_output", "tool_call_output": {...}}
2954+
event_body["content"] = [{"type": "tool_call_output", "tool_call_output": tool_output}]
29532955

29542956
event_name = "gen_ai.tool.message"
29552957

sdk/ai/azure-ai-projects/tests/agents/telemetry/test_responses_instrumentor.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ def test_sync_function_tool_with_content_recording_non_streaming(self, **kwargs)
816816
"attributes": {
817817
"gen_ai.provider.name": "azure.openai",
818818
"gen_ai.message.role": "tool",
819-
"gen_ai.event.content": '{"tool_call_outputs": [{"type": "function", "id": "*", "output": {"temperature": "72°F", "condition": "sunny"}}]}',
819+
"gen_ai.event.content": '{"content": [{"type": "tool_call_output", "tool_call_output": {"type": "function", "id": "*", "output": {"temperature": "72°F", "condition": "sunny"}}}]}',
820820
},
821821
},
822822
{
@@ -1012,7 +1012,7 @@ def test_sync_function_tool_with_content_recording_streaming(self, **kwargs):
10121012
"attributes": {
10131013
"gen_ai.provider.name": "azure.openai",
10141014
"gen_ai.message.role": "tool",
1015-
"gen_ai.event.content": '{"tool_call_outputs": [{"type": "function", "id": "*", "output": {"temperature": "72°F", "condition": "sunny"}}]}',
1015+
"gen_ai.event.content": '{"content": [{"type": "tool_call_output", "tool_call_output": {"type": "function", "id": "*", "output": {"temperature": "72°F", "condition": "sunny"}}}]}',
10161016
},
10171017
},
10181018
{
@@ -1519,10 +1519,10 @@ def test_sync_function_tool_list_conversation_items_with_content_recording(self,
15191519
assert "gen_ai.conversation.item.role" in tool_event_attrs
15201520
assert tool_event_attrs["gen_ai.conversation.item.role"] == "tool"
15211521

1522-
# Check that content contains tool_call_outputs
1522+
# Check that content contains tool_call_output
15231523
assert "gen_ai.event.content" in tool_event_attrs
15241524
content = tool_event_attrs["gen_ai.event.content"]
1525-
assert "tool_call_outputs" in content
1525+
assert "tool_call_output" in content
15261526
assert "temperature" in content
15271527
assert "72°F" in content
15281528

@@ -3367,7 +3367,7 @@ def test_responses_stream_method_with_tools_with_content_recording(self, **kwarg
33673367
"attributes": {
33683368
"gen_ai.provider.name": "azure.openai",
33693369
"gen_ai.message.role": "tool",
3370-
"gen_ai.event.content": '{"tool_call_outputs": [{"type": "function", "id": "*", "output": {"temperature": "65°F", "condition": "cloudy"}}]}',
3370+
"gen_ai.event.content": '{"content": [{"type": "tool_call_output", "tool_call_output": {"type": "function", "id": "*", "output": {"temperature": "65°F", "condition": "cloudy"}}}]}',
33713371
},
33723372
},
33733373
{

sdk/ai/azure-ai-projects/tests/agents/telemetry/test_responses_instrumentor_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ async def test_async_function_tool_with_content_recording_streaming(self, **kwar
472472
"attributes": {
473473
"gen_ai.provider.name": "azure.openai",
474474
"gen_ai.message.role": "tool",
475-
"gen_ai.event.content": '{"tool_call_outputs": [{"type": "function", "id": "*", "output": {"temperature": "72°F", "condition": "sunny"}}]}',
475+
"gen_ai.event.content": '{"content": [{"type": "tool_call_output", "tool_call_output": {"type": "function", "id": "*", "output": {"temperature": "72°F", "condition": "sunny"}}}]}',
476476
},
477477
},
478478
{
@@ -2420,7 +2420,7 @@ async def test_async_responses_stream_method_with_tools_with_content_recording(s
24202420
"attributes": {
24212421
"gen_ai.provider.name": "azure.openai",
24222422
"gen_ai.message.role": "tool",
2423-
"gen_ai.event.content": '{"tool_call_outputs": [{"type": "function", "id": "*", "output": {"temperature": "65°F", "condition": "cloudy"}}]}',
2423+
"gen_ai.event.content": '{"content": [{"type": "tool_call_output", "tool_call_output": {"type": "function", "id": "*", "output": {"temperature": "65°F", "condition": "cloudy"}}}]}',
24242424
},
24252425
},
24262426
{

0 commit comments

Comments
 (0)