@@ -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 ,
@@ -156,6 +157,7 @@ async def run_browser_agent(
156
157
window_w = window_w ,
157
158
window_h = window_h ,
158
159
save_recording_path = save_recording_path ,
160
+ save_agent_history_path = save_agent_history_path ,
159
161
save_trace_path = save_trace_path ,
160
162
task = task ,
161
163
add_infos = add_infos ,
@@ -299,6 +301,7 @@ async def run_custom_agent(
299
301
window_w ,
300
302
window_h ,
301
303
save_recording_path ,
304
+ save_agent_history_path ,
302
305
save_trace_path ,
303
306
task ,
304
307
add_infos ,
@@ -361,6 +364,9 @@ async def run_custom_agent(
361
364
)
362
365
history = await agent .run (max_steps = max_steps )
363
366
367
+ history_file = os .path .join (save_agent_history_path , "AgentHistory.json" )
368
+ agent .save_history (history_file )
369
+
364
370
final_result = history .final_result ()
365
371
errors = history .errors ()
366
372
model_actions = history .model_actions ()
@@ -399,6 +405,7 @@ async def run_with_stream(
399
405
window_w ,
400
406
window_h ,
401
407
save_recording_path ,
408
+ save_agent_history_path ,
402
409
save_trace_path ,
403
410
enable_recording ,
404
411
task ,
@@ -425,6 +432,7 @@ async def run_with_stream(
425
432
window_w = window_w ,
426
433
window_h = window_h ,
427
434
save_recording_path = save_recording_path ,
435
+ save_agent_history_path = save_agent_history_path ,
428
436
save_trace_path = save_trace_path ,
429
437
enable_recording = enable_recording ,
430
438
task = task ,
@@ -455,6 +463,7 @@ async def run_with_stream(
455
463
window_w = window_w ,
456
464
window_h = window_h ,
457
465
save_recording_path = save_recording_path ,
466
+ save_agent_history_path = save_agent_history_path ,
458
467
save_trace_path = save_trace_path ,
459
468
enable_recording = enable_recording ,
460
469
task = task ,
@@ -725,6 +734,14 @@ def create_ui(theme_name="Ocean"):
725
734
interactive = True ,
726
735
)
727
736
737
+ save_agent_history_path = gr .Textbox (
738
+ label = "Agent History Save Path" ,
739
+ placeholder = "e.g., ./tmp/agent_history" ,
740
+ value = "./tmp/agent_history" ,
741
+ info = "Specify the directory where agent history should be saved." ,
742
+ interactive = True ,
743
+ )
744
+
728
745
with gr .TabItem ("🤖 Run Agent" , id = 4 ):
729
746
task = gr .Textbox (
730
747
label = "Task Description" ,
@@ -777,6 +794,14 @@ def create_ui(theme_name="Ocean"):
777
794
778
795
trace_file = gr .File (label = "Trace File" )
779
796
797
+ history_download_button = gr .Button ("⬇️ Download Agent History" )
798
+
799
+ history_download_button .click (
800
+ fn = utils .download_agent_history ,
801
+ inputs = save_agent_history_path ,
802
+ outputs = gr .File (),
803
+ )
804
+
780
805
# Bind the stop button click event after errors_output is defined
781
806
stop_button .click (
782
807
fn = stop_agent ,
@@ -787,11 +812,12 @@ def create_ui(theme_name="Ocean"):
787
812
# Run button click handler
788
813
run_button .click (
789
814
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
- ],
815
+ inputs = [
816
+ agent_type , llm_provider , llm_model_name , llm_temperature , llm_base_url , llm_api_key ,
817
+ use_own_browser , keep_browser_open , headless , disable_security , window_w , window_h ,
818
+ save_recording_path , save_agent_history_path , save_trace_path , # Include the new path
819
+ enable_recording , task , add_infos , max_steps , use_vision , max_actions_per_step , tool_call_in_content
820
+ ],
795
821
outputs = [
796
822
browser_view , # Browser view
797
823
final_result_output , # Final result
0 commit comments