跳转到主要内容

ApifyActorsTool

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

描述

ApifyActorsToolApify Actors(基于云的网络抓取和自动化程序)连接到您的 CrewAI 工作流。利用 Apify Store 上的 4000 多个 Actor,用于从社交媒体、搜索引擎、在线地图、电子商务网站、旅游门户或通用网站提取数据等用例。 有关详细信息,请参阅 Apify 文档中的 Apify CrewAI 集成

入门步骤

1

安装依赖项

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

获取 Apify API 令牌

注册 Apify Console 并获取您的 Apify API 令牌
3

配置环境

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

使用示例

手动使用 ApifyActorsTool 运行 RAG Web 浏览器 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 定义和输入模式,然后构建工具描述和参数模式。这意味着您只需指定一个有效的 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,并在手动使用时根据 Actor 输入模式调整 run_input 来运行 Apify Store 中的其他 Actor。 有关与代理一起使用的示例,请参阅 CrewAI Actor 模板

配置

ApifyActorsTool 需要以下输入才能工作
  • actor_name 要运行的 Apify Actor 的 ID,例如 "apify/rag-web-browser"。在 Apify Store 上浏览所有 Actor。
  • run_input 手动运行工具时,Actor 的输入参数字典。
    • 例如,对于 apify/rag-web-browser Actor:{"query": "搜索词", "maxResults": 5}
    • 有关输入参数列表,请参阅 Actor 的输入模式

资源