From 2eb894993ec6ffdb42bc77b77b8a8b82a8faecd3 Mon Sep 17 00:00:00 2001 From: meshkatshb Date: Mon, 13 Jan 2025 22:37:43 +0330 Subject: [PATCH 1/6] feat: update gitignore for sharing and docker --- .gitignore | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5fda7cd..2d83410 100644 --- a/.gitignore +++ b/.gitignore @@ -177,4 +177,10 @@ cookies.json AgentHistory.json cv_04_24.pdf AgentHistoryList.json -*.gif \ No newline at end of file +*.gif + +# For Sharing (.pem files) +.gradio/ + +# For Docker +data/ From 2717d3a21c243f28bf57e2025ef573f7b0407a8f Mon Sep 17 00:00:00 2001 From: meshkatshb Date: Mon, 13 Jan 2025 22:38:51 +0330 Subject: [PATCH 2/6] feat: add download_agent_history function to make download AgentHistory --- src/utils/utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/utils/utils.py b/src/utils/utils.py index d5a8b25..5280407 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -200,3 +200,11 @@ async def capture_screenshot(browser_context): return encoded except Exception as e: return None + +def download_agent_history(save_agent_history_path): + history_file = os.path.join(save_agent_history_path, "AgentHistory.json") + history_file = os.path.abspath(history_file) # Convert to absolute path + if os.path.exists(history_file): + return history_file + else: + return None From 36649f352cec814c84f4a7c64b5899f85f7f9468 Mon Sep 17 00:00:00 2001 From: meshkatshb Date: Mon, 13 Jan 2025 22:39:43 +0330 Subject: [PATCH 3/6] feat: add Agent History feature to save into file and download option in Result. --- webui.py | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/webui.py b/webui.py index 4e2791a..54d12bd 100644 --- a/webui.py +++ b/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 From bbf9feac1f852ae50973e95fc2d66ed499f03b7a Mon Sep 17 00:00:00 2001 From: meshkatshb Date: Tue, 14 Jan 2025 17:22:37 +0330 Subject: [PATCH 4/6] refactor: create agent history file based on agent_ --- webui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webui.py b/webui.py index 54d12bd..8ee35aa 100644 --- a/webui.py +++ b/webui.py @@ -364,7 +364,7 @@ async def run_custom_agent( ) history = await agent.run(max_steps=max_steps) - history_file = os.path.join(save_agent_history_path, "AgentHistory.json") + history_file = os.path.join(save_agent_history_path, f"{agent.agent_id}.json") agent.save_history(history_file) final_result = history.final_result() From 4b64685988dd3ef5859e9a2a973450476da920b8 Mon Sep 17 00:00:00 2001 From: meshkatshb Date: Tue, 14 Jan 2025 17:38:10 +0330 Subject: [PATCH 5/6] refactor: remove agent history as a button and make it only a file in results tab --- src/utils/utils.py | 8 -------- webui.py | 15 ++++++--------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/utils/utils.py b/src/utils/utils.py index 5280407..d5a8b25 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -200,11 +200,3 @@ async def capture_screenshot(browser_context): return encoded except Exception as e: return None - -def download_agent_history(save_agent_history_path): - history_file = os.path.join(save_agent_history_path, "AgentHistory.json") - history_file = os.path.abspath(history_file) # Convert to absolute path - if os.path.exists(history_file): - return history_file - else: - return None diff --git a/webui.py b/webui.py index 8ee35aa..2f9cfb7 100644 --- a/webui.py +++ b/webui.py @@ -148,7 +148,7 @@ async def run_browser_agent( tool_call_in_content=tool_call_in_content ) elif agent_type == "custom": - final_result, errors, model_actions, model_thoughts, trace_file = await run_custom_agent( + final_result, errors, model_actions, model_thoughts, trace_file, history_file = await run_custom_agent( llm=llm, use_own_browser=use_own_browser, keep_browser_open=keep_browser_open, @@ -186,6 +186,7 @@ async def run_browser_agent( model_thoughts, latest_video, trace_file, + history_file, gr.update(value="Stop", interactive=True), # Re-enable stop button gr.update(value="Run", interactive=True) # Re-enable run button ) @@ -201,6 +202,7 @@ async def run_browser_agent( '', # model_thoughts None, # latest_video None, # trace_file + None, # history_file gr.update(value="Stop", interactive=True), # Re-enable stop button gr.update(value="Run", interactive=True) # Re-enable run button ) @@ -374,7 +376,7 @@ async def run_custom_agent( trace_file = get_latest_files(save_trace_path) - return final_result, errors, model_actions, model_thoughts, trace_file.get('.zip') + return final_result, errors, model_actions, model_thoughts, trace_file.get('.zip'), history_file except Exception as e: import traceback traceback.print_exc() @@ -794,13 +796,7 @@ 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(), - ) + agent_history_file = gr.File(label="Agent History") # Bind the stop button click event after errors_output is defined stop_button.click( @@ -826,6 +822,7 @@ def create_ui(theme_name="Ocean"): model_thoughts_output, # Model thoughts recording_display, # Latest recording trace_file, # Trace file + agent_history_file, # Agent history file stop_button, # Stop button run_button # Run button ], From 845d5dde30368e349aa225148a59dc779327741c Mon Sep 17 00:00:00 2001 From: meshkatshb Date: Tue, 14 Jan 2025 17:48:27 +0330 Subject: [PATCH 6/6] feat: add agent history file to org agents --- webui.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/webui.py b/webui.py index 2f9cfb7..0cdde53 100644 --- a/webui.py +++ b/webui.py @@ -131,7 +131,7 @@ async def run_browser_agent( api_key=llm_api_key, ) if agent_type == "org": - final_result, errors, model_actions, model_thoughts, trace_file = await run_org_agent( + final_result, errors, model_actions, model_thoughts, trace_file, history_file = await run_org_agent( llm=llm, use_own_browser=use_own_browser, keep_browser_open=keep_browser_open, @@ -140,6 +140,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, max_steps=max_steps, @@ -201,8 +202,8 @@ async def run_browser_agent( '', # model_actions '', # model_thoughts None, # latest_video - None, # trace_file None, # history_file + None, # trace_file gr.update(value="Stop", interactive=True), # Re-enable stop button gr.update(value="Run", interactive=True) # Re-enable run button ) @@ -217,6 +218,7 @@ async def run_org_agent( window_w, window_h, save_recording_path, + save_agent_history_path, save_trace_path, task, max_steps, @@ -270,14 +272,17 @@ async def run_org_agent( ) history = await agent.run(max_steps=max_steps) + history_file = os.path.join(save_agent_history_path, f"{agent.agent_id}.json") + agent.save_history(history_file) + final_result = history.final_result() errors = history.errors() model_actions = history.model_actions() model_thoughts = history.model_thoughts() - + trace_file = get_latest_files(save_trace_path) - - return final_result, errors, model_actions, model_thoughts, trace_file.get('.zip') + + return final_result, errors, model_actions, model_thoughts, trace_file.get('.zip'), history_file except Exception as e: import traceback traceback.print_exc() @@ -381,7 +386,7 @@ async def run_custom_agent( import traceback traceback.print_exc() errors = str(e) + "\n" + traceback.format_exc() - return '', errors, '', '', None + return '', errors, '', '', None, None finally: # Handle cleanup based on persistence configuration if not keep_browser_open: