IBM Image Agent Bytes
Pass JPEG bytes to a vision-capable Mistral Small model on watsonx.
"""
Ibm Image Agent Bytes
=====================
Cookbook example for `ibm/watsonx/image_agent_bytes.py`.
"""
from pathlib import Path
from agno.agent import Agent
from agno.media import Image
from agno.models.ibm import WatsonX
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
model=WatsonX(id="meta-llama/llama-3-2-11b-vision-instruct"),
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(
"Tell me about this image and give me the latest news about it.",
images=[
Image(content=image_bytes),
],
stream=True,
)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
passIBM's lifecycle table lists 8 August 2026 as the multitenant withdrawal date for the source's Llama 3.2 11B Vision model. Apply the Mistral Small substitution below for this example. A dedicated deployment has separate setup and availability.
This agent receives an image but has no news-search tool. Its prompt's request for the latest news does not provide live-news retrieval.
Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno ibm-watsonx-aiConfigure your watsonx project and region
Use a project associated with a watsonx.ai Runtime service and an IBM Cloud API key authorized to access it. Copy the project ID and service URL from your watsonx environment. Check regional model availability before selecting a model.
The example URL below is Frankfurt, which is also the adapter default. Change it to match your project and service region.
export IBM_WATSONX_API_KEY="your_ibm_cloud_api_key"
export IBM_WATSONX_PROJECT_ID="your_project_id"
export IBM_WATSONX_URL="https://eu-de.ml.cloud.ibm.com"Add a sample image
Place a JPEG named sample.jpg in the same directory as image_agent_bytes.py.
Select the current vision model
Save the source as image_agent_bytes.py and replace WatsonX(id="meta-llama/llama-3-2-11b-vision-instruct") with WatsonX(id="mistralai/mistral-small-3-1-24b-instruct-2503"). IBM documents this model's image-understanding capability; confirm it is available in your selected region.
Run the example
Save the code above as image_agent_bytes.py, then run:
python image_agent_bytes.pyFull source: cookbook/90_models/ibm/watsonx/image_agent_bytes.py