|
1 | 1 | # Web Search Tool (`web_search`) |
2 | 2 |
|
3 | | -This document describes the `web_search` tool. |
| 3 | +This document describes the `web_search` tool for performing web searches using multiple providers. |
4 | 4 |
|
5 | 5 | ## Description |
6 | 6 |
|
7 | | -Use `web_search` to perform a web search using the Tavily API. The tool returns a concise answer with sources when possible. |
| 7 | +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. |
| 8 | + |
| 9 | +### Supported Providers |
| 10 | + |
| 11 | +1. **DashScope** (Official, Free) - Automatically available for Qwen OAuth users (200 requests/minute, 2000 requests/day) |
| 12 | +2. **Tavily** - High-quality search API with built-in answer generation |
| 13 | +3. **Google Custom Search** - Google's Custom Search JSON API |
8 | 14 |
|
9 | 15 | ### Arguments |
10 | 16 |
|
11 | | -`web_search` takes one argument: |
| 17 | +`web_search` takes two arguments: |
| 18 | + |
| 19 | +- `query` (string, required): The search query |
| 20 | +- `provider` (string, optional): Specific provider to use ("dashscope", "tavily", "google") |
| 21 | + - If not specified, uses the default provider from configuration |
| 22 | + |
| 23 | +## Configuration |
| 24 | + |
| 25 | +### Method 1: Settings File (Recommended) |
| 26 | + |
| 27 | +Add to your `settings.json`: |
| 28 | + |
| 29 | +```json |
| 30 | +{ |
| 31 | + "webSearch": { |
| 32 | + "provider": [ |
| 33 | + { "type": "dashscope" }, |
| 34 | + { "type": "tavily", "apiKey": "tvly-xxxxx" }, |
| 35 | + { |
| 36 | + "type": "google", |
| 37 | + "apiKey": "your-google-api-key", |
| 38 | + "searchEngineId": "your-search-engine-id" |
| 39 | + } |
| 40 | + ], |
| 41 | + "default": "dashscope" |
| 42 | + } |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +**Notes:** |
| 47 | + |
| 48 | +- DashScope doesn't require an API key (official, free service) |
| 49 | +- **Qwen OAuth users:** DashScope is automatically added to your provider list, even if not explicitly configured |
| 50 | +- Configure additional providers (Tavily, Google) if you want to use them alongside DashScope |
| 51 | +- Set `default` to specify which provider to use by default (if not set, priority order: Tavily > Google > DashScope) |
| 52 | + |
| 53 | +### Method 2: Environment Variables |
| 54 | + |
| 55 | +Set environment variables in your shell or `.env` file: |
| 56 | + |
| 57 | +```bash |
| 58 | +# Tavily |
| 59 | +export TAVILY_API_KEY="tvly-xxxxx" |
| 60 | + |
| 61 | +# Google |
| 62 | +export GOOGLE_API_KEY="your-api-key" |
| 63 | +export GOOGLE_SEARCH_ENGINE_ID="your-engine-id" |
| 64 | +``` |
| 65 | + |
| 66 | +### Method 3: Command Line Arguments |
12 | 67 |
|
13 | | -- `query` (string, required): The search query. |
| 68 | +Pass API keys when running Qwen Code: |
14 | 69 |
|
15 | | -## How to use `web_search` |
| 70 | +```bash |
| 71 | +# Tavily |
| 72 | +qwen --tavily-api-key tvly-xxxxx |
16 | 73 |
|
17 | | -`web_search` calls the Tavily API directly. You must configure the `TAVILY_API_KEY` through one of the following methods: |
| 74 | +# Google |
| 75 | +qwen --google-api-key your-key --google-search-engine-id your-id |
18 | 76 |
|
19 | | -1. **Settings file**: Add `"tavilyApiKey": "your-key-here"` to your `settings.json` |
20 | | -2. **Environment variable**: Set `TAVILY_API_KEY` in your environment or `.env` file |
21 | | -3. **Command line**: Use `--tavily-api-key your-key-here` when running the CLI |
| 77 | +# Specify default provider |
| 78 | +qwen --web-search-default tavily |
| 79 | +``` |
22 | 80 |
|
23 | | -If the key is not configured, the tool will be disabled and skipped. |
| 81 | +### Backward Compatibility (Deprecated) |
24 | 82 |
|
25 | | -Usage: |
| 83 | +⚠️ **DEPRECATED:** The legacy `tavilyApiKey` configuration is still supported for backward compatibility but is deprecated: |
26 | 84 |
|
| 85 | +```json |
| 86 | +{ |
| 87 | + "advanced": { |
| 88 | + "tavilyApiKey": "tvly-xxxxx" // ⚠️ Deprecated |
| 89 | + } |
| 90 | +} |
27 | 91 | ``` |
28 | | -web_search(query="Your query goes here.") |
| 92 | + |
| 93 | +**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. |
| 94 | + |
| 95 | +## Disabling Web Search |
| 96 | + |
| 97 | +If you want to disable the web search functionality, you can exclude the `web_search` tool in your `settings.json`: |
| 98 | + |
| 99 | +```json |
| 100 | +{ |
| 101 | + "tools": { |
| 102 | + "exclude": ["web_search"] |
| 103 | + } |
| 104 | +} |
29 | 105 | ``` |
30 | 106 |
|
31 | | -## `web_search` examples |
| 107 | +**Note:** This setting requires a restart of Qwen Code to take effect. Once disabled, the `web_search` tool will not be available to the model, even if web search providers are configured. |
| 108 | + |
| 109 | +## Usage Examples |
32 | 110 |
|
33 | | -Get information on a topic: |
| 111 | +### Basic search (using default provider) |
34 | 112 |
|
35 | 113 | ``` |
36 | | -web_search(query="latest advancements in AI-powered code generation") |
| 114 | +web_search(query="latest advancements in AI") |
| 115 | +``` |
| 116 | + |
| 117 | +### Search with specific provider |
| 118 | + |
37 | 119 | ``` |
| 120 | +web_search(query="latest advancements in AI", provider="tavily") |
| 121 | +``` |
| 122 | + |
| 123 | +### Real-world examples |
| 124 | + |
| 125 | +``` |
| 126 | +web_search(query="weather in San Francisco today") |
| 127 | +web_search(query="latest Node.js LTS version", provider="google") |
| 128 | +web_search(query="best practices for React 19", provider="dashscope") |
| 129 | +``` |
| 130 | + |
| 131 | +## Provider Details |
| 132 | + |
| 133 | +### DashScope (Official) |
| 134 | + |
| 135 | +- **Cost:** Free |
| 136 | +- **Authentication:** Automatically available when using Qwen OAuth authentication |
| 137 | +- **Configuration:** No API key required, automatically added to provider list for Qwen OAuth users |
| 138 | +- **Quota:** 200 requests/minute, 2000 requests/day |
| 139 | +- **Best for:** General queries, always available as fallback for Qwen OAuth users |
| 140 | +- **Auto-registration:** If you're using Qwen OAuth, DashScope is automatically added to your provider list even if you don't configure it explicitly |
| 141 | + |
| 142 | +### Tavily |
| 143 | + |
| 144 | +- **Cost:** Requires API key (paid service with free tier) |
| 145 | +- **Sign up:** https://tavily.com |
| 146 | +- **Features:** High-quality results with AI-generated answers |
| 147 | +- **Best for:** Research, comprehensive answers with citations |
| 148 | + |
| 149 | +### Google Custom Search |
| 150 | + |
| 151 | +- **Cost:** Free tier available (100 queries/day) |
| 152 | +- **Setup:** |
| 153 | + 1. Enable Custom Search API in Google Cloud Console |
| 154 | + 2. Create a Custom Search Engine at https://programmablesearchengine.google.com |
| 155 | +- **Features:** Google's search quality |
| 156 | +- **Best for:** Specific, factual queries |
| 157 | + |
| 158 | +## Important Notes |
| 159 | + |
| 160 | +- **Response format:** Returns a concise answer with numbered source citations |
| 161 | +- **Citations:** Source links are appended as a numbered list: [1], [2], etc. |
| 162 | +- **Multiple providers:** If one provider fails, manually specify another using the `provider` parameter |
| 163 | +- **DashScope availability:** Automatically available for Qwen OAuth users, no configuration needed |
| 164 | +- **Default provider selection:** The system automatically selects a default provider based on availability: |
| 165 | + 1. Your explicit `default` configuration (highest priority) |
| 166 | + 2. CLI argument `--web-search-default` |
| 167 | + 3. First available provider by priority: Tavily > Google > DashScope |
| 168 | + |
| 169 | +## Troubleshooting |
| 170 | + |
| 171 | +**Tool not available?** |
| 172 | + |
| 173 | +- **For Qwen OAuth users:** The tool is automatically registered with DashScope provider, no configuration needed |
| 174 | +- **For other authentication types:** Ensure at least one provider (Tavily or Google) is configured |
| 175 | +- For Tavily/Google: Verify your API keys are correct |
| 176 | + |
| 177 | +**Provider-specific errors?** |
| 178 | + |
| 179 | +- Use the `provider` parameter to try a different search provider |
| 180 | +- Check your API quotas and rate limits |
| 181 | +- Verify API keys are properly set in configuration |
38 | 182 |
|
39 | | -## Important notes |
| 183 | +**Need help?** |
40 | 184 |
|
41 | | -- **Response returned:** The `web_search` tool returns a concise answer when available, with a list of source links. |
42 | | -- **Citations:** Source links are appended as a numbered list. |
43 | | -- **API key:** Configure `TAVILY_API_KEY` via settings.json, environment variables, .env files, or command line arguments. If not configured, the tool is not registered. |
| 185 | +- Check your configuration: Run `qwen` and use the settings dialog |
| 186 | +- View your current settings in `~/.qwen-code/settings.json` (macOS/Linux) or `%USERPROFILE%\.qwen-code\settings.json` (Windows) |
0 commit comments