adapt to browser-use==0.1.29

This commit is contained in:
vincent
2025-01-27 14:10:23 +08:00
parent 8a09c96585
commit 6ceaf8de6b
13 changed files with 429 additions and 488 deletions

View File

@@ -21,6 +21,7 @@ from browser_use.browser.context import (
BrowserContextConfig,
BrowserContextWindowSize,
)
from langchain_ollama import ChatOllama
from playwright.async_api import async_playwright
from src.utils.agent_state import AgentState
@@ -91,7 +92,7 @@ async def run_browser_agent(
max_steps,
use_vision,
max_actions_per_step,
tool_call_in_content
tool_calling_method
):
global _global_agent_state
_global_agent_state.clear_stop() # Clear any previous stop requests
@@ -137,7 +138,7 @@ async def run_browser_agent(
max_steps=max_steps,
use_vision=use_vision,
max_actions_per_step=max_actions_per_step,
tool_call_in_content=tool_call_in_content
tool_calling_method=tool_calling_method
)
elif agent_type == "custom":
final_result, errors, model_actions, model_thoughts, trace_file, history_file = await run_custom_agent(
@@ -156,7 +157,7 @@ async def run_browser_agent(
max_steps=max_steps,
use_vision=use_vision,
max_actions_per_step=max_actions_per_step,
tool_call_in_content=tool_call_in_content
tool_calling_method=tool_calling_method
)
else:
raise ValueError(f"Invalid agent type: {agent_type}")
@@ -215,7 +216,7 @@ async def run_org_agent(
max_steps,
use_vision,
max_actions_per_step,
tool_call_in_content
tool_calling_method
):
try:
global _global_browser, _global_browser_context, _global_agent_state
@@ -251,7 +252,7 @@ async def run_org_agent(
),
)
)
agent = Agent(
task=task,
llm=llm,
@@ -259,7 +260,7 @@ async def run_org_agent(
browser=_global_browser,
browser_context=_global_browser_context,
max_actions_per_step=max_actions_per_step,
tool_call_in_content=tool_call_in_content
tool_calling_method=tool_calling_method
)
history = await agent.run(max_steps=max_steps)
@@ -306,7 +307,7 @@ async def run_custom_agent(
max_steps,
use_vision,
max_actions_per_step,
tool_call_in_content
tool_calling_method
):
try:
global _global_browser, _global_browser_context, _global_agent_state
@@ -345,7 +346,7 @@ async def run_custom_agent(
),
)
)
# Create and run agent
agent = CustomAgent(
task=task,
@@ -357,8 +358,8 @@ async def run_custom_agent(
controller=controller,
system_prompt_class=CustomSystemPrompt,
max_actions_per_step=max_actions_per_step,
tool_call_in_content=tool_call_in_content,
agent_state=_global_agent_state
agent_state=_global_agent_state,
tool_calling_method=tool_calling_method
)
history = await agent.run(max_steps=max_steps)
@@ -411,7 +412,7 @@ async def run_with_stream(
max_steps,
use_vision,
max_actions_per_step,
tool_call_in_content
tool_calling_method
):
global _global_agent_state
stream_vw = 80
@@ -439,7 +440,7 @@ async def run_with_stream(
max_steps=max_steps,
use_vision=use_vision,
max_actions_per_step=max_actions_per_step,
tool_call_in_content=tool_call_in_content
tool_calling_method=tool_calling_method
)
# Add HTML content at the start of the result array
html_content = f"<h1 style='width:{stream_vw}vw; height:{stream_vh}vh'>Using browser...</h1>"
@@ -471,7 +472,7 @@ async def run_with_stream(
max_steps=max_steps,
use_vision=use_vision,
max_actions_per_step=max_actions_per_step,
tool_call_in_content=tool_call_in_content
tool_calling_method=tool_calling_method
)
)
@@ -628,32 +629,37 @@ def create_ui(config, theme_name="Ocean"):
value=config['agent_type'],
info="Select the type of agent to use",
)
max_steps = gr.Slider(
minimum=1,
maximum=200,
value=config['max_steps'],
step=1,
label="Max Run Steps",
info="Maximum number of steps the agent will take",
)
max_actions_per_step = gr.Slider(
minimum=1,
maximum=20,
value=config['max_actions_per_step'],
step=1,
label="Max Actions per Step",
info="Maximum number of actions the agent will take per step",
)
use_vision = gr.Checkbox(
label="Use Vision",
value=config['use_vision'],
info="Enable visual processing capabilities",
)
tool_call_in_content = gr.Checkbox(
label="Use Tool Calls in Content",
value=config['tool_call_in_content'],
info="Enable Tool Calls in content",
)
with gr.Column():
max_steps = gr.Slider(
minimum=1,
maximum=200,
value=config['max_steps'],
step=1,
label="Max Run Steps",
info="Maximum number of steps the agent will take",
)
max_actions_per_step = gr.Slider(
minimum=1,
maximum=20,
value=config['max_actions_per_step'],
step=1,
label="Max Actions per Step",
info="Maximum number of actions the agent will take per step",
)
with gr.Column():
use_vision = gr.Checkbox(
label="Use Vision",
value=config['use_vision'],
info="Enable visual processing capabilities",
)
tool_calling_method = gr.Dropdown(
label="Tool Calling Method",
value=config['tool_calling_method'],
interactive=True,
allow_custom_value=True, # Allow users to input custom model names
choices=["auto", "json_schema", "function_calling"],
info="Tool Calls Funtion Name"
)
with gr.TabItem("🔧 LLM Configuration", id=2):
with gr.Group():
@@ -803,7 +809,7 @@ def create_ui(config, theme_name="Ocean"):
fn=update_ui_from_config,
inputs=[config_file_input],
outputs=[
agent_type, max_steps, max_actions_per_step, use_vision, tool_call_in_content,
agent_type, max_steps, max_actions_per_step, use_vision, tool_calling_method,
llm_provider, llm_model_name, llm_temperature, llm_base_url, llm_api_key,
use_own_browser, keep_browser_open, headless, disable_security, enable_recording,
window_w, window_h, save_recording_path, save_trace_path, save_agent_history_path,
@@ -814,7 +820,7 @@ def create_ui(config, theme_name="Ocean"):
save_config_button.click(
fn=save_current_config,
inputs=[
agent_type, max_steps, max_actions_per_step, use_vision, tool_call_in_content,
agent_type, max_steps, max_actions_per_step, use_vision, tool_calling_method,
llm_provider, llm_model_name, llm_temperature, llm_base_url, llm_api_key,
use_own_browser, keep_browser_open, headless, disable_security,
enable_recording, window_w, window_h, save_recording_path, save_trace_path,
@@ -866,7 +872,7 @@ def create_ui(config, theme_name="Ocean"):
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
enable_recording, task, add_infos, max_steps, use_vision, max_actions_per_step, tool_calling_method
],
outputs=[
browser_view, # Browser view