Tavily Search
Tavily's Search API is a search engine built specifically for AI agents (LLMs), delivering real-time, accurate, and factual results at speed.
Overview
Integration details
Class | Package | Serializable | JS support | Package latest |
---|---|---|---|---|
TavilySearchResults | langchain-community | ❌ | ✅ |
Tool features
Returns artifact | Native async | Return data | Pricing |
---|---|---|---|
✅ | ✅ | Title, URL, content, answer | 1,000 free searches / month |
Setup
The integration lives in the langchain-community
package. We also need to install the tavily-python
package.
%pip install -qU "langchain-community>=0.2.11" tavily-python
Credentials
We also need to set our Tavily API key. You can get an API key by visiting this site and creating an account.
import getpass
import os
if not os.environ.get("TAVILY_API_KEY"):
os.environ["TAVILY_API_KEY"] = getpass.getpass("Tavily API key:\n")
It's also helpful (but not needed) to set up LangSmith for best-in-class observability:
# os.environ["LANGCHAIN_TRACING_V2"] = "true"
# os.environ["LANGCHAIN_API_KEY"] = getpass.getpass()
Instantiation
Here we show how to instantiate an instance of the Tavily search tools, with
from langchain_community.tools import TavilySearchResults
tool = TavilySearchResults(
max_results=5,
search_depth="advanced",
include_answer=True,
include_raw_content=True,
include_images=True,
# include_domains=[...],
# exclude_domains=[...],
# name="...", # overwrite default tool name
# description="...", # overwrite default tool description
# args_schema=..., # overwrite default args_schema: BaseModel
)
API Reference:TavilySearchResults