1818from azure .ai .agents .models ._enums import (
1919 AgentsResponseFormatMode ,
2020 MessageRole ,
21+ MessageStatus ,
2122 RunStepStatus ,
23+ RunStepType ,
2224)
2325from azure .ai .agents .models import (
2426 MessageAttachment ,
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