Prerequisites
The following example requires therequests and openai libraries and an API key from SearchAPI.io.
Example
The following agent will search Google for the latest AI developments.cookbook/91_tools/searchapi_tools.py
Toolkit Params
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | Optional[str] | None | SearchAPI key. If not provided, uses SEARCHAPI_API_KEY environment variable. |
num_results | int | 5 | Default number of results to return per search. |
timeout | int | 30 | Request timeout in seconds. |
enable_search_google | bool | True | Enable Google web search. |
enable_search_news | bool | False | Enable Google News search. |
enable_search_images | bool | False | Enable Google Images search. |
enable_search_youtube | bool | False | Enable YouTube search. |
all | bool | False | Enable all available search functions. |
Toolkit Functions
| Function | Description |
|---|---|
search_google | Search Google. Parameters: query (str), num_results (int), location (str, optional), language (str, optional). Returns organic results, knowledge graph, and related questions. |
search_news | Search Google News. Parameters: query (str), num_results (int), country (str, optional), language (str, optional). Returns news articles with title, source, date, and snippet. |
search_images | Search Google Images. Parameters: query (str), num_results (int), safe_search (str, optional). Returns image results with title, link, and thumbnail. |
search_youtube | Search YouTube. Parameters: query (str), num_results (int). Returns video results with title, link, channel, length, and views. |