Skip to content
CrewAI 文档版本 跟随上游 源快照 953ad162 更新于 2026-10-18

Apify Actors

ApifyActorsTool 让你可以调用 Apify Actors,为你的 CrewAI 工作流提供网页抓取、爬取、数据提取和网页自动化能力。

ApifyActorsTool

将 Apify Actors 集成到你的 CrewAI 工作流中。

描述

ApifyActorsTool 将 Apify Actors(用于网页抓取和自动化的云端程序)接入你的 CrewAI 工作流。 可使用 Apify Store 上的 4,000+ 个 Actors,适用于从社交媒体、搜索引擎、在线地图、电商网站、旅行门户或普通网站提取数据等场景。

详情请参阅 Apify 文档中的 Apify CrewAI 集成。

入门步骤

Install dependencies

使用 pip 安装 crewai[tools] 和 langchain-apify:pip install 'crewai[tools]' langchain-apify。

Obtain an Apify API token

注册 Apify Console 并获取你的 Apify API token..

Configure environment

将你的 Apify API token 设置为 APIFY_API_TOKEN 环境变量,以启用该工具的功能。

使用示例

手动使用 ApifyActorsTool 运行 RAG Web Browser Actor 来执行网页搜索:

python
from crewai_tools import ApifyActorsTool

# Initialize the tool with an Apify Actor
tool = ApifyActorsTool(actor_name="apify/rag-web-browser")

# Run the tool with input parameters
results = tool.run(run_input={"query": "What is CrewAI?", "maxResults": 5})

# Process the results
for result in results:
    print(f"URL: {result['metadata']['url']}")
    print(f"Content: {result.get('markdown', 'N/A')[:100]}...")

预期输出

以下是运行上述代码的输出:

text
URL: https://www.example.com/crewai-intro
Content: CrewAI is a framework for building AI-powered workflows...
URL: https://docs.crewai.com/
Content: Official documentation for CrewAI...

ApifyActorsTool 会使用提供的 actor_name 自动从 Apify 获取 Actor 定义和输入 schema,然后据此构建工具描述和参数 schema。这意味着你只需指定一个有效的 actor_name,在与智能体一起使用时其余工作由工具处理——无需指定 run_input。其工作方式如下:

python
from crewai import Agent
from crewai_tools import ApifyActorsTool

rag_browser = ApifyActorsTool(actor_name="apify/rag-web-browser")

agent = Agent(
    role="Research Analyst",
    goal="Find and summarize information about specific topics",
    backstory="You are an experienced researcher with attention to detail",
    tools=[rag_browser],
)

你只需更改 actor_name 即可运行 Apify Store 中的其他 Actors;手动使用时,再根据 Actor 的输入 schema 调整 run_input。

有关与智能体配合使用的示例,请参阅 CrewAI Actor 模板。

配置

ApifyActorsTool 需要以下输入才能工作:

  • actor_name 要运行的 Apify Actor 的 ID,例如 "apify/rag-web-browser"。可在 Apify Store 浏览所有 Actors。
  • run_input 手动运行该工具时传给 Actor 的输入参数字典。
    • 例如,对于 apify/rag-web-browser Actor:{"query": "search term", "maxResults": 5}
    • 输入参数列表请参见该 Actor 的输入 schema。

资源

BytesRouter 是社区翻译站点,所有译文仅供参考,一切以官方英文原文为准。