Skip to content

Commit 768a7f6

Browse files
committed
fix deepresearch
1 parent a25df05 commit 768a7f6

File tree

4 files changed

+29
-32
lines changed

4 files changed

+29
-32
lines changed

src/agent/custom_agent.py

+19-21
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,6 @@
5454

5555
logger = logging.getLogger(__name__)
5656

57-
58-
def _log_response(response: CustomAgentOutput) -> None:
59-
"""Log the model's response"""
60-
if "Success" in response.current_state.evaluation_previous_goal:
61-
emoji = "✅"
62-
elif "Failed" in response.current_state.evaluation_previous_goal:
63-
emoji = "❌"
64-
else:
65-
emoji = "🤷"
66-
67-
logger.info(f"{emoji} Eval: {response.current_state.evaluation_previous_goal}")
68-
logger.info(f"🧠 New Memory: {response.current_state.important_contents}")
69-
logger.info(f"🤔 Thought: {response.current_state.thought}")
70-
logger.info(f"🎯 Next Goal: {response.current_state.next_goal}")
71-
for i, action in enumerate(response.action):
72-
logger.info(
73-
f"🛠️ Action {i + 1}/{len(response.action)}: {action.model_dump_json(exclude_unset=True)}"
74-
)
75-
76-
7757
Context = TypeVar('Context')
7858

7959

@@ -180,6 +160,24 @@ def __init__(
180160
state=self.state.message_manager_state,
181161
)
182162

163+
def _log_response(self, response: CustomAgentOutput) -> None:
164+
"""Log the model's response"""
165+
if "Success" in response.current_state.evaluation_previous_goal:
166+
emoji = "✅"
167+
elif "Failed" in response.current_state.evaluation_previous_goal:
168+
emoji = "❌"
169+
else:
170+
emoji = "🤷"
171+
172+
logger.info(f"{emoji} Eval: {response.current_state.evaluation_previous_goal}")
173+
logger.info(f"🧠 New Memory: {response.current_state.important_contents}")
174+
logger.info(f"🤔 Thought: {response.current_state.thought}")
175+
logger.info(f"🎯 Next Goal: {response.current_state.next_goal}")
176+
for i, action in enumerate(response.action):
177+
logger.info(
178+
f"🛠️ Action {i + 1}/{len(response.action)}: {action.model_dump_json(exclude_unset=True)}"
179+
)
180+
183181
def _setup_action_models(self) -> None:
184182
"""Setup dynamic action models from controller's registry"""
185183
# Get the dynamic action model from controller's registry
@@ -236,7 +234,7 @@ async def get_next_action(self, input_messages: list[BaseMessage]) -> AgentOutpu
236234
# cut the number of actions to max_actions_per_step if needed
237235
if len(parsed.action) > self.settings.max_actions_per_step:
238236
parsed.action = parsed.action[: self.settings.max_actions_per_step]
239-
_log_response(parsed)
237+
self._log_response(parsed)
240238
return parsed
241239

242240
async def _run_planner(self) -> Optional[str]:

src/agent/custom_prompts.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ def get_user_message(self, use_vision: bool = True) -> HumanMessage:
8888
for i, result in enumerate(self.result):
8989
action = self.actions[i]
9090
state_description += f"Previous action {i + 1}/{len(self.result)}: {action.model_dump_json(exclude_unset=True)}\n"
91+
if result.error:
92+
# only use last 300 characters of error
93+
error = result.error.split('\n')[-1]
94+
state_description += (
95+
f"Error of previous action {i + 1}/{len(self.result)}: ...{error}\n"
96+
)
9197
if result.include_in_memory:
9298
if result.extracted_content:
9399
state_description += f"Result of previous action {i + 1}/{len(self.result)}: {result.extracted_content}\n"
94-
if result.error:
95-
# only use last 300 characters of error
96-
error = result.error.split('\n')[-1]
97-
state_description += (
98-
f"Error of previous action {i + 1}/{len(self.result)}: ...{error}\n"
99-
)
100100

101101
if self.state.screenshot and use_vision == True:
102102
# Format message for vision model

src/utils/deep_research.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ async def extract_content(browser: BrowserContext):
8989
)
9090
# go back to org url
9191
await page.go_back()
92-
msg = f'Extracted page content:\n {content}\n'
92+
msg = f'Extracted page content:\n{content}\n'
9393
logger.info(msg)
9494
return ActionResult(extracted_content=msg)
9595

webui.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ async def run_org_agent(
338338
)
339339
history = await _global_agent.run(max_steps=max_steps)
340340

341-
history_file = os.path.join(save_agent_history_path, f"{_global_agent.agent_id}.json")
341+
history_file = os.path.join(save_agent_history_path, f"{_global_agent.state.agent_id}.json")
342342
_global_agent.save_history(history_file)
343343

344344
final_result = history.final_result()
@@ -450,7 +450,7 @@ async def run_custom_agent(
450450
)
451451
history = await _global_agent.run(max_steps=max_steps)
452452

453-
history_file = os.path.join(save_agent_history_path, f"{_global_agent.agent_id}.json")
453+
history_file = os.path.join(save_agent_history_path, f"{_global_agent.state.agent_id}.json")
454454
_global_agent.save_history(history_file)
455455

456456
final_result = history.final_result()
@@ -985,12 +985,11 @@ def update_llm_num_ctx_visibility(llm_provider):
985985
markdown_output_display = gr.Markdown(label="Research Report")
986986
markdown_download = gr.File(label="Download Research Report")
987987

988-
989988
# Bind the stop button click event after errors_output is defined
990989
stop_button.click(
991990
fn=stop_agent,
992991
inputs=[],
993-
outputs=[errors_output, stop_button, run_button],
992+
outputs=[stop_button, run_button],
994993
)
995994

996995
# Run button click handler

0 commit comments

Comments
 (0)