TavilyTools enable an Agent to search the web using the Tavily API.

Prerequisites

The following examples requires the tavily-python library and an API key from Tavily.

pip install -U tavily-python
export TAVILY_API_KEY=***

Example

The following agent will run a search on Tavily for “language models” and print the response.

cookbook/tools/tavily_tools.py
from phi.agent import Agent
from phi.tools.tavily import TavilyTools

agent = Agent(tools=[TavilyTools()], show_tool_calls=True)
agent.print_response("Search tavily for 'language models'", markdown=True)

Toolkit Params

ParameterTypeDefaultDescription
api_keystr-API key for authentication. If not provided, will check TAVILY_API_KEY environment variable.
searchboolTrueEnables search functionality.
max_tokensint6000Maximum number of tokens to use in search results.
include_answerboolTrueWhether to include an AI-generated answer summary in the response.
search_depthLiteral['basic', 'advanced']'advanced'Depth of search - ‘basic’ for faster results or ‘advanced’ for more comprehensive search.
formatLiteral['json', 'markdown']'markdown'Output format - ‘json’ for raw data or ‘markdown’ for formatted text.
use_search_contextboolFalseWhether to use Tavily’s search context API instead of regular search.

Toolkit Functions

FunctionDescription
web_search_using_tavilySearches the web for a query using Tavily API. Takes a query string and optional max_results parameter (default 5). Returns results in specified format with titles, URLs, content and relevance scores.
web_search_with_tavilyAlternative search function that uses Tavily’s search context API. Takes a query string and returns contextualized search results. Only available if use_search_context is True.

Information