ollama-code

Web Search Tool (web_search)

This document describes the web_search tool for performing web searches using multiple providers.

Description

Use web_search to perform a web search and get information from the internet. The tool supports multiple search providers and returns a concise answer with source citations when available.

Supported Providers

  1. DashScope (Official, Free) - Automatically available for Qwen OAuth users (200 requests/minute, 1000 requests/day)
  2. Tavily - High-quality search API with built-in answer generation
  3. Google Custom Search - Google’s Custom Search JSON API

Arguments

web_search takes two arguments:

Configuration

Add to your settings.json:

{
  "webSearch": {
    "provider": [
      { "type": "dashscope" },
      { "type": "tavily", "apiKey": "tvly-xxxxx" },
      {
        "type": "google",
        "apiKey": "your-google-api-key",
        "searchEngineId": "your-search-engine-id"
      }
    ],
    "default": "dashscope"
  }
}

Notes:

Method 2: Environment Variables

Set environment variables in your shell or .env file:

# Tavily
export TAVILY_API_KEY="tvly-xxxxx"

# Google
export GOOGLE_API_KEY="your-api-key"
export GOOGLE_SEARCH_ENGINE_ID="your-engine-id"

Method 3: Command Line Arguments

Pass API keys when running Ollama Code:

# Tavily
qwen --tavily-api-key tvly-xxxxx

# Google
qwen --google-api-key your-key --google-search-engine-id your-id

# Specify default provider
qwen --web-search-default tavily

Backward Compatibility (Deprecated)

⚠️ DEPRECATED: The legacy tavilyApiKey configuration is still supported for backward compatibility but is deprecated:

{
  "advanced": {
    "tavilyApiKey": "tvly-xxxxx" // ⚠️ Deprecated
  }
}

Important: This configuration is deprecated and will be removed in a future version. Please migrate to the new webSearch configuration format shown above. The old configuration will automatically configure Tavily as a provider, but we strongly recommend updating your configuration.

If you want to disable the web search functionality, you can exclude the web_search tool in your settings.json:

{
  "tools": {
    "exclude": ["web_search"]
  }
}

Note: This setting requires a restart of Ollama Code to take effect. Once disabled, the web_search tool will not be available to the model, even if web search providers are configured.

Usage Examples

Basic search (using default provider)

web_search(query="latest advancements in AI")

Search with specific provider

web_search(query="latest advancements in AI", provider="tavily")

Real-world examples

web_search(query="weather in San Francisco today")
web_search(query="latest Node.js LTS version", provider="google")
web_search(query="best practices for React 19", provider="dashscope")

Provider Details

DashScope (Official)

Tavily

Important Notes

Troubleshooting

Tool not available?

Provider-specific errors?

Need help?