Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

Removed num_clicks, fixed type valuation -> evaluation, and multiaction with output list

magmueller90ef74acebb7
diff --git a/browser_use/agent/message_manager/tests.py b/browser_use/agent/message_manager/tests.py
index 776e35a12..85ef3bb70 100644
--- a/browser_use/agent/message_manager/tests.py
+++ b/browser_use/agent/message_manager/tests.py
@@ -194,11 +194,11 @@ def test_token_overflow_handling_with_real_flow(message_manager: MessageManager,
output = AgentOutput(
current_state=AgentBrain(
- valuation_previous_goal=f'Success in step {i}',
+ evaluation_previous_goal=f'Success in step {i}',
memory=f'Memory from step {i}',
next_goal=f'Goal for step {i+1}',
),
- action=ActionModel(),
+ action=[ActionModel()],
)
message_manager._remove_last_state_message()
message_manager.add_model_output(output)
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index 21242feff..3a8952de7 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -228,14 +228,14 @@ class Agent:
def _log_response(self, response: AgentOutput) -> None:
"""Log the model's response"""
- if 'Success' in response.current_state.valuation_previous_goal:
+ if 'Success' in response.current_state.evaluation_previous_goal:
emoji = '👍'
- elif 'Failed' in response.current_state.valuation_previous_goal:
+ elif 'Failed' in response.current_state.evaluation_previous_goal:
emoji = '⚠️'
else:
emoji = '🤷'
- logger.info(f'{emoji} Evaluation: {response.current_state.valuation_previous_goal}')
+ logger.info(f'{emoji} Evaluation: {response.current_state.evaluation_previous_goal}')
logger.info(f'🧠 Memory: {response.current_state.memory}')
logger.info(f'🎯 Next Goal: {response.current_state.next_goal}')
for action in response.action:
diff --git a/browser_use/agent/tests.py b/browser_use/agent/tests.py
index 77a0b7d1b..624a6aeda 100644
--- a/browser_use/agent/tests.py
+++ b/browser_use/agent/tests.py
@@ -62,7 +62,7 @@ def action_registry():
@pytest.fixture
def sample_history(action_registry):
# Create actions with nested params structure
- click_action = action_registry(click_element={'index': 1, 'num_clicks': 1})
+ click_action = action_registry(click_element={'index': 1})
extract_action = action_registry(extract_page_content={'value': 'text'})
@@ -72,54 +72,59 @@ def sample_history(action_registry):
AgentHistory(
model_output=AgentOutput(
current_state=AgentBrain(
- valuation_previous_goal='None', memory='Started task', next_goal='Click button'
+ evaluation_previous_goal='None', memory='Started task', next_goal='Click button'
),
- action=click_action,
+ action=[click_action],
),
- result=ActionResult(is_done=False),
+ result=[ActionResult(is_done=False)],
state=BrowserStateHistory(
url='https://example.com',
title='Page 1',
tabs=[TabInfo(url='https://example.com', title='Page 1', page_id=1)],
screenshot='screenshot1.png',
+ interacted_element=[],
),
),
AgentHistory(
model_output=AgentOutput(
current_state=AgentBrain(
- valuation_previous_goal='Clicked button',
+ evaluation_previous_goal='Clicked button',
memory='Button clicked',
next_goal='Extract content',
),
- action=extract_action,
- ),
- result=ActionResult(
- is_done=False,
- extracted_content='Extracted text',
- error='Failed to extract completely',
+ action=[extract_action],
),
+ result=[
+ ActionResult(
+ is_done=False,
+ extracted_content='Extracted text',
+ error='Failed to extract completely',
+ )
+ ],
state=BrowserStateHistory(
url='https://example.com/page2',
title='Page 2',
tabs=[TabInfo(url='https://example.com/page2', title='Page 2', page_id=2)],
screenshot='screenshot2.png',
+ interacted_element=[],
),
),
AgentHistory(
model_output=AgentOutput(
current_state=AgentBrain(
- valuation_previous_goal='Extracted content',
+ evaluation_previous_goal='Extracted content',
memory='Content extracted',
next_goal='Finish task',
),
- action=done_action,
+ action=[done_action],
),
- result=ActionResult(is_done=True, extracted_content='Task completed', error=None),
+ result=[ActionResult(is_done=True, extracted_content='Task completed', error=None)],
state=BrowserStateHistory(
url='https://example.com/page2',
title='Page 2',
tabs=[TabInfo(url='https://example.com/page2', title='Page 2', page_id=2)],
screenshot='screenshot3.png',
+ interacted_element=[],
),
),
]
@@ -161,7 +166,7 @@ def test_all_screenshots(sample_history: AgentHistoryList):
def test_all_model_outputs(sample_history: AgentHistoryList):
outputs = sample_history.model_actions()
assert len(outputs) == 3
- assert outputs[0] == {'click_element': {'index': 1, 'xpath': '//button[1]', 'num_clicks': 1}}
+ assert outputs[0] == {'click_element': {'index': 1, 'xpath': '//button[1]'}}
assert outputs[1] == {'extract_page_content': {'value': 'text'}}
assert outputs[2] == {'done': {'text': 'Task completed'}}
@@ -182,11 +187,9 @@ def test_empty_history():
# Add a test to verify action creation
def test_action_creation(action_registry):
- click_action = action_registry(click_element={'index': 1, 'num_clicks': 1})
+ click_action = action_registry(click_element={'index': 1})
- assert click_action.model_dump(exclude_none=True) == {
- 'click_element': {'index': 1, 'num_clicks': 1}
- }
+ assert click_action.model_dump(exclude_none=True) == {'click_element': {'index': 1}}
# run this with:
diff --git a/browser_use/agent/views.py b/browser_use/agent/views.py
index a5cc86f18..9a9c5bcb7 100644
--- a/browser_use/agent/views.py
+++ b/browser_use/agent/views.py
@@ -30,7 +30,7 @@ class ActionResult(BaseModel):
class AgentBrain(BaseModel):
"""Current state of the agent"""
- valuation_previous_goal: str
+ evaluation_previous_goal: str
memory: str
next_goal: str
diff --git a/browser_use/controller/service.py b/browser_use/controller/service.py
index ea638495a..1c14bed9c 100644
--- a/browser_use/controller/service.py
+++ b/browser_use/controller/service.py
@@ -72,20 +72,15 @@ class Controller:
msg = None
- for _ in range(params.num_clicks):
- try:
- await browser._click_element_node(element_node)
- msg = f'🖱️ Clicked element {params.index}: {element_node.xpath}'
- if params.num_clicks > 1:
- msg += f' ({_ + 1}/{params.num_clicks} clicks)'
- except Exception as e:
- logger.warning(f'Element no longer available after {_ + 1} clicks: {str(e)}')
- break
-
- if len(session.context.pages) > initial_pages:
- await browser.switch_to_tab(-1)
-
- return ActionResult(extracted_content=f'{msg}')
+ try:
+ await browser._click_element_node(element_node)
+ msg = f'🖱️ Clicked element {params.index}: {element_node.xpath}'
+ if len(session.context.pages) > initial_pages:
+ await browser.switch_to_tab(-1)
+ return ActionResult(extracted_content=msg)
+ except Exception as e:
+ logger.warning(f'Element no longer available: {str(e)}')
+ return ActionResult(error=str(e))
@self.registry.action('Input text', param_model=InputTextAction, requires_browser=True)
async def input_text(params: InputTextAction, browser: Browser):
diff --git a/browser_use/controller/views.py b/browser_use/controller/views.py
index c1befdad7..7a2dc9904 100644
--- a/browser_use/controller/views.py
+++ b/browser_use/controller/views.py
@@ -14,7 +14,6 @@ class GoToUrlAction(BaseModel):
class ClickElementAction(BaseModel):
index: int
- num_clicks: int = 1
xpath: Optional[str] = None
diff --git a/tests/test_agent_actions.py b/tests/test_agent_actions.py
index 57ea50e6e..50eca7ad7 100644
--- a/tests/test_agent_actions.py
+++ b/tests/test_agent_actions.py
@@ -156,7 +156,6 @@ class CaptchaTest(BaseModel):
@pytest.mark.parametrize(
'captcha',
[
- # good test for num_clicks
CaptchaTest(
name='Text Captcha',
url='https://2captcha.com/demo/text',
@@ -171,7 +170,7 @@ class CaptchaTest(BaseModel):
name='Rotate Captcha',
url='https://2captcha.com/demo/rotatecaptcha',
success_text='Captcha is passed successfully',
- additional_text='Use num_clicks with number to click multiple times at once in same direction. click done when image is exact correct position.',
+ additional_text='Use multiple clicks at once. click done when image is exact correct position.',
),
CaptchaTest(
name='MT Captcha',