# DashScope Tool Use (/examples/models/dashscope/tool-use)



```python title="tool_use.py"
"""
Dashscope Tool Use
==================

Cookbook example for `dashscope/tool_use.py`.
"""

import asyncio

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

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

agent = Agent(
    model=DashScope(id="qwen-plus"),
    tools=[WebSearchTools()],
    markdown=True,
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    # --- Sync + Streaming ---
    agent.print_response("What's happening in AI today?", stream=True)

    # --- Async + Streaming ---
    async def main():
        await agent.aprint_response(
            "What's the latest news about artificial intelligence?", stream=True
        )

    asyncio.run(main())
```

## Run the Example [#run-the-example]

<Steps>
    <Step title="Set up your virtual environment">
      <CodeBlockTabs defaultValue="Mac">
        <CodeBlockTabsList>
          <CodeBlockTabsTrigger value="Mac">
            Mac
          </CodeBlockTabsTrigger>

          <CodeBlockTabsTrigger value="Windows">
            Windows
          </CodeBlockTabsTrigger>
        </CodeBlockTabsList>

        <CodeBlockTab value="Mac">
          ```bash
          uv venv --python 3.12
          source .venv/bin/activate
          ```
        </CodeBlockTab>

        <CodeBlockTab value="Windows">
          ```bash
          uv venv --python 3.12
          .venv\Scripts\activate
          ```
        </CodeBlockTab>
      </CodeBlockTabs>
    </Step>

  <Step title="Install dependencies">
    ```bash
    uv pip install -U agno ddgs openai
    ```
  </Step>

    <Step title="Configure regional DashScope access">
      Activate Alibaba Cloud Model Studio and [create an API key](https://www.alibabacloud.com/help/en/model-studio/get-api-key) for your region and workspace. Agno's default endpoint is Singapore: `https://dashscope-intl.aliyuncs.com/compatible-mode/v1`.

      <CodeBlockTabs defaultValue="Mac/Linux">
        <CodeBlockTabsList>
          <CodeBlockTabsTrigger value="Mac/Linux">
            Mac/Linux
          </CodeBlockTabsTrigger>

          <CodeBlockTabsTrigger value="Windows">
            Windows
          </CodeBlockTabsTrigger>
        </CodeBlockTabsList>

        <CodeBlockTab value="Mac/Linux">
          ```bash
          export DASHSCOPE_API_KEY="your_singapore_api_key"
          ```
        </CodeBlockTab>

        <CodeBlockTab value="Windows">
          ```powershell
          $Env:DASHSCOPE_API_KEY="your_singapore_api_key"
          ```
        </CodeBlockTab>
      </CodeBlockTabs>

      For another region or a workspace-specific domain, pass the matching `base_url` to `DashScope`. Use the [OpenAI-compatible endpoint guide](https://www.alibabacloud.com/help/en/model-studio/qwen-api-via-openai-chat-completions) to match the URL, key and available model. The documented Singapore default remains functional.
    </Step>

  <Step title="Run the example">
    Save the code above as `tool_use.py`, then run:

    ```bash
    python tool_use.py
    ```
  </Step>
</Steps>

Full source: [cookbook/90\_models/dashscope/tool\_use.py](https://github.com/agno-agi/agno/blob/8f36eaf2d18e91afa7b327eec66a3cd3685dcb87/cookbook/90_models/dashscope/tool_use.py)
