主题
SerpApi Google 搜索工具
SerpApiGoogleSearchTool使用 SerpApi 服务执行 Google 搜索。
SerpApiGoogleSearchTool
描述
使用 SerpApiGoogleSearchTool 通过 SerpApi 运行 Google 搜索并检索结构化结果。需要 SerpApi API 密钥。
安装
shell
uv add crewai-tools[serpapi]环境变量
SERPAPI_API_KEY(必填):SerpApi 的 API 密钥。在 https://serpapi.com/ 创建一个(提供免费套餐)。
示例
python
from crewai import Agent, Task, Crew
from crewai_tools import SerpApiGoogleSearchTool
tool = SerpApiGoogleSearchTool()
agent = Agent(
role="Researcher",
goal="Answer questions using Google search",
backstory="Search specialist",
tools=[tool],
verbose=True,
)
task = Task(
description="Search for the latest CrewAI releases",
expected_output="A concise list of relevant results with titles and links",
agent=agent,
)
crew = Crew(agents=[agent], tasks=[task])
result = crew.kickoff()说明
- 在环境中设置
SERPAPI_API_KEY。在 https://serpapi.com/ 创建密钥 - 另请参阅通过 SerpApi 进行 Google Shopping:
/en/tools/search-research/serpapi-googleshoppingtool
参数
运行参数
search_query(str,必填):Google 查询。location(str,可选):地理位置参数。
说明
- 此工具封装 SerpApi 并返回结构化搜索结果。