Skip to content

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

Fixes relative import and type hints

Magnus Müller4629a8d9b77c
diff --git a/eval/judge_system.py b/eval/judge_system.py
index 357b42373..1eca34fec 100644
--- a/eval/judge_system.py
+++ b/eval/judge_system.py
@@ -19,10 +19,11 @@ import base64
import io
import json
import logging
-from dataclasses import dataclass
+from dataclasses import asdict, dataclass
from datetime import datetime
from enum import Enum
from pathlib import Path
+from typing import Any
from langchain_core.language_models.chat_models import BaseChatModel
from PIL import Image
@@ -468,4 +469,79 @@ def get_example_json_structure() -> dict:
}
+def _read_result_file(result_file: Path) -> dict[str, Any]:
+ """Helper function to read result file synchronously."""
+ with open(result_file) as f:
+ return json.load(f)
+
+
+def _write_result_file(result_file: Path, result_data: dict[str, Any]) -> None:
+ """Helper function to write result file synchronously."""
+ with open(result_file, 'w') as f:
+ f.write(json.dumps(result_data, indent=2, default=str))
+
+
# Integration helper function
+async def evaluate_task_with_comprehensive_judge(task_folder: Path, model: BaseChatModel, max_images: int = 10) -> dict[str, Any]:
+ """
+ Evaluate a task result using the comprehensive judge system.
+
+ Returns a dictionary with both the old format for compatibility
+ and the new comprehensive analysis.
+ """
+ result_file = task_folder / 'result.json'
+ if not result_file.exists():
+ return {
+ 'task_id': task_folder.name,
+ 'comprehensive_judge': None,
+ 'error': 'No result.json found',
+ }
+
+ try:
+ # Load existing result using async wrapper
+ result_data = await asyncio.to_thread(_read_result_file, result_file)
+
+ # Check if comprehensive judge result already exists
+ if result_data.get('comprehensive_judge_evaluation'):
+ return {
+ 'task_id': task_folder.name,
+ 'comprehensive_judge': result_data['comprehensive_judge_evaluation'],
+ 'error': None,
+ }
+
+ # Extract data for evaluation
+ task = result_data.get('task', 'Unknown task')
+ complete_history = result_data.get('complete_history', [])
+ final_result = result_data.get('final_result_response', '')
+ screenshot_paths = result_data.get('screenshot_paths', [])
+
+ # Run comprehensive evaluation
+ judge_result = await judge_with_retry(
+ task=task,
+ complete_history=complete_history,
+ final_result=final_result,
+ screenshot_paths=screenshot_paths,
+ model=model,
+ max_images=max_images,
+ )
+
+ # Convert to dict for storage
+ judge_dict = asdict(judge_result)
+
+ # Save back to result file using async wrapper
+ result_data['comprehensive_judge_evaluation'] = judge_dict
+ await asyncio.to_thread(_write_result_file, result_file, result_data)
+
+ return {
+ 'task_id': task_folder.name,
+ 'comprehensive_judge': judge_dict,
+ 'error': None,
+ }
+
+ except Exception as e:
+ logger.error(f'Comprehensive judge evaluation failed for {task_folder.name}: {e}')
+ return {
+ 'task_id': task_folder.name,
+ 'comprehensive_judge': None,
+ 'error': str(e),
+ }
diff --git a/eval/service.py b/eval/service.py
index 58d1c0cd7..62d2af5bf 100644
--- a/eval/service.py
+++ b/eval/service.py
@@ -494,7 +494,7 @@ import requests
from dotenv import load_dotenv
# Import the new comprehensive judge system
-from judge_system import evaluate_task_with_comprehensive_judge
+from .judge_system import evaluate_task_with_comprehensive_judge
class Stage(Enum):
@@ -520,12 +520,12 @@ class TaskResult:
confirmed_task: str
task: Any
max_steps: int
- laminar_link: str = None
+ laminar_link: str | None = None
completed_stages: set[Stage] = field(default_factory=set)
stage_data: dict[Stage, Any] = field(default_factory=dict)
errors: list = field(default_factory=list)
cancelled: bool = False
- critical_error: str = None
+ critical_error: str | None = None
server_save_failed: bool = False
def stage_completed(self, stage: Stage, data: Any = None):
@@ -2086,7 +2086,7 @@ async def run_evaluation_pipeline(
# -------------------------
# Update run data with Laminar link
- run_data_update = {'laminarEvalLink': laminar_eval_link}
+ # run_data_update = {'laminarEvalLink': laminar_eval_link}
# TODO: Update the run data on the server with the Laminar link if needed
# Run the tasks