# Tavily

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

### [​](https://docs.phidata.com/tools/tavily#prerequisites)Prerequisites <a href="#prerequisites" id="prerequisites"></a>

The following examples requires the `tavily-python` library and an API key from [Tavily](https://tavily.com/).

```shell
pip install -U tavily-python
```

```shell
export TAVILY_API_KEY=***
```

### [​](https://docs.phidata.com/tools/tavily#example)Example <a href="#example" id="example"></a>

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

cookbook/tools/tavily\_tools.py

```python
from bitca.agent import Agent
from bitca.tools.tavily import TavilyTools

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

### [​](https://docs.phidata.com/tools/tavily#toolkit-params)Toolkit Params <a href="#toolkit-params" id="toolkit-params"></a>

| 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.                          |

### [​](https://docs.phidata.com/tools/tavily#toolkit-functions)Toolkit Functions <a href="#toolkit-functions" id="toolkit-functions"></a>

| 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.                        |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.projectbit.ca/documentation/tools/tavily.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
