Warning: TheThe langchain-tavily Python package is the official LangChain integration of Tavily, including Search, Extract, Map, and Crawl functionality.langchain_community.tools.tavily_search.toolis deprecated. While it remains functional for now, we strongly recommend migrating to the newlangchain-tavilyPython package which supports Search, Extract, Map, and Crawl functionality and receives continuous updates with the latest features.
Installation
Credentials
We also need to set our Tavily API key. You can get an API key by visiting this site and creating an account.Tavily Search
Here we show how to instantiate the Tavily search tool. This tool allows you to complete search queries using Tavily’s Search API endpoint.Available Parameters
The Tavily Search API accepts various parameters to customize the search:max_results(optional, int): Maximum number of search results to return. Default is 5.topic(optional, str): Category of the search. Can be “general”, “news”, or “finance”. Default is “general”.include_answer(optional, bool): Include an answer to original query in results. Default is False.include_raw_content(optional, bool): Include cleaned and parsed HTML of each search result. Default is False.include_images(optional, bool): Include a list of query related images in the response. Default is False.include_image_descriptions(optional, bool): Include descriptive text for each image. Default is False.search_depth(optional, str): Depth of the search, either “basic” or “advanced”. Default is “basic”.time_range(optional, str): The time range back from the current date ( publish date ) to filter results - “day”, “week”, “month”, or “year”. Default is None.start_date(optional, str): Will return all results after the specified start date ( publish date ). Required to be written in the format YYYY-MM-DD. Default is None.end_date(optional, str): Will return all results before the specified end date. Required to be written in the format YYYY-MM-DD. Default is None.include_domains(optional, List[str]): List of domains to specifically include. Maximum 300 domains. Default is None.exclude_domains(optional, List[str]): List of domains to specifically exclude. Maximum 150 domains. Default is None.
Instantiation
Invoke directly with args
The Tavily search tool accepts the following arguments during invocation:query(required): A natural language search query- The following arguments can also be set during invocation:
include_images,search_depth,time_range,include_domains,exclude_domains,start_date,end_date - For reliability and performance reasons, certain parameters that affect response size cannot be modified during invocation:
include_answerandinclude_raw_content. These limitations prevent unexpected context window issues and ensure consistent results.
Direct Tool Invocation
Use with Agent
Tip: For more relevant and time-aware results, inject today’s date into your system prompt. This helps the agent understand the current context when searching for recent information. For example: f"You are a helpful research assistant. Today's date is {datetime.today().strftime('%B %d, %Y')}. Use web search to find accurate, up-to-date information."
Tavily Extract
Here we show how to instantiate the Tavily extract tool. This tool allows you to extract content from URLs using Tavily’s Extract API endpoint.Available Parameters
The Tavily Extract API accepts various parameters:extract_depth(optional, str): The depth of the extraction, either “basic” or “advanced”. Default is “basic”.include_images(optional, bool): Whether to include images in the extraction. Default is False.
Instantiation
Invoke directly with args
The Tavily extract tool accepts the following arguments during invocation:urls(required): A list of URLs to extract content from.- Both
extract_depthandinclude_imagescan also be set during invocation
Direct Tool Invocation
Tavily Map/Crawl
Tavily provides two complementary tools for website exploration: Map and Crawl. Themap tool discovers and lists URLs from a website, providing a structural overview without extracting content. The crawl tool then extracts the full content from these discovered URLs, making it ideal for data extraction, documentation indexing, and building knowledge bases.
Tavily Map
The Map tool discovers all internal links starting from a base URL, perfect for understanding site structure or planning content extraction.Available Parameters
url(required, str): The root URL to begin mapping.instructions(optional, str): Natural language instructions guiding the mapping process.
Instantiation
Direct Tool Invocation
Tavily Crawl
The Crawl tool extracts full content from URLs. It works perfectly with mapped URLs or can be used standalone to crawl from a starting point.Available Parameters
url(required, str): The root URL to begin the crawl.instructions(optional, str): Natural language instructions guiding content extraction.
Instantiation
Direct Tool Invocation
Tavily Research Agent
This example demonstrates how to build a powerful web research agent using Tavily’s search and extract tools withcreate_agent.
Features
- Internet Search: Query the web for up-to-date information using Tavily’s search API
- Content Extraction: Extract and analyze specific content from web pages
- Seamless Integration: Simple, elegant agent setup with LangChain v1
Tip: For more relevant and time-aware results, inject today’s date into your system prompt. This helps the agent understand the current context when searching for recent information. For example: f"You are a helpful research assistant. Today's date is {datetime.today().strftime('%B %d, %Y')}. Use web search to find relevant information..."