1+ import os
2+ import sys
3+ import json
4+
5+ print ("Checking simple HITL agent output..." )
6+
7+ # Check NuGet package
8+ uipath_dir = ".uipath"
9+ if not os .path .exists (uipath_dir ):
10+ print ("NuGet package directory (.uipath) not found" )
11+ sys .exit (1 )
12+
13+ nupkg_files = [f for f in os .listdir (uipath_dir ) if f .endswith ('.nupkg' )]
14+ if not nupkg_files :
15+ print ("NuGet package file (.nupkg) not found in .uipath directory" )
16+ sys .exit (1 )
17+
18+ print (f"NuGet package found: { nupkg_files [0 ]} " )
19+
20+ # Check agent output file
21+ output_file = "__uipath/output.json"
22+ if not os .path .isfile (output_file ):
23+ print ("Agent output file not found" )
24+ sys .exit (1 )
25+
26+ print ("Agent output file found" )
27+
28+ # Check status and required fields
29+ try :
30+ with open (output_file , 'r' , encoding = 'utf-8' ) as f :
31+ output_data = json .load (f )
32+
33+ # Check status
34+ status = output_data .get ("status" )
35+ if status != "successful" :
36+ print (f"Agent execution failed with status: { status } " )
37+ sys .exit (1 )
38+
39+ print ("Agent execution status: successful" )
40+
41+ # Check required fields for simple HITL agent
42+ if "output" not in output_data :
43+ print ("Missing 'output' field in agent response" )
44+ sys .exit (1 )
45+
46+ output_content = output_data ["output" ]
47+
48+ # Check for agent response
49+ if "response" not in output_content :
50+ print ("Missing 'response' field in output" )
51+ sys .exit (1 )
52+
53+ response = output_content ["response" ]
54+
55+ # Check response structure
56+ if "blocks" not in response :
57+ print ("Missing 'blocks' field in response" )
58+ sys .exit (1 )
59+
60+ blocks = response ["blocks" ]
61+ if not blocks or len (blocks ) == 0 :
62+ print ("No response blocks found" )
63+ sys .exit (1 )
64+
65+ # Check for text content
66+ text_block = blocks [0 ]
67+ if "text" not in text_block :
68+ print ("Missing 'text' field in response block" )
69+ sys .exit (1 )
70+
71+ response_text = text_block ["text" ]
72+
73+ # Check for tool calls (function execution)
74+ if "tool_calls" not in output_content :
75+ print ("Missing 'tool_calls' field - function was not called" )
76+ sys .exit (1 )
77+
78+ tool_calls = output_content ["tool_calls" ]
79+ if not tool_calls or len (tool_calls ) == 0 :
80+ print ("No tool calls found - function was not executed" )
81+ sys .exit (1 )
82+
83+ # Validate the specific function call
84+ first_call = tool_calls [0 ]
85+ expected_fields = ["tool_name" , "tool_kwargs" , "tool_id" ]
86+
87+ for field in expected_fields :
88+ if field not in first_call :
89+ print (f"Missing '{ field } ' in tool call" )
90+ sys .exit (1 )
91+
92+ # Check if the correct function was called
93+ if first_call ["tool_name" ] != "may_research_company" :
94+ print (f"Wrong function called: { first_call ['tool_name' ]} , expected 'may_research_company'" )
95+ sys .exit (1 )
96+
97+ # Check function parameters
98+ tool_kwargs = first_call ["tool_kwargs" ]
99+ if "company_name" not in tool_kwargs :
100+ print ("Missing 'company_name' parameter in function call" )
101+ sys .exit (1 )
102+
103+ company_name = tool_kwargs ["company_name" ]
104+
105+ # Check if response indicates successful approval
106+ if "research" not in response_text .lower () or "uipath" not in response_text .lower ():
107+ print ("Response doesn't indicate successful research approval" )
108+ sys .exit (1 )
109+
110+ print ("All HITL-specific validations passed:" )
111+ print (f"Agent response: { response_text } " )
112+ print (f"Function called: { first_call ['tool_name' ]} " )
113+ print (f"Company researched: { company_name } " )
114+ print (f"Tool call ID: { first_call ['tool_id' ]} " )
115+
116+ print ("Simple HITL agent working correctly." )
117+
118+ except Exception as e :
119+ print (f"Error checking output: { e } " )
120+ sys .exit (1 )
0 commit comments