mirror of
https://github.com/browser-use/web-ui.git
synced 2026-03-22 11:17:17 +08:00
feat: add Agent History feature to save into file and download option in Result.
This commit is contained in:
36
webui.py
36
webui.py
@@ -92,6 +92,7 @@ async def run_browser_agent(
|
||||
window_w,
|
||||
window_h,
|
||||
save_recording_path,
|
||||
save_agent_history_path,
|
||||
save_trace_path,
|
||||
enable_recording,
|
||||
task,
|
||||
@@ -156,6 +157,7 @@ async def run_browser_agent(
|
||||
window_w=window_w,
|
||||
window_h=window_h,
|
||||
save_recording_path=save_recording_path,
|
||||
save_agent_history_path=save_agent_history_path,
|
||||
save_trace_path=save_trace_path,
|
||||
task=task,
|
||||
add_infos=add_infos,
|
||||
@@ -299,6 +301,7 @@ async def run_custom_agent(
|
||||
window_w,
|
||||
window_h,
|
||||
save_recording_path,
|
||||
save_agent_history_path,
|
||||
save_trace_path,
|
||||
task,
|
||||
add_infos,
|
||||
@@ -361,6 +364,9 @@ async def run_custom_agent(
|
||||
)
|
||||
history = await agent.run(max_steps=max_steps)
|
||||
|
||||
history_file = os.path.join(save_agent_history_path, "AgentHistory.json")
|
||||
agent.save_history(history_file)
|
||||
|
||||
final_result = history.final_result()
|
||||
errors = history.errors()
|
||||
model_actions = history.model_actions()
|
||||
@@ -399,6 +405,7 @@ async def run_with_stream(
|
||||
window_w,
|
||||
window_h,
|
||||
save_recording_path,
|
||||
save_agent_history_path,
|
||||
save_trace_path,
|
||||
enable_recording,
|
||||
task,
|
||||
@@ -425,6 +432,7 @@ async def run_with_stream(
|
||||
window_w=window_w,
|
||||
window_h=window_h,
|
||||
save_recording_path=save_recording_path,
|
||||
save_agent_history_path=save_agent_history_path,
|
||||
save_trace_path=save_trace_path,
|
||||
enable_recording=enable_recording,
|
||||
task=task,
|
||||
@@ -455,6 +463,7 @@ async def run_with_stream(
|
||||
window_w=window_w,
|
||||
window_h=window_h,
|
||||
save_recording_path=save_recording_path,
|
||||
save_agent_history_path=save_agent_history_path,
|
||||
save_trace_path=save_trace_path,
|
||||
enable_recording=enable_recording,
|
||||
task=task,
|
||||
@@ -725,6 +734,14 @@ def create_ui(theme_name="Ocean"):
|
||||
interactive=True,
|
||||
)
|
||||
|
||||
save_agent_history_path = gr.Textbox(
|
||||
label="Agent History Save Path",
|
||||
placeholder="e.g., ./tmp/agent_history",
|
||||
value="./tmp/agent_history",
|
||||
info="Specify the directory where agent history should be saved.",
|
||||
interactive=True,
|
||||
)
|
||||
|
||||
with gr.TabItem("🤖 Run Agent", id=4):
|
||||
task = gr.Textbox(
|
||||
label="Task Description",
|
||||
@@ -777,6 +794,14 @@ def create_ui(theme_name="Ocean"):
|
||||
|
||||
trace_file = gr.File(label="Trace File")
|
||||
|
||||
history_download_button = gr.Button("⬇️ Download Agent History")
|
||||
|
||||
history_download_button.click(
|
||||
fn=utils.download_agent_history,
|
||||
inputs=save_agent_history_path,
|
||||
outputs=gr.File(),
|
||||
)
|
||||
|
||||
# Bind the stop button click event after errors_output is defined
|
||||
stop_button.click(
|
||||
fn=stop_agent,
|
||||
@@ -787,11 +812,12 @@ def create_ui(theme_name="Ocean"):
|
||||
# Run button click handler
|
||||
run_button.click(
|
||||
fn=run_with_stream,
|
||||
inputs=[
|
||||
agent_type, llm_provider, llm_model_name, llm_temperature, llm_base_url, llm_api_key,
|
||||
use_own_browser, keep_browser_open, headless, disable_security, window_w, window_h, save_recording_path, save_trace_path,
|
||||
enable_recording, task, add_infos, max_steps, use_vision, max_actions_per_step, tool_call_in_content
|
||||
],
|
||||
inputs=[
|
||||
agent_type, llm_provider, llm_model_name, llm_temperature, llm_base_url, llm_api_key,
|
||||
use_own_browser, keep_browser_open, headless, disable_security, window_w, window_h,
|
||||
save_recording_path, save_agent_history_path, save_trace_path, # Include the new path
|
||||
enable_recording, task, add_infos, max_steps, use_vision, max_actions_per_step, tool_call_in_content
|
||||
],
|
||||
outputs=[
|
||||
browser_view, # Browser view
|
||||
final_result_output, # Final result
|
||||
|
||||
Reference in New Issue
Block a user