Skip to content

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

Add impossible_task and reached_captcha to JudgementResult

Cursor Agentcb814da33ec1
diff --git a/browser_use/agent/judge.py b/browser_use/agent/judge.py
index a58eefc27..a6220f0f2 100644
--- a/browser_use/agent/judge.py
+++ b/browser_use/agent/judge.py
@@ -122,6 +122,28 @@ def construct_judge_messages(
- The agent made up content that is not in the screenshot or the page state
- The agent calls done action before completing all key points of the task
+**IMPOSSIBLE TASK DETECTION:**
+Set `impossible_task` to true when the task fundamentally could not be completed due to:
+- Vague or ambiguous task instructions that cannot be reasonably interpreted
+- Website genuinely broken or non-functional (be conservative - temporary issues don't count)
+- Required links/pages truly inaccessible (404, 403, etc.)
+- Task requires authentication/login but no credentials were provided
+- Task asks for functionality that doesn't exist on the target site
+- Other insurmountable external obstacles beyond the agent's control
+
+Do NOT mark as impossible if:
+- Agent made poor decisions but task was achievable
+- Temporary page loading issues that could be retried
+- Agent didn't try the right approach
+- Website works but agent struggled with it
+
+**CAPTCHA DETECTION:**
+Set `reached_captcha` to true if:
+- Screenshots show captcha challenges (reCAPTCHA, hCaptcha, etc.)
+- Agent reports being blocked by bot detection
+- Error messages indicate captcha/verification requirements
+- Any evidence the agent encountered anti-bot measures during execution
+
**IMPORTANT EVALUATION NOTES:**
- **evaluate for action** - For each key step of the trace, double check whether the action that the agent tried to performed actually happened. If the required action did not actually occur, the verdict should be false.
- **screenshot is not entire content** - The agent has the entire DOM content, but the screenshot is only part of the content. If the agent extracts information from the page, but you do not see it in the screenshot, you can assume this information is there.
@@ -138,7 +160,9 @@ Respond with EXACTLY this JSON structure (no additional text before or after):
{{
"reasoning": "Breakdown of user task into key points. Detailed analysis covering: what went well, what didn't work, trajectory quality assessment, tool usage evaluation, output quality review, and overall user satisfaction prediction",
"verdict": true or false,
- "failure_reason": "If verdict is false, provide the key reason why the task was not completed successfully. If verdict is true, use an empty string."
+ "failure_reason": "If verdict is false, provide the key reason why the task was not completed successfully. If verdict is true, use an empty string.",
+ "impossible_task": true or false,
+ "reached_captcha": true or false
}}
</response_format>
"""
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index 5bde05406..112da3849 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -974,6 +974,10 @@ class Agent(Generic[Context, AgentStructuredOutput]):
judge_log += f'⚖️ {verdict_color}Judge Verdict: {verdict_text}\033[0m\n'
if judgement.failure_reason:
judge_log += f' Failure: {judgement.failure_reason}\n'
+ if judgement.impossible_task:
+ judge_log += ' 🚫 Impossible Task: Task was fundamentally impossible to complete\n'
+ if judgement.reached_captcha:
+ judge_log += ' 🤖 Captcha Detected: Agent encountered captcha challenges\n'
judge_log += f' {judgement.reasoning}\n'
self.logger.info(judge_log)
diff --git a/browser_use/agent/views.py b/browser_use/agent/views.py
index 0d2744d6f..470f92340 100644
--- a/browser_use/agent/views.py
+++ b/browser_use/agent/views.py
@@ -94,6 +94,14 @@ class JudgementResult(BaseModel):
reasoning: str | None = Field(default=None, description='Explanation of the judgement')
verdict: bool = Field(description='Whether the trace was successful or not')
failure_reason: str | None = Field(default=None, description='If the trace was not successful, the reason why')
+ impossible_task: bool = Field(
+ default=False,
+ description='True if the task was impossible to complete due to vague instructions, broken website, inaccessible links, missing login credentials, or other insurmountable obstacles',
+ )
+ reached_captcha: bool = Field(
+ default=False,
+ description='True if the agent encountered captcha challenges during task execution',
+ )
class ActionResult(BaseModel):
diff --git a/tests/ci/test_judge.py b/tests/ci/test_judge.py
new file mode 100644
index 000000000..6e209b240
--- /dev/null
+++ b/tests/ci/test_judge.py
@@ -0,0 +1,118 @@
+"""Tests for judge functionality."""
+
+import json
+
+import pytest
+
+from browser_use.agent.judge import construct_judge_messages
+from browser_use.agent.views import JudgementResult
+
+
+def test_judgement_result_schema():
+ """Test that JudgementResult has all required fields."""
+ # Test with all fields
+ result = JudgementResult(
+ reasoning='Task completed successfully',
+ verdict=True,
+ failure_reason='',
+ impossible_task=False,
+ reached_captcha=False,
+ )
+
+ assert result.reasoning == 'Task completed successfully'
+ assert result.verdict is True
+ assert result.failure_reason == ''
+ assert result.impossible_task is False
+ assert result.reached_captcha is False
+
+ # Test with defaults
+ result_defaults = JudgementResult(
+ verdict=False,
+ failure_reason='Task failed due to missing login credentials',
+ )
+
+ assert result_defaults.verdict is False
+ assert result_defaults.failure_reason == 'Task failed due to missing login credentials'
+ assert result_defaults.impossible_task is False # Default
+ assert result_defaults.reached_captcha is False # Default
+
+ # Test serialization includes new fields
+ data = result.model_dump()
+ assert 'impossible_task' in data
+ assert 'reached_captcha' in data
+
+
+def test_judgement_result_impossible_task():
+ """Test impossible_task field scenarios."""
+ # Impossible task due to missing credentials
+ result_impossible = JudgementResult(
+ reasoning='Task requires login but no credentials were provided',
+ verdict=False,
+ failure_reason='Missing login credentials',
+ impossible_task=True,
+ reached_captcha=False,
+ )
+
+ assert result_impossible.impossible_task is True
+ assert result_impossible.verdict is False
+
+ # Achievable task that just failed
+ result_achievable = JudgementResult(
+ reasoning='Agent made poor navigation choices',
+ verdict=False,
+ failure_reason='Navigation error',
+ impossible_task=False,
+ reached_captcha=False,
+ )
+
+ assert result_achievable.impossible_task is False
+
+
+def test_judgement_result_reached_captcha():
+ """Test reached_captcha field scenarios."""
+ # Task blocked by captcha
+ result_captcha = JudgementResult(
+ reasoning='Agent was blocked by reCAPTCHA on the login page',
+ verdict=False,
+ failure_reason='Blocked by captcha',
+ impossible_task=True,
+ reached_captcha=True,
+ )
+
+ assert result_captcha.reached_captcha is True
+ assert result_captcha.verdict is False
+
+ # Task without captcha
+ result_no_captcha = JudgementResult(
+ reasoning='Task completed without any anti-bot measures',
+ verdict=True,
+ failure_reason='',
+ impossible_task=False,
+ reached_captcha=False,
+ )
+
+ assert result_no_captcha.reached_captcha is False
+
+
+def test_judge_prompt_includes_new_fields():
+ """Test that the judge system prompt includes instructions for new fields."""
+ messages = construct_judge_messages(
+ task='Test task',
+ final_result='Test result',
+ agent_steps=['Step 1: Navigate', 'Step 2: Click'],
+ screenshot_paths=[],
+ max_images=10,
+ )
+
+ # Get system prompt
+ system_prompt = messages[0].content
+
+ # Check that the prompt mentions the new fields
+ assert 'impossible_task' in system_prompt
+ assert 'reached_captcha' in system_prompt
+ assert 'IMPOSSIBLE TASK DETECTION' in system_prompt
+ assert 'CAPTCHA DETECTION' in system_prompt
+
+ # Check that response format includes the new fields
+ assert '"impossible_task": true or false' in system_prompt
+ assert '"reached_captcha": true or false' in system_prompt