Skip to content

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

Fix task instruction to be more clear and less likly end up in hallucination

magmuellerf6928747d5b2
diff --git a/browser_use/agent/message_manager/service.py b/browser_use/agent/message_manager/service.py
index 3c8fe27b9..76ed45047 100644
--- a/browser_use/agent/message_manager/service.py
+++ b/browser_use/agent/message_manager/service.py
@@ -85,9 +85,14 @@ class MessageManager:
self._add_message_with_tokens(example_tool_call)
- task_message = HumanMessage(content=f'Your task is: {task}')
+ task_message = self.task_instructions(task)
self._add_message_with_tokens(task_message)
+ @staticmethod
+ def task_instructions(task: str) -> HumanMessage:
+ content = f'Your ultimate task is: {task}. If you achieved your ultimate task, stop everything and use the done action in the next step to complete the task. If not, continue as usual.'
+ return HumanMessage(content=content)
+
def add_state_message(
self,
state: BrowserState,