ApifyActorsTool

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

描述

ApifyActorsTool 连接 Apify Actors(基于云的网页抓取和自动化程序)到您的 CrewAI 工作流。您可以使用 Apify Store 上的 4000 多个 Actors,用于从社交媒体、搜索引擎、在线地图、电子商务网站、旅游门户或普通网站提取数据等用例。

详情请参阅 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.org.cn/
Content: Official documentation for CrewAI...

ApifyActorsTool 会自动使用提供的 actor_name 从 Apify 获取 Actor 定义和输入 schema,然后构建工具描述和参数 schema。这意味着您只需要指定一个有效的 actor_name,当与代理一起使用时,工具会处理其余部分——无需指定 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 运行其他 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": "搜索词", "maxResults": 5}
    • 有关输入参数列表,请参阅 Actor 的 输入 schema

资源