Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CrewAIInc CrewAI Vision Tool

From Leeroopedia
Knowledge Sources
Domains Tools, Vision, Image_Analysis
Last Updated 2026-02-11 00:00 GMT

Overview

VisionTool analyzes images using vision-capable LLMs, describing image contents from either a URL or a local file path.

Description

The VisionTool extends BaseTool and uses an ImagePromptSchema that validates the input image_path_url by checking that URLs start with "http" or that local file paths exist and have supported extensions (.jpg, .jpeg, .png, .gif, .webp). The tool uses private attributes (_model and _llm) with a lazy-initialization pattern: the llm property creates an LLM instance (defaulting to gpt-4o-mini) only when first accessed. The _run method handles two paths: for URLs, the image data is passed directly; for local files, the image is read and base64-encoded. It constructs a multimodal message with text ("What's in this image?") and the image data, then calls the LLM to get a description. The model property setter resets the LLM instance if the model identifier changes.

Usage

Use this tool when a CrewAI agent needs to understand and describe visual content from web URLs or local image files as part of workflows that process visual information alongside text.

Code Reference

Source Location

  • Repository: CrewAI
  • File: lib/crewai-tools/src/crewai_tools/tools/vision_tool/vision_tool.py
  • Lines: 1-136

Signature

class ImagePromptSchema(BaseModel):
    image_path_url: str = "The image path or URL."

class VisionTool(BaseTool):
    name: str = "Vision Tool"
    description: str = "This tool uses OpenAI's Vision API to describe the contents of an image."
    args_schema: type[BaseModel] = ImagePromptSchema
    env_vars: list[EnvVar]  # OPENAI_API_KEY
    _model: str = PrivateAttr(default="gpt-4o-mini")
    _llm: LLM | None = PrivateAttr(default=None)

    def __init__(self, llm: LLM | None = None, model: str = "gpt-4o-mini", **kwargs):
        ...
    def _run(self, **kwargs) -> str:
        ...

Import

from crewai_tools import VisionTool

I/O Contract

Inputs

Name Type Required Description
image_path_url str Yes The image URL (starting with "http") or local file path (.jpg, .jpeg, .png, .gif, .webp)

Outputs

Name Type Description
_run() returns str A text description of the image contents generated by the vision LLM

Usage Examples

Basic Usage (URL)

from crewai_tools import VisionTool

tool = VisionTool()
result = tool._run(image_path_url="https://example.com/image.jpg")

Local File

from crewai_tools import VisionTool

tool = VisionTool(model="gpt-4o")
result = tool._run(image_path_url="/path/to/image.png")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment