image_agent.py
"""
Dashscope Image Agent
=====================
Cookbook example for `dashscope/image_agent.py`.
"""
import asyncio
from agno.agent import Agent
from agno.media import Image
from agno.models.dashscope import DashScope
from agno.tools.websearch import WebSearchTools
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
model=DashScope(id="qwen-vl-plus"),
tools=[WebSearchTools()],
markdown=True,
)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
# --- Sync + Streaming ---
agent.print_response(
"Analyze this image in detail and tell me what you see. Also search for more information about the subject.",
images=[
Image(
url="https://upload.wikimedia.org/wikipedia/commons/0/0c/GoldenGateBridge-001.jpg"
)
],
stream=True,
)
# --- Async + Streaming ---
async def main():
await agent.aprint_response(
"What do you see in this image? Provide a detailed description and search for related information.",
images=[
Image(
url="https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg"
)
],
stream=True,
)
asyncio.run(main())
Run the Example
1
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
2
Install dependencies
uv pip install -U agno ddgs openai
3
Export your DashScope API key
export DASHSCOPE_API_KEY="your_dashscope_api_key_here"
$Env:DASHSCOPE_API_KEY="your_dashscope_api_key_here"
4
Run the example
Save the code above as
image_agent.py, then run:python image_agent.py