@@ -60,60 +60,79 @@ async def run_browser_agent(
60
60
tool_call_in_content ,
61
61
browser_context = None
62
62
):
63
- """Run the browser agent with proper browser context initialization"""
64
- browser = None
65
- try :
66
- # Run the agent
67
- llm = utils .get_llm_model (
68
- provider = llm_provider ,
69
- model_name = llm_model_name ,
70
- temperature = llm_temperature ,
71
- base_url = llm_base_url ,
72
- api_key = llm_api_key ,
63
+ # Disable recording if the checkbox is unchecked
64
+ if not enable_recording :
65
+ save_recording_path = None
66
+
67
+ # Ensure the recording directory exists if recording is enabled
68
+ if save_recording_path :
69
+ os .makedirs (save_recording_path , exist_ok = True )
70
+
71
+ # Get the list of existing videos before the agent runs
72
+ existing_videos = set ()
73
+ if save_recording_path :
74
+ existing_videos = set (
75
+ glob .glob (os .path .join (save_recording_path , "*.[mM][pP]4" ))
76
+ + glob .glob (os .path .join (save_recording_path , "*.[wW][eE][bB][mM]" ))
73
77
)
74
78
75
- if agent_type == "org" :
76
- result = await run_org_agent (
77
- llm = llm ,
78
- headless = headless ,
79
- disable_security = disable_security ,
80
- window_w = window_w ,
81
- window_h = window_h ,
82
- save_recording_path = save_recording_path ,
83
- save_trace_path = save_trace_path ,
84
- task = task ,
85
- max_steps = max_steps ,
86
- use_vision = use_vision ,
87
- max_actions_per_step = max_actions_per_step ,
88
- tool_call_in_content = tool_call_in_content ,
89
- browser_context = browser_context ,
90
- )
91
- elif agent_type == "custom" :
92
- result = await run_custom_agent (
93
- llm = llm ,
94
- use_own_browser = use_own_browser ,
95
- headless = headless ,
96
- disable_security = disable_security ,
97
- window_w = window_w ,
98
- window_h = window_h ,
99
- save_recording_path = save_recording_path ,
100
- save_trace_path = save_trace_path ,
101
- task = task ,
102
- add_infos = add_infos ,
103
- max_steps = max_steps ,
104
- use_vision = use_vision ,
105
- max_actions_per_step = max_actions_per_step ,
106
- tool_call_in_content = tool_call_in_content ,
107
- browser_context = browser_context ,
108
- )
109
- else :
110
- raise ValueError (f"Invalid agent type: { agent_type } " )
111
-
112
- return result
79
+ # Run the agent
80
+ llm = utils .get_llm_model (
81
+ provider = llm_provider ,
82
+ model_name = llm_model_name ,
83
+ temperature = llm_temperature ,
84
+ base_url = llm_base_url ,
85
+ api_key = llm_api_key ,
86
+ )
87
+
88
+ if agent_type == "org" :
89
+ final_result , errors , model_actions , model_thoughts = await run_org_agent (
90
+ llm = llm ,
91
+ headless = headless ,
92
+ disable_security = disable_security ,
93
+ window_w = window_w ,
94
+ window_h = window_h ,
95
+ save_recording_path = save_recording_path ,
96
+ save_trace_path = save_trace_path ,
97
+ task = task ,
98
+ max_steps = max_steps ,
99
+ use_vision = use_vision ,
100
+ max_actions_per_step = max_actions_per_step ,
101
+ tool_call_in_content = tool_call_in_content ,
102
+ browser_context = browser_context ,
103
+ )
104
+ elif agent_type == "custom" :
105
+ final_result , errors , model_actions , model_thoughts = await run_custom_agent (
106
+ llm = llm ,
107
+ use_own_browser = use_own_browser ,
108
+ headless = headless ,
109
+ disable_security = disable_security ,
110
+ window_w = window_w ,
111
+ window_h = window_h ,
112
+ save_recording_path = save_recording_path ,
113
+ save_trace_path = save_trace_path ,
114
+ task = task ,
115
+ add_infos = add_infos ,
116
+ max_steps = max_steps ,
117
+ use_vision = use_vision ,
118
+ max_actions_per_step = max_actions_per_step ,
119
+ tool_call_in_content = tool_call_in_content ,
120
+ browser_context = browser_context ,
121
+ )
122
+ else :
123
+ raise ValueError (f"Invalid agent type: { agent_type } " )
124
+
125
+ # Get the list of videos after the agent runs (if recording is enabled)
126
+ latest_video = None
127
+ if save_recording_path :
128
+ new_videos = set (
129
+ glob .glob (os .path .join (save_recording_path , "*.[mM][pP]4" ))
130
+ + glob .glob (os .path .join (save_recording_path , "*.[wW][eE][bB][mM]" ))
131
+ )
132
+ if new_videos - existing_videos :
133
+ latest_video = list (new_videos - existing_videos )[0 ] # Get the first new video
113
134
114
- finally :
115
- if browser :
116
- browser .close ()
135
+ return final_result , errors , model_actions , model_thoughts , latest_video
117
136
118
137
async def run_org_agent (
119
138
llm ,
@@ -151,6 +170,8 @@ async def run_org_agent(
151
170
task = task ,
152
171
llm = llm ,
153
172
use_vision = use_vision ,
173
+ max_actions_per_step = max_actions_per_step ,
174
+ tool_call_in_content = tool_call_in_content ,
154
175
browser_context = browser_context_in ,
155
176
)
156
177
history = await agent .run (max_steps = max_steps )
@@ -180,7 +201,7 @@ async def run_org_agent(
180
201
model_actions = history .model_actions ()
181
202
model_thoughts = history .model_thoughts ()
182
203
recorded_files = get_latest_files (save_recording_path )
183
- trace_file = get_latest_files (save_recording_path + "/../traces" )
204
+ trace_file = get_latest_files (save_trace_path )
184
205
return final_result , errors , model_actions , model_thoughts , recorded_files .get ('.webm' ), trace_file .get ('.zip' )
185
206
186
207
async def run_custom_agent (
0 commit comments