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

# Tavily

**TavilyTools** 使 Agent 能够使用 Tavily API 搜索网络。

## 先决条件

以下示例需要 `tavily-python` 库和来自 [Tavily](https://tavily.com/) 的 API 密钥。

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

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

## 示例

下面的 agent 将在 Tavily 上搜索“language models”并打印响应。

```python cookbook/tools/tavily_tools.py theme={null}
from agno.agent import Agent
from agno.tools.tavily import TavilyTools

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

## Toolkit 参数

| 参数                   | 类型                             | 默认值          | 描述                                              |
| -------------------- | ------------------------------ | ------------ | ----------------------------------------------- |
| `api_key`            | `str`                          | -            | 用于身份验证的 API 密钥。如果未提供，将检查 TAVILY\_API\_KEY 环境变量。 |
| `search`             | `bool`                         | `True`       | 启用搜索功能。                                         |
| `max_tokens`         | `int`                          | `6000`       | 搜索结果中使用的最大 token 数。                             |
| `include_answer`     | `bool`                         | `True`       | 是否在响应中包含 AI 生成的答案摘要。                            |
| `search_depth`       | `Literal['basic', 'advanced']` | `'advanced'` | 搜索深度 - 'basic' 用于更快的结果，或 'advanced' 用于更全面的搜索。   |
| `format`             | `Literal['json', 'markdown']`  | `'markdown'` | 输出格式 - 'json' 用于原始数据或 'markdown' 用于格式化文本。       |
| `use_search_context` | `bool`                         | `False`      | 是否使用 Tavily 的搜索上下文 API 而不是常规搜索。                 |

## Toolkit 功能

| 功能                        | 描述                                                                                         |
| ------------------------- | ------------------------------------------------------------------------------------------ |
| `web_search_using_tavily` | 使用 Tavily API 搜索特定查询的网络。接受一个查询字符串和可选的 max\_results 参数（默认为 5）。以指定的格式返回结果，包括标题、URL、内容和相关性分数。 |
| `web_search_with_tavily`  | 使用 Tavily 搜索上下文 API 的替代搜索功能。接受一个查询字符串并返回情境化搜索结果。仅当 use\_search\_context 为 True 时可用。        |

## 开发者资源

* 查看 [Tools](https://github.com/agno-agi/agno/blob/main/libs/agno/agno/tools/tavily.py)
* 查看 [Cookbook](https://github.com/agno-agi/agno/blob/main/cookbook/tools/tavily_tools.py)
