@@ -672,7 +672,6 @@ async def run_agent_streamed_auto_send(
672672 raise ValueError ("Agentex client must be provided for auto_send methods" )
673673
674674 tool_call_map : dict [str , ResponseFunctionToolCall ] = {}
675- tool_call_item_id_to_call_id : dict [str , str ] = {}
676675
677676 trace = self .tracer .trace (trace_id )
678677 redacted_params = redact_mcp_server_params (mcp_server_params )
@@ -765,7 +764,7 @@ async def run_agent_streamed_auto_send(
765764 type = "full" ,
766765 ),
767766 )
768-
767+
769768 elif event .item .type == "tool_call_output_item" :
770769 tool_output_item = event .item .raw_item
771770
@@ -893,79 +892,13 @@ async def run_agent_streamed_auto_send(
893892 elif isinstance (event .data , ResponseOutputItemDoneEvent ):
894893 # Handle item completion
895894 item_id = event .data .item .id
896-
897- # Check if this is a tool call completion
898- if (
899- event .data .item .type == "function_call"
900- and item_id in tool_call_item_id_to_call_id
901- ):
902- call_id = tool_call_item_id_to_call_id [
903- item_id
904- ]
905-
906- # Now that arguments are complete, stream
907- # the tool request
908- if call_id in tool_call_map :
909- # Parse the complete arguments
910- tool_args = {}
911- args_str = tool_call_map [call_id ].arguments
912- if isinstance (args_str , str ) and args_str :
913- try :
914- tool_args = json .loads (args_str )
915- except (
916- json .JSONDecodeError ,
917- ValueError
918- ):
919- # Keep as empty dict if not
920- # valid JSON
921- pass
922-
923- # Create tool request with complete
924- # arguments
925- tool_request_content = ToolRequestContent (
926- author = "agent" ,
927- tool_call_id = call_id ,
928- name = tool_call_map [call_id ].name ,
929- arguments = tool_args ,
930- )
931-
932- # Create and stream the tool request
933- async with (
934- self .streaming_service .
935- streaming_task_message_context (
936- task_id = task_id ,
937- initial_content = (
938- tool_request_content
939- ),
940- ) as streaming_context
941- ):
942- # Tool requests don't count for first stream update timing
943- await streaming_context .stream_update (
944- update = StreamTaskMessageFull (
945- parent_task_message = (
946- streaming_context .
947- task_message
948- ),
949- content = tool_request_content ,
950- type = "full" ,
951- )
952- )
953-
954- # Handle text message completion
955- elif item_id in item_id_to_streaming_context :
895+ if item_id in item_id_to_streaming_context :
956896 streaming_context = (
957897 item_id_to_streaming_context [
958898 item_id
959899 ]
960900 )
961901
962- # Don't close streaming contexts for reasoning
963- # They should just end with their last delta
964- # Only close if it's not reasoning content
965- if not isinstance (streaming_context .task_message .content , ReasoningContent ):
966- await streaming_context .close ()
967- unclosed_item_ids .discard (item_id )
968-
969902 elif isinstance (event .data , ResponseCompletedEvent ):
970903 # All items complete, finish all remaining
971904 # streaming contexts for this session
0 commit comments