mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-07 13:23:15 +00:00
Improve operator exception handling
- Do not catch errors messages just to re-throw them. Results in confusing exception happened during handling of an exception stacktrace. Makes it harder to debug - Log error when action_results.content isn't set or empty to debug this operator run error
This commit is contained in:
@@ -138,14 +138,6 @@ async def operate_browser(
|
|||||||
response = summary_message
|
response = summary_message
|
||||||
else: # Hit iteration limit
|
else: # Hit iteration limit
|
||||||
response = f"Operator hit iteration limit ({max_iterations}). If the results seem incomplete try again, assign a smaller task or try a different approach.\nThese were the results till now:\n{summary_message}"
|
response = f"Operator hit iteration limit ({max_iterations}). If the results seem incomplete try again, assign a smaller task or try a different approach.\nThese were the results till now:\n{summary_message}"
|
||||||
except requests.RequestException as e:
|
|
||||||
error_msg = f"Browser use failed due to a network error: {e}"
|
|
||||||
logger.error(error_msg)
|
|
||||||
raise ValueError(error_msg)
|
|
||||||
except Exception as e:
|
|
||||||
error_msg = f"Browser use failed due to an unexpected error: {e}"
|
|
||||||
logger.exception(error_msg) # Log full traceback for unexpected errors
|
|
||||||
raise ValueError(error_msg)
|
|
||||||
finally:
|
finally:
|
||||||
if environment and not user_input_message: # Don't close browser if user input required
|
if environment and not user_input_message: # Don't close browser if user input required
|
||||||
await environment.close()
|
await environment.close()
|
||||||
|
|||||||
@@ -168,6 +168,7 @@ Focus on the visual action and provide all necessary context.
|
|||||||
logger.info(f"Reasoning LLM suggested action: {natural_language_action}")
|
logger.info(f"Reasoning LLM suggested action: {natural_language_action}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
logger.error(f"Error calling Reasoning LLM: {e}", exc_info=True)
|
||||||
return {"type": "error", "message": f"Error calling Reasoning LLM: {e}"}
|
return {"type": "error", "message": f"Error calling Reasoning LLM: {e}"}
|
||||||
|
|
||||||
return {"type": "action", "message": natural_language_action}
|
return {"type": "action", "message": natural_language_action}
|
||||||
@@ -212,7 +213,7 @@ Focus on the visual action and provide all necessary context.
|
|||||||
rendered_parts += [f"**Action**: {action.type}"]
|
rendered_parts += [f"**Action**: {action.type}"]
|
||||||
action_results += [{"content": None}] # content set after environment step
|
action_results += [{"content": None}] # content set after environment step
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error calling Grounding LLM: {e}")
|
logger.error(f"Error calling Grounding LLM: {e}", exc_info=True)
|
||||||
rendered_parts += [f"**Error**: Error contacting Grounding LLM: {e}"]
|
rendered_parts += [f"**Error**: Error contacting Grounding LLM: {e}"]
|
||||||
|
|
||||||
rendered_response = self._render_response(rendered_parts, current_state.screenshot)
|
rendered_response = self._render_response(rendered_parts, current_state.screenshot)
|
||||||
@@ -256,6 +257,8 @@ Focus on the visual action and provide all necessary context.
|
|||||||
# Append action results to history
|
# Append action results to history
|
||||||
action_results_content = []
|
action_results_content = []
|
||||||
for action_result in agent_action.action_results:
|
for action_result in agent_action.action_results:
|
||||||
|
if not action_result.get("content"):
|
||||||
|
logger.error("Action result content is empty or None: {action_result}")
|
||||||
action_results_content.extend(action_result["content"])
|
action_results_content.extend(action_result["content"])
|
||||||
self.messages.append(AgentMessage(role="environment", content=action_results_content))
|
self.messages.append(AgentMessage(role="environment", content=action_results_content))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user