跳转到内容

Apify Actors

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

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

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

  1. 安装依赖

    使用 pip 安装 crewai[tools]langchain-apifypip install 'crewai[tools]' langchain-apify

  2. 获取 Apify API token

    注册 Apify Console,然后获取你的 Apify API token

  3. 配置环境

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

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

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]}...")

下面是上述代码的输出:

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,当它与 agents 一起使用时,工具会自动处理其余部分 - 无需指定 run_input。工作方式如下:

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 中的其他 Actor;在手动使用时,则根据 Actor 的输入 schema 调整 run_input 即可。

有关 agents 使用示例,请参阅 CrewAI Actor template

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

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