Skip to content

Commit 36649f3

Browse files
committed
feat: add Agent History feature to save into file and download option in Result.
1 parent 2717d3a commit 36649f3

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

webui.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ async def run_browser_agent(
9292
window_w,
9393
window_h,
9494
save_recording_path,
95+
save_agent_history_path,
9596
save_trace_path,
9697
enable_recording,
9798
task,
@@ -156,6 +157,7 @@ async def run_browser_agent(
156157
window_w=window_w,
157158
window_h=window_h,
158159
save_recording_path=save_recording_path,
160+
save_agent_history_path=save_agent_history_path,
159161
save_trace_path=save_trace_path,
160162
task=task,
161163
add_infos=add_infos,
@@ -299,6 +301,7 @@ async def run_custom_agent(
299301
window_w,
300302
window_h,
301303
save_recording_path,
304+
save_agent_history_path,
302305
save_trace_path,
303306
task,
304307
add_infos,
@@ -361,6 +364,9 @@ async def run_custom_agent(
361364
)
362365
history = await agent.run(max_steps=max_steps)
363366

367+
history_file = os.path.join(save_agent_history_path, "AgentHistory.json")
368+
agent.save_history(history_file)
369+
364370
final_result = history.final_result()
365371
errors = history.errors()
366372
model_actions = history.model_actions()
@@ -399,6 +405,7 @@ async def run_with_stream(
399405
window_w,
400406
window_h,
401407
save_recording_path,
408+
save_agent_history_path,
402409
save_trace_path,
403410
enable_recording,
404411
task,
@@ -425,6 +432,7 @@ async def run_with_stream(
425432
window_w=window_w,
426433
window_h=window_h,
427434
save_recording_path=save_recording_path,
435+
save_agent_history_path=save_agent_history_path,
428436
save_trace_path=save_trace_path,
429437
enable_recording=enable_recording,
430438
task=task,
@@ -455,6 +463,7 @@ async def run_with_stream(
455463
window_w=window_w,
456464
window_h=window_h,
457465
save_recording_path=save_recording_path,
466+
save_agent_history_path=save_agent_history_path,
458467
save_trace_path=save_trace_path,
459468
enable_recording=enable_recording,
460469
task=task,
@@ -725,6 +734,14 @@ def create_ui(theme_name="Ocean"):
725734
interactive=True,
726735
)
727736

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+
728745
with gr.TabItem("🤖 Run Agent", id=4):
729746
task = gr.Textbox(
730747
label="Task Description",
@@ -777,6 +794,14 @@ def create_ui(theme_name="Ocean"):
777794

778795
trace_file = gr.File(label="Trace File")
779796

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+
780805
# Bind the stop button click event after errors_output is defined
781806
stop_button.click(
782807
fn=stop_agent,
@@ -787,11 +812,12 @@ def create_ui(theme_name="Ocean"):
787812
# Run button click handler
788813
run_button.click(
789814
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+
],
795821
outputs=[
796822
browser_view, # Browser view
797823
final_result_output, # Final result

0 commit comments

Comments
 (0)