> ## Documentation Index
> Fetch the complete documentation index at: https://docs.phidata.com/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}
pip install -U tavily-python
```

```shell theme={null}
export TAVILY_API_KEY=***
```

## Example

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

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

| Parameter            | Type                           | Default      | Description                                                                                    |
| -------------------- | ------------------------------ | ------------ | ---------------------------------------------------------------------------------------------- |
| `api_key`            | `str`                          | -            | API key for authentication. If not provided, will check TAVILY\_API\_KEY environment variable. |
| `search`             | `bool`                         | `True`       | Enables search functionality.                                                                  |
| `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.                          |
| `use_search_context` | `bool`                         | `False`      | Whether to use Tavily's search context API instead of regular search.                          |

## Toolkit Functions

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

* View on [Github](https://github.com/agno-agi/phidata/blob/main/phi/tools/tavily.py)
