|
1 | 1 | # Web Search Tool |
2 | 2 |
|
3 | | -Search the web using the Brave Search API. |
| 3 | +Search the web using multiple providers with automatic detection. |
4 | 4 |
|
5 | 5 | ## Description |
6 | 6 |
|
7 | 7 | Returns titles, URLs, and snippets for search results. Use when you need current information, research topics, or find websites. |
8 | 8 |
|
| 9 | +Supports multiple search providers: |
| 10 | +- **Brave Search API** (default, for backward compatibility) |
| 11 | +- **Google Custom Search API** (fallback) |
| 12 | + |
9 | 13 | ## Arguments |
10 | 14 |
|
11 | 15 | | Argument | Type | Required | Default | Description | |
12 | 16 | |----------|------|----------|---------|-------------| |
13 | 17 | | `query` | str | Yes | - | The search query (1-500 chars) | |
14 | | -| `num_results` | int | No | `10` | Number of results to return (1-20) | |
15 | | -| `country` | str | No | `us` | Country code for localized results (us, uk, de, etc.) | |
| 18 | +| `num_results` | int | No | `10` | Number of results (1-10 for Google, 1-20 for Brave) | |
| 19 | +| `country` | str | No | `us` | Country code for localized results | |
| 20 | +| `language` | str | No | `en` | Language code (Google only) | |
| 21 | +| `provider` | str | No | `auto` | Provider: "auto", "google", or "brave" | |
16 | 22 |
|
17 | 23 | ## Environment Variables |
18 | 24 |
|
| 25 | +Set credentials for at least one provider: |
| 26 | + |
| 27 | +### Option 1: Google Custom Search |
| 28 | +| Variable | Required | Description | |
| 29 | +|----------|----------|-------------| |
| 30 | +| `GOOGLE_API_KEY` | Yes | API key from [Google Cloud Console](https://console.cloud.google.com/) | |
| 31 | +| `GOOGLE_CSE_ID` | Yes | Search Engine ID from [Programmable Search Engine](https://programmablesearchengine.google.com/) | |
| 32 | + |
| 33 | +### Option 2: Brave Search |
19 | 34 | | Variable | Required | Description | |
20 | 35 | |----------|----------|-------------| |
21 | 36 | | `BRAVE_SEARCH_API_KEY` | Yes | API key from [Brave Search API](https://brave.com/search/api/) | |
22 | 37 |
|
| 38 | +## Provider Selection |
| 39 | + |
| 40 | +- `provider="auto"` (default): Uses Brave if available, otherwise Google (backward compatible) |
| 41 | +- `provider="brave"`: Force Brave Search |
| 42 | +- `provider="google"`: Force Google Custom Search |
| 43 | + |
| 44 | +## Example Usage |
| 45 | + |
| 46 | +```python |
| 47 | +# Auto-detect provider based on available credentials |
| 48 | +result = web_search(query="climate change effects") |
| 49 | + |
| 50 | +# Force specific provider |
| 51 | +result = web_search(query="python tutorial", provider="google") |
| 52 | +result = web_search(query="local news", provider="brave", country="id") |
| 53 | +``` |
| 54 | + |
23 | 55 | ## Error Handling |
24 | 56 |
|
25 | 57 | Returns error dicts for common issues: |
26 | | -- `BRAVE_SEARCH_API_KEY environment variable not set` - Missing API key |
| 58 | +- `No search credentials configured` - No API keys set |
| 59 | +- `Google credentials not configured` - Missing Google keys when provider="google" |
| 60 | +- `Brave credentials not configured` - Missing Brave key when provider="brave" |
27 | 61 | - `Query must be 1-500 characters` - Empty or too long query |
28 | | -- `Invalid API key` - API key rejected (HTTP 401) |
29 | | -- `Rate limit exceeded. Try again later.` - Too many requests (HTTP 429) |
| 62 | +- `Invalid API key` - API key rejected |
| 63 | +- `Rate limit exceeded` - Too many requests |
30 | 64 | - `Search request timed out` - Request exceeded 30s timeout |
31 | | -- `Network error: <error>` - Connection or DNS issues |
|
0 commit comments