TavilySearchTool provides an interface to the Tavily Search API, enabling CrewAI agents to perform comprehensive web searches. It allows for specifying search depth, topics, time ranges, included/excluded domains, and whether to include direct answers, raw content, or images in the results.
Installation
To use theTavilySearchTool, you need to install the tavily-python library:
Environment Variables
Ensure your Tavily API key is set as an environment variable:Example Usage
Hereโs how to initialize and use theTavilySearchTool within a CrewAI agent:
Configuration Options
TheTavilySearchTool accepts the following arguments during initialization or when calling the run method:
query(str): Required. The search query string.search_depth(Literal[โbasicโ, โadvancedโ], optional): The depth of the search. Defaults to"basic".topic(Literal[โgeneralโ, โnewsโ, โfinanceโ], optional): The topic to focus the search on. Defaults to"general".time_range(Literal[โdayโ, โweekโ, โmonthโ, โyearโ], optional): The time range for the search. Defaults toNone.days(int, optional): The number of days to search back. Relevant iftime_rangeis not set. Defaults to7.max_results(int, optional): The maximum number of search results to return. Defaults to5.include_domains(Sequence[str], optional): A list of domains to prioritize in the search. Defaults toNone.exclude_domains(Sequence[str], optional): A list of domains to exclude from the search. Defaults toNone.include_answer(Union[bool, Literal[โbasicโ, โadvancedโ]], optional): Whether to include a direct answer synthesized from the search results. Defaults toFalse.include_raw_content(bool, optional): Whether to include the raw HTML content of the searched pages. Defaults toFalse.include_images(bool, optional): Whether to include image results. Defaults toFalse.timeout(int, optional): The request timeout in seconds. Defaults to60.
Advanced Usage
You can configure the tool with custom parameters:Features
- Comprehensive Search: Access to Tavilyโs powerful search index
- Configurable Depth: Choose between basic and advanced search modes
- Topic Filtering: Focus searches on general, news, or finance topics
- Time Range Control: Limit results to specific time periods
- Domain Control: Include or exclude specific domains
- Direct Answers: Get synthesized answers from search results
- Content Filtering: Prevent context window issues with automatic content truncation
Response Format
The tool returns search results as a JSON string containing:- Search results with titles, URLs, and content snippets
- Optional direct answers to queries
- Optional image results
- Optional raw HTML content (when enabled)
