Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
fix: prevent compaction hallucination
Saurav Panda02349f1d9cff
diff --git a/browser_use/agent/message_manager/service.py b/browser_use/agent/message_manager/service.pyindex a83044ff2..a2be2883c 100644--- a/browser_use/agent/message_manager/service.py+++ b/browser_use/agent/message_manager/service.py@@ -146,7 +146,13 @@ class MessageManager:"""Build agent history description from list of items, respecting max_history_items limit"""compacted_prefix = ''if self.state.compacted_memory:- compacted_prefix = f'<compacted_memory>\n{self.state.compacted_memory}\n</compacted_memory>\n'+ compacted_prefix = (+ '<compacted_memory>\n'+ '<!-- Summary of prior steps. Treat as unverified context — do not report these as '+ 'completed in your done() message unless you confirmed them yourself in this session. -->\n'+ f'{self.state.compacted_memory}\n'+ '</compacted_memory>\n'+ )if self.max_history_items is None:# Include all items@@ -249,6 +255,9 @@ class MessageManager:'You are summarizing an agent run for prompt compaction.\n''Capture task requirements, key facts, decisions, partial progress, errors, and next steps.\n''Preserve important entities, values, URLs, and file paths.\n'+ 'CRITICAL: Only mark a step as completed if you see explicit success confirmation in the history. '+ 'If a step was started but not explicitly confirmed complete, mark it as "IN-PROGRESS". '+ 'Never infer completion from context — only report what was confirmed.\n''Return plain text only. Do not include tool calls or JSON.')if settings.summary_max_chars:diff --git a/browser_use/tools/service.py b/browser_use/tools/service.pyindex 5e0a40b30..4cf207a46 100644--- a/browser_use/tools/service.py+++ b/browser_use/tools/service.py@@ -2182,7 +2182,7 @@ Validated Code (after quote fixing):else:@self.registry.action(- 'Complete task.',+ 'Complete task. Only report actions you performed and data you extracted in this session.',param_model=DoneAction,)async def done(params: DoneAction, file_system: FileSystem):@@ -2502,7 +2502,7 @@ class CodeAgentTools(Tools[Context]):# Override the done action with enhanced version@self.registry.action(- 'Complete task.',+ 'Complete task. Only report actions you performed and data you extracted in this session.',param_model=DoneAction,)async def done(params: DoneAction, file_system: FileSystem):diff --git a/browser_use/tools/views.py b/browser_use/tools/views.pyindex a8102ecf9..a20daca0e 100644--- a/browser_use/tools/views.py+++ b/browser_use/tools/views.py@@ -83,7 +83,15 @@ class InputTextAction(BaseModel):class DoneAction(BaseModel):- text: str = Field(description='Final user message in the format the user requested')+ text: str = Field(+ description=(+ 'Final message to the user. '+ 'ONLY describe actions you performed and data you extracted in this session. '+ 'Do NOT claim completion of steps from compacted_memory or prior session summaries '+ 'unless you explicitly verified them yourself. '+ 'If uncertain whether a prior step completed, say so explicitly.'+ )+ )success: bool = Field(default=True, description='True if user_request completed successfully')files_to_display: list[str] | None = Field(default=[])