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 title problem in schema as well as enum problems
mertunsalled7cfa4ab2e7
diff --git a/browser_use/agent/views.py b/browser_use/agent/views.pyindex 7871f1807..06f1a5e79 100644--- a/browser_use/agent/views.py+++ b/browser_use/agent/views.py@@ -364,7 +364,7 @@ class AgentHistory(BaseModel):# Handle action serializationmodel_output_dump = Noneif self.model_output:- action_dump = [action.model_dump(exclude_none=True) for action in self.model_output.action]+ action_dump = [action.model_dump(exclude_none=True, mode='json') for action in self.model_output.action]# Filter sensitive data only from input action parameters if sensitive_data is providedif sensitive_data:@@ -385,7 +385,7 @@ class AgentHistory(BaseModel):# Handle result serialization - don't filter ActionResult data# as it should contain meaningful information for the agent- result_dump = [r.model_dump(exclude_none=True) for r in self.result]+ result_dump = [r.model_dump(exclude_none=True, mode='json') for r in self.result]return {'model_output': model_output_dump,@@ -504,7 +504,7 @@ class AgentHistoryList(BaseModel, Generic[AgentStructuredOutput]):def last_action(self) -> None | dict:"""Last action in history"""if self.history and self.history[-1].model_output:- return self.history[-1].model_output.action[-1].model_dump(exclude_none=True)+ return self.history[-1].model_output.action[-1].model_dump(exclude_none=True, mode='json')return Nonedef errors(self) -> list[str | None]:@@ -630,7 +630,7 @@ class AgentHistoryList(BaseModel, Generic[AgentStructuredOutput]):# Guard against None interacted_element before zippinginteracted_elements = h.state.interacted_element or [None] * len(h.model_output.action)for action, interacted_element in zip(h.model_output.action, interacted_elements):- output = action.model_dump(exclude_none=True)+ output = action.model_dump(exclude_none=True, mode='json')output['interacted_element'] = interacted_elementoutputs.append(output)return outputs@@ -646,7 +646,7 @@ class AgentHistoryList(BaseModel, Generic[AgentStructuredOutput]):interacted_elements = h.state.interacted_element or [None] * len(h.model_output.action)# Zip actions with interacted elements and resultsfor action, interacted_element, result in zip(h.model_output.action, interacted_elements, h.result):- action_output = action.model_dump(exclude_none=True)+ action_output = action.model_dump(exclude_none=True, mode='json')action_output['interacted_element'] = interacted_element# Only keep long_term_memory from resultaction_output['result'] = result.long_term_memory if result and result.long_term_memory else None@@ -695,8 +695,8 @@ class AgentHistoryList(BaseModel, Generic[AgentStructuredOutput]):# Get actions from model_outputif h.model_output and h.model_output.action:- # Use existing model_dump to get action dicts- actions_list = [action.model_dump(exclude_none=True) for action in h.model_output.action]+ # Use model_dump with mode='json' to serialize enums properly+ actions_list = [action.model_dump(exclude_none=True, mode='json') for action in h.model_output.action]action_json = json.dumps(actions_list, indent=1)step_text += f'Actions: {action_json}\n'diff --git a/browser_use/llm/google/chat.py b/browser_use/llm/google/chat.pyindex 16055191b..9d2495944 100644--- a/browser_use/llm/google/chat.py+++ b/browser_use/llm/google/chat.py@@ -500,13 +500,16 @@ class ChatGoogle(BaseChatModel):schema = resolve_refs(schema)# Remove unsupported properties- def clean_schema(obj: Any) -> Any:+ def clean_schema(obj: Any, parent_key: str | None = None) -> Any:if isinstance(obj, dict):# Remove unsupported propertiescleaned = {}for key, value in obj.items():- if key not in ['additionalProperties', 'title', 'default']:- cleaned_value = clean_schema(value)+ # Only strip 'title' when it's a JSON Schema metadata field (not inside 'properties')+ # 'title' as a metadata field appears at schema level, not as a property name+ is_metadata_title = key == 'title' and parent_key != 'properties'+ if key not in ['additionalProperties', 'default'] and not is_metadata_title:+ cleaned_value = clean_schema(value, parent_key=key)# Handle empty object properties - Gemini doesn't allow empty OBJECT typesif (key == 'properties'@@ -530,13 +533,9 @@ class ChatGoogle(BaseChatModel):):cleaned['properties'] = {'_placeholder': {'type': 'string'}}- # Also remove 'title' from the required list if it exists- if 'required' in cleaned and isinstance(cleaned.get('required'), list):- cleaned['required'] = [p for p in cleaned['required'] if p != 'title']-return cleanedelif isinstance(obj, list):- return [clean_schema(item) for item in obj]+ return [clean_schema(item, parent_key=parent_key) for item in obj]return objreturn clean_schema(schema)