Image Agent

Pass raw image bytes to an IBM WatsonX vision model.

Code

Use a project and region that serve this vision model; check IBM regional availability. The example describes the supplied image and does not retrieve current news.

from pathlib import Path

from agno.agent import Agent
from agno.media import Image
from agno.models.ibm import WatsonX

agent = Agent(
    model=WatsonX(id="mistralai/mistral-small-3-1-24b-instruct-2503"),
    markdown=True,
)

image_path = Path(__file__).parent.joinpath("sample.jpg")

# Read the image file content as bytes
image_bytes = image_path.read_bytes()

agent.print_response(
    "Describe the contents of this image.",
    images=[
        Image(content=image_bytes),
    ],
    stream=True,
)

Usage

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Set your API key

export IBM_WATSONX_API_KEY=xxx
export IBM_WATSONX_PROJECT_ID=xxx

Install dependencies

uv pip install -U ibm-watsonx-ai agno

Add sample image

Place a sample image named "sample.jpg" in the same directory as the script.

Run Agent

Save the code above as image_agent_bytes.py, then run:

python image_agent_bytes.py

The example loads an image from a file and passes it to an IBM WatsonX vision model along with a prompt.