Skip to content

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

eval-repeat-judge

Magnus Müller0612eb0aae9a
diff --git a/.github/workflows/eval.yaml b/.github/workflows/eval.yaml
index 8c769921e..f3024d662 100644
--- a/.github/workflows/eval.yaml
+++ b/.github/workflows/eval.yaml
@@ -209,6 +209,7 @@ jobs:
DEFAULT_MEMORY_INTERVAL="10"
DEFAULT_MAX_ACTIONS_PER_STEP="10"
DEFAULT_PLANNER_INTERVAL="1"
+ DEFAULT_JUDGE_REPEAT_COUNT="1"
DEFAULT_TEST_CASE="OnlineMind2Web"
# Extract and apply defaults using parameter expansion
@@ -248,6 +249,9 @@ jobs:
PLANNER_INTERVAL="${{ github.event.client_payload.script_args.planner_interval }}"
PLANNER_INTERVAL="${PLANNER_INTERVAL:-$DEFAULT_PLANNER_INTERVAL}"
+ JUDGE_REPEAT_COUNT="${{ github.event.client_payload.script_args.judge_repeat_count }}"
+ JUDGE_REPEAT_COUNT="${JUDGE_REPEAT_COUNT:-$DEFAULT_JUDGE_REPEAT_COUNT}"
+
TEST_CASE="${{ github.event.client_payload.script_args.test_case }}"
TEST_CASE="${TEST_CASE:-$DEFAULT_TEST_CASE}"
@@ -280,6 +284,7 @@ jobs:
"--memory-interval" "$MEMORY_INTERVAL"
"--max-actions-per-step" "$MAX_ACTIONS_PER_STEP"
"--planner-interval" "$PLANNER_INTERVAL"
+ "--judge-repeat-count" "$JUDGE_REPEAT_COUNT"
"--test-case" "$TEST_CASE"
)
diff --git a/eval/comprehensive_judge.py b/eval/comprehensive_judge.py
index 3072b0723..c854947b6 100644
--- a/eval/comprehensive_judge.py
+++ b/eval/comprehensive_judge.py
@@ -521,6 +521,90 @@ async def judge_with_retry(
return create_fallback_result(task, 'Max retries exceeded without proper error handling')
+async def judge_with_repeat_and_average(
+ task: str,
+ complete_history: list[dict],
+ final_result: str,
+ last_message: str,
+ screenshot_paths: list[str],
+ model: BaseChatModel,
+ judge_repeat_count: int = 1,
+ max_retries: int = 3,
+ max_images: int = 10,
+) -> JudgeResult:
+ """
+ Run the judge multiple times and average the results.
+
+ Args:
+ task: The original task description
+ complete_history: Full execution history with steps and results
+ final_result: The final result returned to the user
+ last_message: The agent's final message/output before completion
+ screenshot_paths: List of screenshot file paths from execution
+ model: The LLM model to use for evaluation
+ judge_repeat_count: Number of times to repeat the judge evaluation (averages over multiple judgments)
+ max_retries: Maximum number of retry attempts per judge run
+ max_images: Maximum number of images to include in evaluation
+
+ Returns:
+ JudgeResult with averaged scores and merged feedback
+ """
+ if judge_repeat_count <= 1:
+ # Single evaluation - use existing logic
+ return await judge_with_retry(
+ task, complete_history, final_result, last_message, screenshot_paths, model, max_retries, max_images
+ )
+
+ logger.info(f'Running {judge_repeat_count} judge evaluations for averaging')
+
+ evaluations: list[JudgeResult] = []
+ for i in range(judge_repeat_count):
+ logger.info(f'Running judge evaluation {i + 1}/{judge_repeat_count}')
+
+ try:
+ evaluation = await judge_with_retry(
+ task, complete_history, final_result, last_message, screenshot_paths, model, max_retries, max_images
+ )
+ evaluations.append(evaluation)
+ except Exception as e:
+ logger.warning(f'Judge evaluation {i + 1} failed: {e}')
+ continue
+
+ if not evaluations or len(evaluations) == 0:
+ return create_fallback_result(task, 'All judge evaluations failed')
+
+ logger.info(f'Averaging {len(evaluations)} successful evaluations')
+
+ # Calculate averaged score
+ avg_score = sum(eval.final_score for eval in evaluations) / len(evaluations)
+
+ # Merge error categories (keep unique)
+ all_error_categories = []
+ for eval in evaluations:
+ all_error_categories.extend(eval.error_categories)
+ unique_error_categories = list(set(all_error_categories)) # Remove duplicates
+
+ # Merge improvement tips (keep unique)
+ all_improvement_tips = []
+ for eval in evaluations:
+ all_improvement_tips.extend(eval.improvement_tips)
+ unique_improvement_tips = list(set(all_improvement_tips)) # Remove duplicates
+
+ # concat reasoning with 1. and 2....
+ reasoning = ''
+ for eval in evaluations:
+ reasoning += f'Reasoning judge {i + 1}: {eval.reasoning}\n'
+
+ # Create averaged result
+ return JudgeResult(
+ task_summary=evaluations[0].task_summary,
+ reasoning=reasoning,
+ error_categories=unique_error_categories,
+ final_score=int(avg_score),
+ improvement_tips=unique_improvement_tips,
+ )
+
+
def _read_result_file(result_file: Path) -> dict[str, Any]:
"""Helper function to read result file synchronously."""
with open(result_file) as f:
@@ -534,12 +618,20 @@ def _write_result_file(result_file: Path, result_data: dict[str, Any]) -> None:
# Integration helper function
-async def evaluate_task_with_comprehensive_judge(task_folder: Path, model: BaseChatModel, max_images: int = 10) -> dict[str, Any]:
+async def evaluate_task_with_comprehensive_judge(
+ task_folder: Path, model: BaseChatModel, max_images: int = 10, judge_repeat_count: int = 1
+) -> 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.
+ Args:
+ task_folder: Path to the task result folder
+ model: The LLM model to use for evaluation
+ max_images: Maximum number of images to include in evaluation
+ judge_repeat_count: Number of times to repeat the judge evaluation (averages over multiple judgments)
+
+ Returns:
+ Dictionary with both the old format for compatibility and the new comprehensive analysis.
"""
result_file = task_folder / 'result.json'
if not result_file.exists():
@@ -568,14 +660,15 @@ async def evaluate_task_with_comprehensive_judge(task_folder: Path, model: BaseC
last_message = result_data.get('last_message', '')
screenshot_paths = result_data.get('screenshot_paths', [])
- # Run comprehensive evaluation
- judge_result = await judge_with_retry(
+ # Run comprehensive evaluation with repeat and averaging
+ judge_result = await judge_with_repeat_and_average(
task=task,
complete_history=complete_history,
final_result=final_result,
last_message=last_message,
screenshot_paths=screenshot_paths,
model=model,
+ judge_repeat_count=judge_repeat_count,
max_images=max_images,
)
diff --git a/eval/service.py b/eval/service.py
index b3fb8e9e4..ec0b648ae 100644
--- a/eval/service.py
+++ b/eval/service.py
@@ -344,7 +344,9 @@ async def reformat_agent_history(
# ================================================
-async def judge_task_result(model, task_folder: Path, score_threshold: float = 3, use_mind2web: bool = False) -> dict:
+async def judge_task_result(
+ model, task_folder: Path, score_threshold: float = 3, use_mind2web: bool = False, judge_repeat_count: int = 1
+) -> dict:
"""
Judge a single task result using the comprehensive judge system by default,
with optional fallback to the original Online_Mind2Web evaluation.
@@ -354,6 +356,7 @@ async def judge_task_result(model, task_folder: Path, score_threshold: float = 3
task_folder: Path to the task result folder
score_threshold: Score threshold for image filtering (used only for Mind2Web)
use_mind2web: If True, use the original Online_Mind2Web evaluation instead
+ judge_repeat_count: Number of times to repeat the judge evaluation (averages over multiple judgments)
Returns:
Dictionary containing judgment results
@@ -436,7 +439,7 @@ async def judge_task_result(model, task_folder: Path, score_threshold: float = 3
else:
# Use the new comprehensive judge system (default)
- logger.info(f'Task {task_folder.name}: Using comprehensive judge evaluation')
+ logger.info(f'Task {task_folder.name}: Using comprehensive judge evaluation with {judge_repeat_count} repetition(s)')
# Check if comprehensive judge result already exists
if result.get('comprehensive_judge_evaluation'):
@@ -451,10 +454,12 @@ async def judge_task_result(model, task_folder: Path, score_threshold: float = 3
}
try:
- # Run comprehensive judge evaluation
+ # Run comprehensive judge evaluation (with repeat and averaging handled in comprehensive_judge.py)
comprehensive_result = await asyncio.wait_for(
- evaluate_task_with_comprehensive_judge(task_folder=task_folder, model=model, max_images=10),
- timeout=180, # 3 minutes max for evaluation
+ evaluate_task_with_comprehensive_judge(
+ task_folder=task_folder, model=model, max_images=10, judge_repeat_count=judge_repeat_count
+ ),
+ timeout=180 * judge_repeat_count, # Increase timeout based on repeat count
)
if comprehensive_result.get('error'):
@@ -594,7 +599,11 @@ async def run_agent_with_browser(
@observe(name='evaluate_task_result', span_type='EVALUATOR') # type: ignore[arg-type]
async def evaluate_task_result(
- eval_model: BaseChatModel, task_folder: Path, task: Task | None = None, use_mind2web: bool = False
+ eval_model: BaseChatModel,
+ task_folder: Path,
+ task: Task | None = None,
+ use_mind2web: bool = False,
+ judge_repeat_count: int = 1,
) -> dict:
"""Evaluate the task result"""
# Check if this is a login task that should use both cookie-based and judge evaluation
@@ -602,7 +611,9 @@ async def evaluate_task_result(
logger.info(f'Using combined cookie-based and judge evaluation for login task {task.task_id}')
# First run the judge evaluation to get comprehensive feedback
- judge_result = await judge_task_result(eval_model, task_folder, score_threshold=3, use_mind2web=use_mind2web)
+ judge_result = await judge_task_result(
+ eval_model, task_folder, score_threshold=3, use_mind2web=use_mind2web, judge_repeat_count=judge_repeat_count
+ )
# Then run the cookie-based evaluation to get the actual score
cookie_result = await evaluate_task_with_login_cookie(task.login_cookie, task_folder)
@@ -620,7 +631,9 @@ async def evaluate_task_result(
return judge_result
else:
- return await judge_task_result(eval_model, task_folder, score_threshold=3, use_mind2web=use_mind2web)
+ return await judge_task_result(
+ eval_model, task_folder, score_threshold=3, use_mind2web=use_mind2web, judge_repeat_count=judge_repeat_count
+ )
async def cleanup_browser_safe(browser_session: BrowserSession):
@@ -697,6 +710,7 @@ async def run_task_with_semaphore(
use_mind2web_judge: bool = False,
use_thinking: bool = True,
gmail_tokens_dict: dict[str, str] | None = None,
+ judge_repeat_count: int = 1,
) -> dict:
"""Clean pipeline approach for running tasks"""
task_start_time = time.time()
@@ -928,8 +942,8 @@ async def run_task_with_semaphore(
logger.info(f'Task {task.task_id}: Evaluation starting.')
evaluation = await run_stage(
Stage.EVALUATE,
- lambda: evaluate_task_result(eval_model, task_folder, task, use_mind2web_judge),
- timeout=300,
+ lambda: evaluate_task_result(eval_model, task_folder, task, use_mind2web_judge, judge_repeat_count),
+ timeout=300 * judge_repeat_count, # Increase timeout based on repeat count
)
task_result.stage_completed(Stage.EVALUATE, evaluation)
logger.info(f'Task {task.task_id}: Evaluation completed.')
@@ -1135,6 +1149,7 @@ async def run_multiple_tasks(
use_mind2web_judge: bool = False,
use_thinking: bool = True,
gmail_tokens_dict: dict[str, str] | None = None,
+ judge_repeat_count: int = 1,
) -> dict:
"""
Run multiple tasks in parallel and evaluate results.
@@ -1217,6 +1232,7 @@ async def run_multiple_tasks(
use_mind2web_judge=use_mind2web_judge,
use_thinking=use_thinking,
gmail_tokens_dict=gmail_tokens_dict,
+ judge_repeat_count=judge_repeat_count,
)
for task in tasks_to_run
),
@@ -1313,6 +1329,7 @@ async def run_evaluation_pipeline(
use_mind2web_judge: bool = False,
use_thinking: bool = True,
gmail_tokens_dict: dict[str, str] | None = None,
+ judge_repeat_count: int = 1,
) -> dict:
"""
Complete evaluation pipeline that handles Laminar setup and task execution in the same event loop
@@ -1368,6 +1385,7 @@ async def run_evaluation_pipeline(
use_mind2web_judge=use_mind2web_judge,
use_thinking=use_thinking,
gmail_tokens_dict=gmail_tokens_dict,
+ judge_repeat_count=judge_repeat_count,
)
@@ -1414,6 +1432,12 @@ if __name__ == '__main__':
help='Model to use for planning (separate from main agent model)',
)
parser.add_argument('--planner-interval', type=int, default=1, help='Run planner every N steps (default: 1)')
+ parser.add_argument(
+ '--judge-repeat-count',
+ type=int,
+ default=1,
+ help='Number of times to repeat the judge evaluation for each task (averages over multiple judgments)',
+ )
parser.add_argument(
'--test-case', type=str, default='OnlineMind2Web', help='Name of the test case to fetch (default: OnlineMind2Web)'
)
@@ -1625,6 +1649,7 @@ if __name__ == '__main__':
'planner_model': args.planner_model,
'planner_interval': args.planner_interval,
'include_result': args.include_result,
+ 'judge_repeat_count': args.judge_repeat_count,
}
run_data = {
@@ -1811,6 +1836,7 @@ if __name__ == '__main__':
use_mind2web_judge=args.use_mind2web_judge,
use_thinking=not args.no_thinking,
gmail_tokens_dict=gmail_tokens_dict,
+ judge_repeat_count=args.judge_repeat_count,
)
)