Skip to content

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

improve example tool call in _init_messages to encourage model reasoning

Alezander9f19349eccf51
diff --git a/browser_use/agent/message_manager/service.py b/browser_use/agent/message_manager/service.py
index b75ea7d9d..0b2322e4f 100644
--- a/browser_use/agent/message_manager/service.py
+++ b/browser_use/agent/message_manager/service.py
@@ -70,25 +70,36 @@ class MessageManager:
placeholder_message = HumanMessage(content='Example output:')
self._add_message_with_tokens(placeholder_message, message_type='init')
- tool_calls = [
- {
+ example_tool_call = AIMessage(
+ content='',
+ tool_calls=[{
'name': 'AgentOutput',
'args': {
'current_state': {
- 'evaluation_previous_goal': 'Success - I opend the first page',
- 'memory': 'Starting with the new task. I have completed 1/10 steps',
- 'next_goal': 'Click on company a',
+ 'evaluation_previous_goal': """
+ Success - I successfully clicked on the 'Apple' link from the Google Search results page,
+ which directed me to the 'Apple' company homepage. This is a good start toward finding
+ the best place to buy a new iPhone as the Apple website often list iPhones for sale.
+ """.strip(),
+ 'memory': """
+ I searched for 'iPhone retailers' on Google. From the Google Search results page,
+ I used the 'click_element' tool to click on a element labelled 'Best Buy' but calling
+ the tool did not direct me to a new page. I then used the 'click_element' tool to click
+ on a element labelled 'Apple' which redirected me to the 'Apple' company homepage.
+ Currently at step 3/15.
+ """.strip(),
+ 'next_goal': """
+ Looking at reported structure of the current page, I can see the item '[127]<h3 iPhone/>'
+ in the content. I think this button will lead to more information and potentially prices
+ for iPhones. I'll click on the link to 'iPhone' at index [127] using the 'click_element'
+ tool and hope to see prices on the next page.
+ """.strip(),
},
- 'action': [{'click_element': {'index': 0}}],
+ 'action': [{'click_element': {'index': 127}}],
},
'id': str(self.state.tool_id),
'type': 'tool_call',
- }
- ]
-
- example_tool_call = AIMessage(
- content='',
- tool_calls=tool_calls,
+ },]
)
self._add_message_with_tokens(example_tool_call, message_type='init')
self.add_tool_message(content='Browser started', message_type='init')