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
Changes from background composer bc-4b95c2c0-b3db-46d7-82ec-5bb4d84dd5b1
Cursor Agentad2614fb60cd
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex 32ef95d5b..7116caf1d 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -915,9 +915,7 @@ class Agent(Generic[Context]):async def get_next_action(self, input_messages: list[BaseMessage]) -> AgentOutput:"""Get next action from LLM based on current state"""- # Determine output format based on whether we have a structured output schema- output_format = self.AgentOutput- response = await self.llm.ainvoke(input_messages, output_format=output_format)+ response = await self.llm.ainvoke(input_messages, output_format=self.AgentOutput)parsed = response.completion# cut the number of actions to max_actions_per_step if neededdiff --git a/eval/judge_system.py b/eval/judge_system.pyindex a15946903..ad6eb06ec 100644--- a/eval/judge_system.py+++ b/eval/judge_system.py@@ -287,8 +287,6 @@ async def comprehensive_judge(# Build error categories dynamically from enumerror_categories_text = ', '.join([category.value for category in ErrorCategory])--# Construct the evaluation promptsystem_prompt = f"""You are an expert judge evaluating browser-use agent performance.@@ -656,8 +654,6 @@ async def evaluate_task_with_comprehensive_judge(task_folder: Path, model: BaseCfinal_result = result_data.get('final_result_response', '')last_message = result_data.get('last_message', '')screenshot_paths = result_data.get('screenshot_paths', [])--# Run comprehensive evaluationjudge_result = await judge_with_retry(diff --git a/structured_output_implementation_analysis.md b/structured_output_implementation_analysis.mddeleted file mode 100644index c23951bc9..000000000--- a/structured_output_implementation_analysis.md+++ /dev/null@@ -1,123 +0,0 @@-# Structured Output Implementation Analysis--## Overview--The structured output functionality in the browser-use evaluation system has been correctly implemented to work with the Controller. The system converts JSON schemas from task datasets into Pydantic models using `datamodel-code-generator` and passes them to the Controller's `output_model` parameter. The Controller then creates a custom `done` action that enforces the structured output format.--## Correct Implementation Flow--### 1. Task Class Enhancement (`eval/service.py`)--✅ **Status: Correctly Implemented**--- Added `output_schema` as an optional field in the Task class-- Creates Pydantic model using `create_pydantic_model_from_schema()` function-- Stores both the original schema and the generated Pydantic model--```python-self.output_schema = kwargs.get('output_schema', None)-if self.output_schema:- # Convert JSON schema to Pydantic model class- self.output_model = create_pydantic_model_from_schema(- self.output_schema,- f"Task_{self.task_id}_Output"- )-else:- self.output_model = None-```--### 2. Schema Conversion Utility (`eval/service.py`)--✅ **Status: Correctly Implemented with datamodel-code-generator**--- Uses `datamodel-code-generator` library for robust JSON schema to Pydantic conversion-- Handles complex schemas, nested objects, arrays, and validation rules-- Falls back to basic implementation if library is not available-- Added to eval dependencies in `pyproject.toml`--```python-def create_pydantic_model_from_schema(schema: dict, model_name: str = "DynamicModel") -> type[BaseModel]:- """- Convert JSON schema to Pydantic model class using datamodel-code-generator.- """- # Uses datamodel-code-generator for robust conversion- # Falls back to basic create_model if library unavailable-```--### 3. Controller Integration--✅ **Status: Correctly Implemented**--- Controller receives `output_model` parameter in `create_controller()` function-- Controller creates custom structured `done` action when `output_model` is provided-- Both regular and SERP-enabled controllers support `output_model` parameter--```python-controller = create_controller(use_serp=use_serp, output_model=task.output_model)-```--### 4. Judge System--✅ **Status: Correctly Implemented (No Schema Needed)**--- Judge evaluates the final structured response directly-- No need to pass original schema to judge-- Judge validates the structured output as part of task completion assessment--## Technical Implementation Details--### How It Works:--1. **Task Loading**: JSON dataset contains tasks with optional `output_schema` field-2. **Schema Parsing**: Task class loads schema and converts to Pydantic model using `datamodel-code-generator`-3. **Controller Setup**: Agent receives Pydantic model class and passes to Controller constructor-4. **Runtime Behavior**: Controller creates structured `done` action that validates output against the model-5. **Judge Evaluation**: Judge evaluates the final structured response for task completion--### Key Features:--- **Robust Schema Conversion**: Uses `datamodel-code-generator` for comprehensive JSON Schema support-- **Backward Compatibility**: Maintains compatibility with tasks without structured output-- **Proper Type Safety**: Generated Pydantic models provide full type validation-- **Clean Architecture**: Schema handling is separated from agent logic-- **Fallback Support**: Basic implementation available if advanced library is not installed--### Example Usage:--```python-# In JSON dataset-{- "task_id": "extract_product_info",- "confirmed_task": "Extract product name and price from the page",- "output_schema": {- "type": "object",- "properties": {- "product_name": {"type": "string"},- "price": {"type": "number"},- "currency": {"type": "string"}- },- "required": ["product_name", "price"]- }-}--# Generated Pydantic model automatically handles validation-# Controller enforces structured output format via custom done action-# Judge evaluates final structured response-```--## Implementation Status Update--### ✅ Correctly Implemented Components:-- **Task class schema handling**: Properly loads `output_schema` and converts to Pydantic model-- **Schema conversion utility**: Uses `datamodel-code-generator` for robust conversion with fallback-- **Controller integration**: Correctly passes `output_model` to Controller constructor-- **Dependency management**: Added `datamodel-code-generator` to eval dependencies-- **Judge system evaluation**: Correctly evaluates final structured response without needing original schema--### 🎯 Next Steps for Usage:-1. Install eval dependencies: `uv sync --extra eval`-2. Create tasks with `output_schema` field in JSON format-3. Run evaluation - structured output will be automatically enforced-4. Judge will evaluate the structured response for task completion--The implementation is complete and ready for use with structured output tasks.\ No newline at end of file