xAI Image Agent

Describe an image URL with Grok 4.5 and search for related news.

The source-fidelity code uses the older grok-2-vision-latest model. Replace it with grok-4.5 before running the example.

image_agent.py
"""
Xai Image Agent
===============

Cookbook example for `xai/image_agent.py`.
"""

from agno.agent import Agent
from agno.media import Image
from agno.models.xai import xAI
from agno.tools.websearch import WebSearchTools

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

agent = Agent(
    model=xAI(id="grok-2-vision-latest"),
    tools=[WebSearchTools()],
    markdown=True,
)

agent.print_response(
    "Tell me about this image and give me the latest news about it.",
    images=[
        Image(
            url="https://upload.wikimedia.org/wikipedia/commons/0/0c/GoldenGateBridge-001.jpg"
        )
    ],
    stream=True,
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    pass

Run the Example

Set up your virtual environment

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

Install dependencies

uv pip install -U agno ddgs openai

Export your xAI API key

export XAI_API_KEY="your_xai_api_key_here"

Update the model

When saving the code, replace grok-2-vision-latest with grok-4.5.

Run the example

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

python image_agent.py

Full source: cookbook/90_models/xai/image_agent.py