Skip to content

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

Include last message in judge

Magnus Müller2afffcccbb8a
diff --git a/eval/judge_system.py b/eval/judge_system.py
index de73d0c0f..d36cff979 100644
--- a/eval/judge_system.py
+++ b/eval/judge_system.py
@@ -189,11 +189,14 @@ def encode_image(image_path: str) -> str:
return ''
-def truncate_text(text: str, max_length: int) -> str:
+def truncate_text(text: str, max_length: int, from_beginning: bool = False) -> str:
"""Truncate text to maximum length with eval system indicator."""
if len(text) <= max_length:
return text
- return text[: max_length - 23] + '...[cut for eval]...'
+ if from_beginning:
+ return '...[cut for eval]' + text[-max_length + 23 :]
+ else:
+ return text[: max_length - 23] + '...[cut for eval]...'
def prepare_agent_steps(complete_history: list[dict]) -> list[str]:
@@ -326,7 +329,7 @@ async def comprehensive_judge(
# Prepare inputs with length limits
task_truncated = truncate_text(task, 40000)
final_result_truncated = truncate_text(final_result or 'No final result', 40000)
- last_message_truncated = truncate_text(last_message or 'No last message', 40000)
+ last_message_truncated = truncate_text(last_message or 'No last message', 40000, from_beginning=True)
agent_steps = prepare_agent_steps(complete_history)
# Select and filter images
diff --git a/eval/service.py b/eval/service.py
index 1b1360ebb..c936e64d1 100644
--- a/eval/service.py
+++ b/eval/service.py
@@ -1340,7 +1340,9 @@ async def run_agent_with_browser(
planner_interval=planner_interval,
source='eval_platform',
)
-
+ # get last message
+ last_input_messages = agent.message_manager.last_input_messages
+ last_message = last_input_messages[-1].text
await agent.run(max_steps=max_steps)
return agent.state.history