Agent with Tools

Give a DashScope qwen-plus agent web search tools and stream the response.

Code

from agno.agent import Agent
from agno.models.dashscope import DashScope
from agno.tools.websearch import WebSearchTools

agent = Agent(
    model=DashScope(id="qwen-plus"),
    tools=[WebSearchTools()],
    markdown=True,
)
agent.print_response("What's happening in AI today?", stream=True)

The default endpoint is Singapore (https://dashscope-intl.aliyuncs.com/compatible-mode/v1). Use a DASHSCOPE_API_KEY issued for that service region and a model available there. Keys and endpoints must match the service region, regardless of your physical location. For another region, pass its base_url to DashScope; see Model Studio API keys and regional endpoints.

Usage

Set up your virtual environment

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

Set your API key

export DASHSCOPE_API_KEY=xxx

Install dependencies

uv pip install -U openai ddgs agno

Run Agent

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

python tool_use.py