Skip to content

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

fix title problem in schema as well as enum problems

mertunsalled7cfa4ab2e7
diff --git a/browser_use/agent/views.py b/browser_use/agent/views.py
index 7871f1807..06f1a5e79 100644
--- a/browser_use/agent/views.py
+++ b/browser_use/agent/views.py
@@ -364,7 +364,7 @@ class AgentHistory(BaseModel):
# Handle action serialization
model_output_dump = None
if 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 provided
if 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 None
def errors(self) -> list[str | None]:
@@ -630,7 +630,7 @@ class AgentHistoryList(BaseModel, Generic[AgentStructuredOutput]):
# Guard against None interacted_element before zipping
interacted_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_element
outputs.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 results
for 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 result
action_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_output
if 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.py
index 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 properties
cleaned = {}
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 types
if (
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 cleaned
elif isinstance(obj, list):
- return [clean_schema(item) for item in obj]
+ return [clean_schema(item, parent_key=parent_key) for item in obj]
return obj
return clean_schema(schema)