Skip to content

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

removed self verify injection to agent

Saurav Pandaf1fbdbc1a817
diff --git a/browser_use/agent/judge.py b/browser_use/agent/judge.py
index 52f9361c2..8de0c7407 100644
--- a/browser_use/agent/judge.py
+++ b/browser_use/agent/judge.py
@@ -222,65 +222,3 @@ Evaluate this agent execution given the criteria and respond with the exact JSON
]
-def construct_self_verify_messages(
- task: str,
- final_result: str,
- last_screenshot_path: str | None = None,
- use_vision: bool | Literal['auto'] = True,
-) -> list[BaseMessage]:
- """
- Construct lightweight verification messages to check if the agent's claimed success is justified.
-
- Much lighter than the full judge — just task + final result + optional last screenshot.
- """
- task_truncated = _truncate_text(task, 20000)
- final_result_truncated = _truncate_text(final_result, 20000)
-
- system_prompt = """You are a strict verifier checking whether a browser automation agent actually completed its task.
-
-Your job is simple: given the task and the agent's final response, determine if the response genuinely satisfies ALL requirements of the task.
-
-Check for these common failure patterns:
-1. **Incorrect data**: Wrong number of items, missing filters/criteria, wrong format
-2. **Unverified actions**: Agent claims to have submitted a form, posted a comment, or saved a file but there's no evidence it happened
-3. **Incomplete results**: Some requirements from the task are not addressed in the response
-4. **Fabricated content**: Data that looks plausible but wasn't actually extracted from any page
-
-Respond with EXACTLY this JSON structure:
-{
- "verified": true or false,
- "reason": "Brief explanation if not verified, empty string if verified"
-}
-
-Be strict: if the response doesn't clearly satisfy every requirement, set verified to false."""
-
- user_prompt = f"""<task>
-{task_truncated or 'No task provided'}
-</task>
-
-<agent_final_response>
-{final_result_truncated or 'No response provided'}
-</agent_final_response>
-
-Does the agent's response fully satisfy all requirements of the task? Respond with the JSON structure."""
-
- # Build content parts
- content_parts: list[ContentPartTextParam | ContentPartImageParam] = [ContentPartTextParam(text=user_prompt)]
-
- # Add last screenshot if available and vision is enabled
- if use_vision is not False and last_screenshot_path:
- encoded = _encode_image(last_screenshot_path)
- if encoded:
- content_parts.append(
- ContentPartImageParam(
- image_url=ImageURL(
- url=f'data:image/png;base64,{encoded}',
- media_type='image/png',
- )
- )
- )
-
- return [
- SystemMessage(content=system_prompt),
- UserMessage(content=content_parts),
- ]
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index fd313ef07..f9b8c9c22 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -36,7 +36,7 @@ from pydantic import BaseModel, ValidationError
from uuid_extensions import uuid7str
from browser_use import Browser, BrowserProfile, BrowserSession
-from browser_use.agent.judge import construct_judge_messages, construct_self_verify_messages
+from browser_use.agent.judge import construct_judge_messages
# Lazy import for gif to avoid heavy agent.views import at startup
# from browser_use.agent.gif import create_history_gif
@@ -57,7 +57,6 @@ from browser_use.agent.views import (
BrowserStateHistory,
DetectedVariable,
JudgementResult,
- SelfVerifyResult,
StepMetadata,
)
from browser_use.browser.events import _get_timeout
@@ -179,7 +178,6 @@ class Agent(Generic[Context, AgentStructuredOutput]):
page_extraction_llm: BaseChatModel | None = None,
fallback_llm: BaseChatModel | None = None,
use_judge: bool = True,
- use_self_verification: bool = True,
ground_truth: str | None = None,
judge_llm: BaseChatModel | None = None,
injected_agent_state: AgentState | None = None,
@@ -388,7 +386,6 @@ class Agent(Generic[Context, AgentStructuredOutput]):
step_timeout=step_timeout,
final_response_after_failure=final_response_after_failure,
use_judge=use_judge,
- use_self_verification=use_self_verification,
ground_truth=ground_truth,
)
@@ -1289,54 +1286,6 @@ class Agent(Generic[Context, AgentStructuredOutput]):
self._message_manager._add_context_message(UserMessage(content=msg))
self.AgentOutput = self.DoneAgentOutput
- async def _self_verify_success(self) -> str | None:
- """Lightweight self-verification when agent claims success.
-
- Uses the agent's own LLM to verify that the final response actually satisfies the task.
- Returns None if verification passes, or a reason string if it should be rejected.
- """
- last_result = self.history.history[-1].result[-1]
- if not last_result.success:
- return None # Agent already says failure, no need to verify
-
- task = self.task
- final_result = self.history.final_result() or ''
- screenshot_paths = [p for p in self.history.screenshot_paths() if p is not None]
-
- verify_messages = construct_self_verify_messages(
- task=task,
- final_result=final_result,
- last_screenshot_path=screenshot_paths[-1] if screenshot_paths else None,
- use_vision=self.settings.use_vision,
- )
-
- try:
- response = await self.llm.ainvoke(verify_messages, output_format=SelfVerifyResult)
- result: SelfVerifyResult = response.completion # type: ignore[assignment]
- if not result.verified:
- reason = result.reason or 'Verification found unmet requirements'
- self.logger.info(f'⚠️ Self-verification failed: {reason}')
- return reason
- return None
- except Exception as e:
- self.logger.warning(f'Self-verification failed with error: {e}')
- return None # Don't override on error
-
- def _undo_done_and_inject_retry(self, reason: str, steps_remaining: int) -> None:
- """Undo the done action result and inject a retry message so the agent continues."""
- last_result = self.history.history[-1].result[-1]
- # Clear the done state so the step loop continues
- last_result.is_done = False
- last_result.success = None
-
- self.state.self_verification_retries += 1
-
- msg = (
- f'Your previous done(success=true) was rejected by verification: "{reason}" '
- f'Continue working to address this. You have {steps_remaining} steps remaining.'
- )
- self._message_manager._add_context_message(UserMessage(content=msg))
-
@observe(ignore_input=True, ignore_output=False)
async def _judge_trace(self) -> JudgementResult | None:
"""Judge the trace of the agent"""
@@ -2013,26 +1962,6 @@ class Agent(Generic[Context, AgentStructuredOutput]):
await self.step(step_info)
if self.history.is_done():
- # Self-verify before logging completion
- if self.settings.use_self_verification:
- rejection_reason = await self._self_verify_success()
- if rejection_reason is not None:
- # Check if we can retry: have steps left and haven't exceeded retry cap
- steps_remaining = (step_info.max_steps - step_info.step_number - 1) if step_info else 0
- can_retry = steps_remaining > 0 and self.state.self_verification_retries < 1
- if can_retry:
- self._undo_done_and_inject_retry(rejection_reason, steps_remaining)
- return False, False
- else:
- # No retries left — accept the failure
- last_result = self.history.history[-1].result[-1]
- last_result.success = False
- verification_note = f'\n\n[Self-verification: {rejection_reason}]'
- if last_result.extracted_content:
- last_result.extracted_content += verification_note
- else:
- last_result.extracted_content = verification_note.strip()
-
await self.log_completion()
# Run judge before done callback if enabled
@@ -2234,24 +2163,6 @@ class Agent(Generic[Context, AgentStructuredOutput]):
await on_step_end(self)
if self.history.is_done():
- # Self-verify before logging completion
- if self.settings.use_self_verification:
- rejection_reason = await self._self_verify_success()
- if rejection_reason is not None:
- steps_remaining = max_steps - step - 1
- can_retry = steps_remaining > 0 and self.state.self_verification_retries < 1
- if can_retry:
- self._undo_done_and_inject_retry(rejection_reason, steps_remaining)
- return False
- else:
- last_result = self.history.history[-1].result[-1]
- last_result.success = False
- verification_note = f'\n\n[Self-verification: {rejection_reason}]'
- if last_result.extracted_content:
- last_result.extracted_content += verification_note
- else:
- last_result.extracted_content = verification_note.strip()
-
await self.log_completion()
# Run judge before done callback if enabled
diff --git a/browser_use/agent/views.py b/browser_use/agent/views.py
index 9727dae96..713ed3c37 100644
--- a/browser_use/agent/views.py
+++ b/browser_use/agent/views.py
@@ -46,7 +46,6 @@ class AgentSettings(BaseModel):
flash_mode: bool = False # If enabled, disables evaluation_previous_goal and next_goal, and sets use_thinking = False
use_judge: bool = True
ground_truth: str | None = None # Ground truth answer or criteria for judge validation
- use_self_verification: bool = True # Run lightweight self-check before accepting done(success=True)
max_history_items: int | None = None
page_extraction_llm: BaseChatModel | None = None
@@ -74,7 +73,6 @@ class AgentState(BaseModel):
stopped: bool = False
session_initialized: bool = False # Track if session events have been dispatched
follow_up_task: bool = False # Track if the agent is a follow-up task
- self_verification_retries: int = 0 # Number of times self-verification has rejected done(success=true)
message_manager_state: MessageManagerState = Field(default_factory=MessageManagerState)
file_system_state: FileSystemState | None = None
@@ -109,12 +107,6 @@ class JudgementResult(BaseModel):
)
-class SelfVerifyResult(BaseModel):
- """Result of lightweight self-verification before done."""
-
- verified: bool = Field(description='True if the task appears completed correctly')
- reason: str = Field(default='', description='Brief explanation if not verified')
-
class ActionResult(BaseModel):
"""Result of executing an action"""