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
Seperate results which stay in context and which not to avoid max token limit
magmuellere4ed94914134
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex 7bc4c9745..9bd8912d0 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -156,14 +156,15 @@ class Agent:logger.error(f'{prefix}{error_msg}')self.consecutive_failures += 1- return ActionResult(error=error_msg)+ return ActionResult(error=error_msg, include_in_memory=True)def _update_messages_with_result(self, result: ActionResult) -> None:"""Update message history with action results"""- if result.extracted_content:- self.messages.append(HumanMessage(content=result.extracted_content))- if result.error:- self.messages.append(HumanMessage(content=result.error))+ if result.include_in_memory:+ if result.extracted_content:+ self.messages.append(HumanMessage(content=result.extracted_content))+ if result.error:+ self.messages.append(HumanMessage(content=result.error))def _make_history_item(self,diff --git a/browser_use/agent/views.py b/browser_use/agent/views.pyindex 7dc49ead1..2b33357fb 100644--- a/browser_use/agent/views.py+++ b/browser_use/agent/views.py@@ -48,6 +48,7 @@ class ActionResult(BaseModel):is_done: Optional[bool] = Falseextracted_content: Optional[str] = Noneerror: Optional[str] = None+ include_in_memory: bool = False # whether to include in past messages as context or notclass AgentBrain(BaseModel):diff --git a/browser_use/controller/service.py b/browser_use/controller/service.pyindex 3c8461bf0..fabeabbdc 100644--- a/browser_use/controller/service.py+++ b/browser_use/controller/service.py@@ -86,7 +86,7 @@ class Controller:if len(driver.window_handles) > initial_handles:browser.handle_new_tab()- return ActionResult(extracted_content=f'Clicked element {msg}')+ return ActionResult(extracted_content=f'{msg}')@self.registry.action('Input text', param_model=InputTextAction, requires_browser=True)def input_text(params: InputTextAction, browser: Browser):