mirror of
https://github.com/browser-use/web-ui.git
synced 2026-03-22 11:17:17 +08:00
fix deepresearch
This commit is contained in:
@@ -54,26 +54,6 @@ from .custom_views import CustomAgentOutput, CustomAgentStepInfo, CustomAgentSta
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _log_response(response: CustomAgentOutput) -> None:
|
||||
"""Log the model's response"""
|
||||
if "Success" in response.current_state.evaluation_previous_goal:
|
||||
emoji = "✅"
|
||||
elif "Failed" in response.current_state.evaluation_previous_goal:
|
||||
emoji = "❌"
|
||||
else:
|
||||
emoji = "🤷"
|
||||
|
||||
logger.info(f"{emoji} Eval: {response.current_state.evaluation_previous_goal}")
|
||||
logger.info(f"🧠 New Memory: {response.current_state.important_contents}")
|
||||
logger.info(f"🤔 Thought: {response.current_state.thought}")
|
||||
logger.info(f"🎯 Next Goal: {response.current_state.next_goal}")
|
||||
for i, action in enumerate(response.action):
|
||||
logger.info(
|
||||
f"🛠️ Action {i + 1}/{len(response.action)}: {action.model_dump_json(exclude_unset=True)}"
|
||||
)
|
||||
|
||||
|
||||
Context = TypeVar('Context')
|
||||
|
||||
|
||||
@@ -180,6 +160,24 @@ class CustomAgent(Agent):
|
||||
state=self.state.message_manager_state,
|
||||
)
|
||||
|
||||
def _log_response(self, response: CustomAgentOutput) -> None:
|
||||
"""Log the model's response"""
|
||||
if "Success" in response.current_state.evaluation_previous_goal:
|
||||
emoji = "✅"
|
||||
elif "Failed" in response.current_state.evaluation_previous_goal:
|
||||
emoji = "❌"
|
||||
else:
|
||||
emoji = "🤷"
|
||||
|
||||
logger.info(f"{emoji} Eval: {response.current_state.evaluation_previous_goal}")
|
||||
logger.info(f"🧠 New Memory: {response.current_state.important_contents}")
|
||||
logger.info(f"🤔 Thought: {response.current_state.thought}")
|
||||
logger.info(f"🎯 Next Goal: {response.current_state.next_goal}")
|
||||
for i, action in enumerate(response.action):
|
||||
logger.info(
|
||||
f"🛠️ Action {i + 1}/{len(response.action)}: {action.model_dump_json(exclude_unset=True)}"
|
||||
)
|
||||
|
||||
def _setup_action_models(self) -> None:
|
||||
"""Setup dynamic action models from controller's registry"""
|
||||
# Get the dynamic action model from controller's registry
|
||||
@@ -236,7 +234,7 @@ class CustomAgent(Agent):
|
||||
# cut the number of actions to max_actions_per_step if needed
|
||||
if len(parsed.action) > self.settings.max_actions_per_step:
|
||||
parsed.action = parsed.action[: self.settings.max_actions_per_step]
|
||||
_log_response(parsed)
|
||||
self._log_response(parsed)
|
||||
return parsed
|
||||
|
||||
async def _run_planner(self) -> Optional[str]:
|
||||
|
||||
@@ -88,15 +88,15 @@ class CustomAgentMessagePrompt(AgentMessagePrompt):
|
||||
for i, result in enumerate(self.result):
|
||||
action = self.actions[i]
|
||||
state_description += f"Previous action {i + 1}/{len(self.result)}: {action.model_dump_json(exclude_unset=True)}\n"
|
||||
if result.error:
|
||||
# only use last 300 characters of error
|
||||
error = result.error.split('\n')[-1]
|
||||
state_description += (
|
||||
f"Error of previous action {i + 1}/{len(self.result)}: ...{error}\n"
|
||||
)
|
||||
if result.include_in_memory:
|
||||
if result.extracted_content:
|
||||
state_description += f"Result of previous action {i + 1}/{len(self.result)}: {result.extracted_content}\n"
|
||||
if result.error:
|
||||
# only use last 300 characters of error
|
||||
error = result.error.split('\n')[-1]
|
||||
state_description += (
|
||||
f"Error of previous action {i + 1}/{len(self.result)}: ...{error}\n"
|
||||
)
|
||||
|
||||
if self.state.screenshot and use_vision == True:
|
||||
# Format message for vision model
|
||||
|
||||
@@ -89,7 +89,7 @@ async def deep_research(task, llm, agent_state=None, **kwargs):
|
||||
)
|
||||
# go back to org url
|
||||
await page.go_back()
|
||||
msg = f'Extracted page content:\n {content}\n'
|
||||
msg = f'Extracted page content:\n{content}\n'
|
||||
logger.info(msg)
|
||||
return ActionResult(extracted_content=msg)
|
||||
|
||||
|
||||
7
webui.py
7
webui.py
@@ -338,7 +338,7 @@ async def run_org_agent(
|
||||
)
|
||||
history = await _global_agent.run(max_steps=max_steps)
|
||||
|
||||
history_file = os.path.join(save_agent_history_path, f"{_global_agent.agent_id}.json")
|
||||
history_file = os.path.join(save_agent_history_path, f"{_global_agent.state.agent_id}.json")
|
||||
_global_agent.save_history(history_file)
|
||||
|
||||
final_result = history.final_result()
|
||||
@@ -450,7 +450,7 @@ async def run_custom_agent(
|
||||
)
|
||||
history = await _global_agent.run(max_steps=max_steps)
|
||||
|
||||
history_file = os.path.join(save_agent_history_path, f"{_global_agent.agent_id}.json")
|
||||
history_file = os.path.join(save_agent_history_path, f"{_global_agent.state.agent_id}.json")
|
||||
_global_agent.save_history(history_file)
|
||||
|
||||
final_result = history.final_result()
|
||||
@@ -985,12 +985,11 @@ def create_ui(config, theme_name="Ocean"):
|
||||
markdown_output_display = gr.Markdown(label="Research Report")
|
||||
markdown_download = gr.File(label="Download Research Report")
|
||||
|
||||
|
||||
# Bind the stop button click event after errors_output is defined
|
||||
stop_button.click(
|
||||
fn=stop_agent,
|
||||
inputs=[],
|
||||
outputs=[errors_output, stop_button, run_button],
|
||||
outputs=[stop_button, run_button],
|
||||
)
|
||||
|
||||
# Run button click handler
|
||||
|
||||
Reference in New Issue
Block a user