Tavily

Search and extract web content with TavilyTools, backed by the Tavily search and extract APIs.

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

Prerequisites

The following example requires the tavily-python and openai libraries and an API key from Tavily.

uv pip install -U agno tavily-python openai
export TAVILY_API_KEY=***
# optional: use a self-hosted Tavily-compatible API endpoint
# export TAVILY_API_BASE_URL=https://your-tavily-compatible-endpoint

Example

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

cookbook/91_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_contextboolFalseSelect the context helper instead of ordinary search; requires enable_search=True or all=True.
enable_extractboolFalseEnable URL content extraction functionality.
allboolFalseEnable extraction and one search implementation, selected by enable_search_context.
max_tokensint6000Ordinary search: serialized-character budget for adding results, not a hard output bound; the answer is retained. Context search: forwarded to the SDK as max_tokens.
include_answerboolTrueWhether to include an AI-generated answer summary in the response.
search_depthLiteral['basic', 'advanced', 'fast', 'ultra-fast']'advanced'Depth of search - 'basic' (1 credit), 'advanced' (2 credits), 'fast', or 'ultra-fast'.
extract_depthLiteral['basic', 'advanced']'basic'Extraction depth - 'basic' (1 credit/5 URLs) or 'advanced' (2 credits/5 URLs).
include_imagesboolFalseRequest images from Tavily; the formatted toolkit output omits the image fields.
include_faviconboolFalseRequest favicons from Tavily; the formatted toolkit output omits favicon fields.
extract_timeoutOptional[int]NoneTimeout in seconds for extraction requests.
extract_formatLiteral['markdown', 'text']'markdown'Wrapper heading style; not forwarded as the provider extraction format. Text output can still contain Markdown.
formatLiteral['json', 'markdown']'markdown'Output format - 'json' for raw data or 'markdown' for formatted text.
topicOptional[Literal['general', 'news', 'finance']]NoneSearch category - general, news, or finance.
time_rangeOptional[Literal['day', 'week', 'month', 'year', 'd', 'w', 'm', 'y']]NoneTime window for results - day, week, month, year (or d/w/m/y).
start_dateOptional[str]NoneOnly include results published after this date (YYYY-MM-DD).
end_dateOptional[str]NoneOnly include results published before this date (YYYY-MM-DD).
daysOptional[int]NoneNumber of days back to include results. Applies to the news topic only.
include_domainsOptional[List[str]]NoneRestrict results to these domains.
exclude_domainsOptional[List[str]]NoneExclude these domains from results.
countryOptional[str]NoneBoost results from this country (e.g., 'united states').
auto_parametersboolFalseLet Tavily auto-tune search parameters. Explicitly set values (including the always-sent search_depth and include_answer) take precedence.
chunks_per_sourceOptional[int]NoneNumber of content chunks per source (1-3). Advanced search only.
search_paramsOptional[Dict[str, Any]]NoneAdditional parameters merged into web search requests. Overrides named parameters on key collision.

The context helper forwards only query, search_depth, and max_tokens. Domain, date, topic, and other search options in this table, including search_params, apply to ordinary search.

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 selected result fields as JSON or Markdown according to 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. Selected when enable_search_context=True and search is enabled.
extract_url_contentExtract content from one or more URLs using Tavily's Extract API. Parameters include urls (str), a single URL or comma-separated URLs. Returns extracted content in the configured extract_format (markdown or text). Only available when enable_extract or all is True.

Developer Resources