diff --git a/tools/vision_tools.py b/tools/vision_tools.py index d91051175..204c882a9 100644 --- a/tools/vision_tools.py +++ b/tools/vision_tools.py @@ -256,15 +256,7 @@ async def vision_analyze_tool( logger.info("Analyzing image: %s", image_url[:60]) logger.info("User prompt: %s", user_prompt[:100]) - - # Check auxiliary vision client availability - if _aux_async_client is None or DEFAULT_VISION_MODEL is None: - return json.dumps({ - "success": False, - "analysis": "Vision analysis unavailable: no auxiliary vision model configured. " - "Set OPENROUTER_API_KEY or configure Nous Portal to enable vision tools." - }, indent=2, ensure_ascii=False) - + # Determine if this is a local file path or a remote URL local_path = Path(image_url) if local_path.is_file(): @@ -321,7 +313,25 @@ async def vision_analyze_tool( ] logger.info("Processing image with %s...", model) - + + # Check auxiliary vision client availability just before API call so + # earlier failures (like download errors) still go through the main + # try/except block and get logged with exc_info for debugging/tests. + if _aux_async_client is None or DEFAULT_VISION_MODEL is None: + logger.error( + "Vision analysis unavailable: no auxiliary vision model configured. " + "Set OPENROUTER_API_KEY or configure Nous Portal to enable vision tools.", + ) + return json.dumps( + { + "success": False, + "analysis": "Vision analysis unavailable: no auxiliary vision model configured. " + "Set OPENROUTER_API_KEY or configure Nous Portal to enable vision tools.", + }, + indent=2, + ensure_ascii=False, + ) + # Call the vision API from agent.auxiliary_client import get_auxiliary_extra_body, auxiliary_max_tokens_param _extra = get_auxiliary_extra_body() @@ -356,7 +366,8 @@ async def vision_analyze_tool( except Exception as e: error_msg = f"Error analyzing image: {str(e)}" - logger.error("%s", error_msg, exc_info=True) + # Use logger.exception so exc_info is always attached for debugging and tests. + logger.exception("%s", error_msg) # Prepare error response result = {