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

# Apify

本指南演示了如何在 Agno 框架中集成和使用 [Apify](https://apify.com/actors) Actor，以增强 AI Agent 的网络抓取、爬取、数据提取和网络自动化功能。

## 什么是 Apify？

[Apify](https://apify.com/) 是一个提供以下服务的平台：

* 为 AI Agent 提供数据收集服务，专注于从社交媒体、搜索引擎、在线地图、电子商务网站、旅游门户或常规网站提取数据
* 一个包含各种数据任务的现成 Actor（专用工具）的市场
* 运行和变现我们自己 AI Agent 的基础设施

## 前提条件

1. 注册一个 [Apify 账户](https://console.apify.com/sign-up)
2. 获取您的 Apify API 令牌（可从 [Apify](https://docs.apify.com/platform/integrations/api) 获取）
3. 安装所需包：

```bash theme={null}
pip install agno apify-client
```

## 基本用法

Agno 框架让集成 Apify Actor 到您的 Agent 中变得十分简单。以下是一个简单的示例：

```python theme={null}
from agno.agent import Agent
from agno.tools.apify import ApifyTools

# 创建一个包含 ApifyTools 的 Agent
agent = Agent(
    tools=[
        ApifyTools(
            actors=["apify/rag-web-browser"],  # 指定要使用的 Apify Actor，如果需要，可使用多个
            apify_api_token="your_apify_api_key"  # 或者设置 APIFY_API_TOKEN 环境变量
        )
    ],
    show_tool_calls=True,
    markdown=True
)

# 使用 Agent 获取网站内容
agent.print_response("What information can you find on https://docs.agno.com/introduction ?", markdown=True)
```

## 可用的 Apify 工具

您可以轻松地将任何 Apify Actor 集成作为工具。以下是一些示例：

### 1. RAG Web Browser

[RAG Web Browser](https://apify.com/apify/rag-web-browser) Actor 专为 AI 和 LLM 应用而设计。它会搜索查询的网页或处理 URL，然后清理和格式化内容供您的 Agent 使用。此工具默认启用。

```python theme={null}
from agno.agent import Agent
from agno.tools.apify import ApifyTools

agent = Agent(
    tools=[
        ApifyTools(actors=["apify/rag-web-browser"])
    ],
    show_tool_calls=True,
    markdown=True
)

# 搜索信息并处理结果
agent.print_response("What are the latest developments in large language models?", markdown=True)
```

### 2. Website Content Crawler

此工具使用 Apify 的 [Website Content Crawler](https://apify.com/apify/website-content-crawler) Actor 来提取网站的文本内容，非常适合 RAG 应用。

```python theme={null}
from agno.agent import Agent
from agno.tools.apify import ApifyTools

agent = Agent(
    tools=[
        ApifyTools(actors=["apify/website-content-crawler"])
    ],
    markdown=True
)

# 让 Agent 处理网页内容
agent.print_response("Summarize the content from https://docs.agno.com/introduction", markdown=True)
```

### 3. Google Places Crawler

[Google Places Crawler](https://apify.com/compass/crawler-google-places) 从 Google Maps 和 Google Places 提取有关企业的数据。

```python theme={null}
from agno.agent import Agent
from agno.tools.apify import ApifyTools

agent = Agent(
    tools=[
        ApifyTools(actors=["compass/crawler-google-places"])
    ],
    show_tool_calls=True
)

# 查找特定位置的企业信息
agent.print_response("What are the top-rated restaurants in San Francisco?", markdown=True)
agent.print_response("Find coffee shops in Prague", markdown=True)
```

## 示例场景

### RAG Web Browser + Google Places Crawler

此示例结合了网络搜索和本地企业数据，以提供关于主题的全面信息：

```python theme={null}
from agno.agent import Agent
from agno.tools.apify import ApifyTools

agent = Agent(
    tools=[
        ApifyTools(actors=[
            "apify/rag-web-browser",
            "compass/crawler-google-places"
        ])
    ],
    show_tool_calls=True
)

# 获取一般信息和本地商家信息
agent.print_response(
    """
    我下个月要去东京旅行。
    1. 研究最佳旅行时间和主要景点
    2. 在新宿附近找一家评价好的寿司餐厅
    根据这些信息整理一份全面的旅行指南。
    """,
    markdown=True
)
```

## Toolkit 参数

| 参数                | 类型                  | 默认值    | 描述                                         |
| ----------------- | ------------------- | ------ | ------------------------------------------ |
| `apify_api_token` | `str`               | `None` | Apify API 令牌（或通过 APIFY\_API\_TOKEN 环境变量设置） |
| `actors`          | `str` 或 `List[str]` | `None` | 单个 Actor ID 或要注册的 Actor ID 列表              |

## 开发者资源

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

## 资源

* [Apify Actor 文档](https://docs.apify.com/Actors)
* [Apify Store - 浏览可用 Actor](https://apify.com/store)
* [如何在 Apify 上构建和变现 AI Agent](https://blog.apify.com/how-to-build-an-ai-agent/)
