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:
Debanjum
2025-05-10 16:31:48 -06:00
parent 59e0e092b0
commit ac19f6d336
2 changed files with 4 additions and 9 deletions

View File

@@ -138,14 +138,6 @@ async def operate_browser(
response = summary_message
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}"
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:
if environment and not user_input_message: # Don't close browser if user input required
await environment.close()

View File

@@ -168,6 +168,7 @@ Focus on the visual action and provide all necessary context.
logger.info(f"Reasoning LLM suggested action: {natural_language_action}")
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": "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}"]
action_results += [{"content": None}] # content set after environment step
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_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
action_results_content = []
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"])
self.messages.append(AgentMessage(role="environment", content=action_results_content))