> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2-update-deprecated-models.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Tavily

**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](https://tavily.com/).

```shell theme={null}
uv pip install -U tavily-python
```

```shell theme={null}
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.

```python cookbook/14_tools/tavily_tools.py theme={null}
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

| Parameter               | Type                           | Default      | Description                                                                                                                                                                                                                                 |
| ----------------------- | ------------------------------ | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `api_key`               | `Optional[str]`                | `None`       | Tavily API key. If not provided, will use TAVILY\_API\_KEY environment variable.                                                                                                                                                            |
| `api_base_url`          | `Optional[str]`                | `None`       | Tavily 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](https://api.tavily.com)). |
| `enable_search`         | `bool`                         | `True`       | Enable search functionality.                                                                                                                                                                                                                |
| `enable_search_context` | `bool`                         | `False`      | Enable search context functionality using Tavily's context API.                                                                                                                                                                             |
| `all`                   | `bool`                         | `False`      | Enable all available functions in the toolkit.                                                                                                                                                                                              |
| `max_tokens`            | `int`                          | `6000`       | Maximum number of tokens to use in search results.                                                                                                                                                                                          |
| `include_answer`        | `bool`                         | `True`       | Whether to include an AI-generated answer summary in the response.                                                                                                                                                                          |
| `search_depth`          | `Literal['basic', 'advanced']` | `'advanced'` | Depth of search - 'basic' for faster results or 'advanced' for more comprehensive search.                                                                                                                                                   |
| `format`                | `Literal['json', 'markdown']`  | `'markdown'` | Output format - 'json' for raw data or 'markdown' for formatted text.                                                                                                                                                                       |

## Toolkit Functions

| Function                  | Description                                                                                                                                                                                                                                                                    |
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `web_search_using_tavily` | Search 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_tavily`  | Alternative 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

* View [Tools](https://github.com/agno-agi/agno/blob/main/libs/agno/agno/tools/tavily.py)
