Apify Actors
ApifyActorsTool
Section titled “ApifyActorsTool”将 Apify Actors 集成到你的 CrewAI 工作流中。
ApifyActorsTool 将 Apify Actors 连接到你的 CrewAI 工作流。Apify Actors 是运行在云端的网页抓取和自动化程序。
你可以使用 Apify Store 上 4,000 多个 Actor,适用于从社交媒体、搜索引擎、在线地图、电商网站、旅行门户或通用网站提取数据等场景。
更多详情请参阅 Apify 文档中的 Apify CrewAI 集成。
- 安装依赖
使用 pip 安装
crewai[tools]和langchain-apify:pip install 'crewai[tools]' langchain-apify。 - 获取 Apify API token
注册 Apify Console,然后获取你的 Apify API token。
- 配置环境
将你的 Apify API token 设置为
APIFY_API_TOKEN环境变量,以启用该工具功能。
手动使用 ApifyActorsTool 运行 RAG Web Browser Actor 执行网页搜索:
from crewai_tools import ApifyActorsTool
# Initialize the tool with an Apify Actortool = ApifyActorsTool(actor_name="apify/rag-web-browser")
# Run the tool with input parametersresults = tool.run(run_input={"query": "What is CrewAI?", "maxResults": 5})
# Process the resultsfor result in results: print(f"URL: {result['metadata']['url']}") print(f"Content: {result.get('markdown', 'N/A')[:100]}...")下面是上述代码的输出:
URL: https://www.example.com/crewai-introContent: 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 Agentfrom 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-browserActor:{"query": "search term", "maxResults": 5} - 具体输入参数请查看该 Actor 的 input schema。
- 例如,对于
- Apify:探索 Apify 平台。
- How to build an AI agent on Apify - 在 Apify 平台上创建、发布和变现 AI agents 的完整分步指南。
- RAG Web Browser Actor:一个面向 LLM 网页搜索的热门 Actor。
- CrewAI Integration Guide:查看 Apify 与 CrewAI 集成的官方指南。