@@ -92,6 +92,7 @@ async def run_browser_agent(
92
92
window_w ,
93
93
window_h ,
94
94
save_recording_path ,
95
+ save_agent_history_path ,
95
96
save_trace_path ,
96
97
enable_recording ,
97
98
task ,
@@ -130,7 +131,7 @@ async def run_browser_agent(
130
131
api_key = llm_api_key ,
131
132
)
132
133
if agent_type == "org" :
133
- final_result , errors , model_actions , model_thoughts , trace_file = await run_org_agent (
134
+ final_result , errors , model_actions , model_thoughts , trace_file , history_file = await run_org_agent (
134
135
llm = llm ,
135
136
use_own_browser = use_own_browser ,
136
137
keep_browser_open = keep_browser_open ,
@@ -139,6 +140,7 @@ async def run_browser_agent(
139
140
window_w = window_w ,
140
141
window_h = window_h ,
141
142
save_recording_path = save_recording_path ,
143
+ save_agent_history_path = save_agent_history_path ,
142
144
save_trace_path = save_trace_path ,
143
145
task = task ,
144
146
max_steps = max_steps ,
@@ -147,7 +149,7 @@ async def run_browser_agent(
147
149
tool_call_in_content = tool_call_in_content
148
150
)
149
151
elif agent_type == "custom" :
150
- final_result , errors , model_actions , model_thoughts , trace_file = await run_custom_agent (
152
+ final_result , errors , model_actions , model_thoughts , trace_file , history_file = await run_custom_agent (
151
153
llm = llm ,
152
154
use_own_browser = use_own_browser ,
153
155
keep_browser_open = keep_browser_open ,
@@ -156,6 +158,7 @@ async def run_browser_agent(
156
158
window_w = window_w ,
157
159
window_h = window_h ,
158
160
save_recording_path = save_recording_path ,
161
+ save_agent_history_path = save_agent_history_path ,
159
162
save_trace_path = save_trace_path ,
160
163
task = task ,
161
164
add_infos = add_infos ,
@@ -184,6 +187,7 @@ async def run_browser_agent(
184
187
model_thoughts ,
185
188
latest_video ,
186
189
trace_file ,
190
+ history_file ,
187
191
gr .update (value = "Stop" , interactive = True ), # Re-enable stop button
188
192
gr .update (value = "Run" , interactive = True ) # Re-enable run button
189
193
)
@@ -198,6 +202,7 @@ async def run_browser_agent(
198
202
'' , # model_actions
199
203
'' , # model_thoughts
200
204
None , # latest_video
205
+ None , # history_file
201
206
None , # trace_file
202
207
gr .update (value = "Stop" , interactive = True ), # Re-enable stop button
203
208
gr .update (value = "Run" , interactive = True ) # Re-enable run button
@@ -213,6 +218,7 @@ async def run_org_agent(
213
218
window_w ,
214
219
window_h ,
215
220
save_recording_path ,
221
+ save_agent_history_path ,
216
222
save_trace_path ,
217
223
task ,
218
224
max_steps ,
@@ -266,14 +272,17 @@ async def run_org_agent(
266
272
)
267
273
history = await agent .run (max_steps = max_steps )
268
274
275
+ history_file = os .path .join (save_agent_history_path , f"{ agent .agent_id } .json" )
276
+ agent .save_history (history_file )
277
+
269
278
final_result = history .final_result ()
270
279
errors = history .errors ()
271
280
model_actions = history .model_actions ()
272
281
model_thoughts = history .model_thoughts ()
273
-
282
+
274
283
trace_file = get_latest_files (save_trace_path )
275
-
276
- return final_result , errors , model_actions , model_thoughts , trace_file .get ('.zip' )
284
+
285
+ return final_result , errors , model_actions , model_thoughts , trace_file .get ('.zip' ), history_file
277
286
except Exception as e :
278
287
import traceback
279
288
traceback .print_exc ()
@@ -299,6 +308,7 @@ async def run_custom_agent(
299
308
window_w ,
300
309
window_h ,
301
310
save_recording_path ,
311
+ save_agent_history_path ,
302
312
save_trace_path ,
303
313
task ,
304
314
add_infos ,
@@ -361,19 +371,22 @@ async def run_custom_agent(
361
371
)
362
372
history = await agent .run (max_steps = max_steps )
363
373
374
+ history_file = os .path .join (save_agent_history_path , f"{ agent .agent_id } .json" )
375
+ agent .save_history (history_file )
376
+
364
377
final_result = history .final_result ()
365
378
errors = history .errors ()
366
379
model_actions = history .model_actions ()
367
380
model_thoughts = history .model_thoughts ()
368
381
369
382
trace_file = get_latest_files (save_trace_path )
370
383
371
- return final_result , errors , model_actions , model_thoughts , trace_file .get ('.zip' )
384
+ return final_result , errors , model_actions , model_thoughts , trace_file .get ('.zip' ), history_file
372
385
except Exception as e :
373
386
import traceback
374
387
traceback .print_exc ()
375
388
errors = str (e ) + "\n " + traceback .format_exc ()
376
- return '' , errors , '' , '' , None
389
+ return '' , errors , '' , '' , None , None
377
390
finally :
378
391
# Handle cleanup based on persistence configuration
379
392
if not keep_browser_open :
@@ -399,6 +412,7 @@ async def run_with_stream(
399
412
window_w ,
400
413
window_h ,
401
414
save_recording_path ,
415
+ save_agent_history_path ,
402
416
save_trace_path ,
403
417
enable_recording ,
404
418
task ,
@@ -425,6 +439,7 @@ async def run_with_stream(
425
439
window_w = window_w ,
426
440
window_h = window_h ,
427
441
save_recording_path = save_recording_path ,
442
+ save_agent_history_path = save_agent_history_path ,
428
443
save_trace_path = save_trace_path ,
429
444
enable_recording = enable_recording ,
430
445
task = task ,
@@ -455,6 +470,7 @@ async def run_with_stream(
455
470
window_w = window_w ,
456
471
window_h = window_h ,
457
472
save_recording_path = save_recording_path ,
473
+ save_agent_history_path = save_agent_history_path ,
458
474
save_trace_path = save_trace_path ,
459
475
enable_recording = enable_recording ,
460
476
task = task ,
@@ -725,6 +741,14 @@ def create_ui(theme_name="Ocean"):
725
741
interactive = True ,
726
742
)
727
743
744
+ save_agent_history_path = gr .Textbox (
745
+ label = "Agent History Save Path" ,
746
+ placeholder = "e.g., ./tmp/agent_history" ,
747
+ value = "./tmp/agent_history" ,
748
+ info = "Specify the directory where agent history should be saved." ,
749
+ interactive = True ,
750
+ )
751
+
728
752
with gr .TabItem ("🤖 Run Agent" , id = 4 ):
729
753
task = gr .Textbox (
730
754
label = "Task Description" ,
@@ -777,6 +801,8 @@ def create_ui(theme_name="Ocean"):
777
801
778
802
trace_file = gr .File (label = "Trace File" )
779
803
804
+ agent_history_file = gr .File (label = "Agent History" )
805
+
780
806
# Bind the stop button click event after errors_output is defined
781
807
stop_button .click (
782
808
fn = stop_agent ,
@@ -787,11 +813,12 @@ def create_ui(theme_name="Ocean"):
787
813
# Run button click handler
788
814
run_button .click (
789
815
fn = run_with_stream ,
790
- inputs = [
791
- agent_type , llm_provider , llm_model_name , llm_temperature , llm_base_url , llm_api_key ,
792
- use_own_browser , keep_browser_open , headless , disable_security , window_w , window_h , save_recording_path , save_trace_path ,
793
- enable_recording , task , add_infos , max_steps , use_vision , max_actions_per_step , tool_call_in_content
794
- ],
816
+ inputs = [
817
+ agent_type , llm_provider , llm_model_name , llm_temperature , llm_base_url , llm_api_key ,
818
+ use_own_browser , keep_browser_open , headless , disable_security , window_w , window_h ,
819
+ save_recording_path , save_agent_history_path , save_trace_path , # Include the new path
820
+ enable_recording , task , add_infos , max_steps , use_vision , max_actions_per_step , tool_call_in_content
821
+ ],
795
822
outputs = [
796
823
browser_view , # Browser view
797
824
final_result_output , # Final result
@@ -800,6 +827,7 @@ def create_ui(theme_name="Ocean"):
800
827
model_thoughts_output , # Model thoughts
801
828
recording_display , # Latest recording
802
829
trace_file , # Trace file
830
+ agent_history_file , # Agent history file
803
831
stop_button , # Stop button
804
832
run_button # Run button
805
833
],
0 commit comments