Skip to content

Commit 51bf1f0

Browse files
authored
Fix telemetry issues. (Azure#42698)
* Fix telemetry issues. * Fix * Add support for OpenAPI step * Fix OpenAPI tool logging * Fix comment * Fix
1 parent 52bf8db commit 51bf1f0

File tree

5 files changed

+586
-757
lines changed

5 files changed

+586
-757
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
### Bugs Fixed
1212

13+
* Fix the issue with logging Agent message, when the message has "in progress" status (related to [issue](https://github.com/Azure/azure-sdk-for-python/issues/42645)).
14+
* Fix the issue with `RunStepOpenAPIToolCall` logging [issue](https://github.com/Azure/azure-sdk-for-python/issues/42645).
15+
1316
### Sample updates
1417

1518
## 1.2.0b3 (2025-08-22)

sdk/ai/azure-ai-agents/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/ai/azure-ai-agents",
5-
"Tag": "python/ai/azure-ai-agents_cf22042479"
5+
"Tag": "python/ai/azure-ai-agents_ac2e010ef5"
66
}

sdk/ai/azure-ai-agents/azure/ai/agents/telemetry/_ai_agents_instrumentor.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
from azure.ai.agents.models._enums import (
1919
AgentsResponseFormatMode,
2020
MessageRole,
21+
MessageStatus,
2122
RunStepStatus,
23+
RunStepType,
2224
)
2325
from azure.ai.agents.models import (
2426
MessageAttachment,
@@ -28,6 +30,7 @@
2830
RunStepDeltaChunk,
2931
RunStepError,
3032
RunStepFunctionToolCall,
33+
RunStepOpenAPIToolCall,
3134
RunStepToolCallDetails,
3235
RunStepCodeInterpreterToolCall,
3336
RunStepBingGroundingToolCall,
@@ -439,6 +442,12 @@ def _process_tool_calls(self, step: RunStep) -> List[Dict[str, Any]]:
439442
"type": t.type,
440443
t.type: t.bing_grounding,
441444
}
445+
elif isinstance(t, RunStepOpenAPIToolCall):
446+
tool_call = {
447+
"id": t.id,
448+
"type": t.type,
449+
'function': t.as_dict().get('function', {})
450+
}
442451
else:
443452
tool_details = t.as_dict()[t.type]
444453

@@ -2057,7 +2066,8 @@ def on_thread_message(self, message: "ThreadMessage") -> None: # type: ignore[f
20572066
else:
20582067
retval = super().on_thread_message(message) # pylint: disable=assignment-from-none # type: ignore
20592068

2060-
if message.status in {"completed", "incomplete"}:
2069+
# Message status may be in progress, even if the thread.message.completed event has arrived.
2070+
if message.status in {MessageStatus.COMPLETED, MessageStatus.INCOMPLETE} or (message.status == MessageStatus.IN_PROGRESS and message.content):
20612071
self.last_message = message
20622072

20632073
return retval # type: ignore
@@ -2081,14 +2091,14 @@ def on_run_step(self, step: "RunStep") -> None: # type: ignore[func-returns-val
20812091
retval = super().on_run_step(step) # pylint: disable=assignment-from-none # type: ignore
20822092

20832093
if (
2084-
step.type == "tool_calls"
2094+
step.type == RunStepType.TOOL_CALLS
20852095
and isinstance(step.step_details, RunStepToolCallDetails)
20862096
and step.status == RunStepStatus.COMPLETED
20872097
):
20882098
self.instrumentor._add_tool_assistant_message_event( # pylint: disable=protected-access # pyright: ignore [reportFunctionMemberAccess]
20892099
self.span, step
20902100
)
2091-
elif step.type == "message_creation" and step.status == RunStepStatus.COMPLETED:
2101+
elif step.type == RunStepType.MESSAGE_CREATION and step.status == RunStepStatus.COMPLETED:
20922102
self.instrumentor.add_thread_message_event(self.span, cast(ThreadMessage, self.last_message), step.usage)
20932103
if (
20942104
self.span
@@ -2194,7 +2204,8 @@ async def on_thread_message(self, message: "ThreadMessage") -> None: # type: ig
21942204
else:
21952205
retval = await super().on_thread_message(message) # type: ignore
21962206

2197-
if message.status in {"completed", "incomplete"}:
2207+
# Message status may be in progress, even if the thread.message.completed event has arrived.
2208+
if message.status in {MessageStatus.COMPLETED, MessageStatus.INCOMPLETE} or (message.status == MessageStatus.IN_PROGRESS and message.content):
21982209
self.last_message = message
21992210

22002211
return retval # type: ignore
@@ -2218,14 +2229,14 @@ async def on_run_step(self, step: "RunStep") -> None: # type: ignore[func-retur
22182229
retval = await super().on_run_step(step) # type: ignore
22192230

22202231
if (
2221-
step.type == "tool_calls"
2232+
step.type == RunStepType.TOOL_CALLS
22222233
and isinstance(step.step_details, RunStepToolCallDetails)
22232234
and step.status == RunStepStatus.COMPLETED
22242235
):
22252236
self.instrumentor._add_tool_assistant_message_event( # pylint: disable=protected-access # pyright: ignore [reportFunctionMemberAccess]
22262237
self.span, step
22272238
)
2228-
elif step.type == "message_creation" and step.status == RunStepStatus.COMPLETED:
2239+
elif step.type == RunStepType.MESSAGE_CREATION and step.status == RunStepStatus.COMPLETED:
22292240
self.instrumentor.add_thread_message_event(self.span, cast(ThreadMessage, self.last_message), step.usage)
22302241
if (
22312242
self.span

0 commit comments

Comments
 (0)