Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions tools/vision_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 = {
Expand Down