Skip to content

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

Restructure

magmueller433723ef76de
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index c7b89c434..9b6503716 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -352,26 +352,22 @@ class Agent:
converted_input_messages = self.message_manager.convert_messages_for_non_function_calling_models(input_messages)
merged_input_messages = self.message_manager.merge_successive_human_messages(converted_input_messages)
output = self.llm.invoke(merged_input_messages)
- # TODO: currently invoke does not return reasoning_content, we should override it
- # print(f'reasoning_content: {output.reasoning_content}')
- print(f'content: {output.content}')
+ # TODO: currently invoke does not return reasoning_content, we should override invoke
try:
parsed_json = self.message_manager.extract_json_from_model_output(output.content)
parsed = self.AgentOutput(**parsed_json)
except (ValueError, ValidationError) as e:
logger.warning(f'Failed to parse model output: {str(e)}')
raise ValueError('Could not parse response.')
+ elif self.tool_calling_method is None:
+ structured_llm = self.llm.with_structured_output(self.AgentOutput, include_raw=True)
+ response: dict[str, Any] = await structured_llm.ainvoke(input_messages) # type: ignore
+ parsed: AgentOutput | None = response['parsed']
else:
- if self.tool_calling_method is None:
- structured_llm = self.llm.with_structured_output(self.AgentOutput, include_raw=True)
- else:
- structured_llm = self.llm.with_structured_output(
- self.AgentOutput, include_raw=True, method=self.tool_calling_method
- )
-
+ structured_llm = self.llm.with_structured_output(self.AgentOutput, include_raw=True, method=self.tool_calling_method)
response: dict[str, Any] = await structured_llm.ainvoke(input_messages) # type: ignore
-
parsed: AgentOutput | None = response['parsed']
+
if parsed is None:
raise ValueError('Could not parse response.')