Skip to main content
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.
uv pip install -U tavily-python
export TAVILY_API_KEY=***
# optional: use a self-hosted Tavily-compatible API endpoint
export TAVILY_API_BASE_URL=https://custom.tavily.com

Example

The following agent will run a search on Tavily for “language models” and print the response.
cookbook/14_tools/tavily_tools.py
from agno.agent import Agent
from agno.tools.tavily import TavilyTools

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

Toolkit Params

ParameterTypeDefaultDescription
api_keyOptional[str]NoneTavily API key. If not provided, will use TAVILY_API_KEY environment variable.
api_base_urlOptional[str]NoneTavily API base URL. If not provided, uses TAVILY_API_BASE_URL when set; if both are unset or None, falls back to the default base URL from the tavily-python client (for example, https://api.tavily.com).
enable_searchboolTrueEnable search functionality.
enable_search_contextboolFalseEnable search context functionality using Tavily’s context API.
allboolFalseEnable all available functions in the toolkit.
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.

Toolkit Functions

FunctionDescription
web_search_using_tavilySearch the web for a given query using Tavily API. Parameters include query (str) for the search query and max_results (int, default=5) for maximum number of results. Returns JSON string of results with titles, URLs, content and relevance scores in specified format.
web_search_with_tavilyAlternative search function that uses Tavily’s search context API. Parameters include query (str) for the search query. Returns contextualized search results. Only available when enable_search_context is True.

Developer Resources