主题
Linkup 搜索工具
LinkupSearchTool支持查询 Linkup API 以获取上下文信息。
LinkupSearchTool
描述
LinkupSearchTool 提供了查询 Linkup API 以获取上下文信息并检索结构化结果的能力。此工具非常适合用来自 Linkup 的最新可靠信息丰富工作流,使智能体能够在任务期间访问相关数据。
安装
要使用此工具,你需要安装 Linkup SDK:
shell
uv add linkup-sdk入门步骤
要有效使用 LinkupSearchTool,请按以下步骤操作:
- API 密钥:获取 Linkup API 密钥。
- 环境设置:使用 API 密钥设置你的环境。
- 安装 SDK:使用上面的命令安装 Linkup SDK。
示例
以下示例演示如何初始化该工具并在智能体中使用它:
python
from crewai_tools import LinkupSearchTool
from crewai import Agent
import os
# Initialize the tool with your API key
linkup_tool = LinkupSearchTool(api_key=os.getenv("LINKUP_API_KEY"))
# Define an agent that uses the tool
@agent
def researcher(self) -> Agent:
'''
This agent uses the LinkupSearchTool to retrieve contextual information
from the Linkup API.
'''
return Agent(
config=self.agents_config["researcher"],
tools=[linkup_tool]
)参数
LinkupSearchTool 接受以下参数:
构造函数参数
- api_key:必填。你的 Linkup API 密钥。
运行参数
- query:必填。搜索词或短语。
- depth:可选。搜索深度。默认值为 "standard"。
- output_type:可选。输出类型。默认值为 "searchResults"。
高级用法
你可以自定义搜索参数以获得更具体的结果:
python
# Perform a search with custom parameters
results = linkup_tool.run(
query="Women Nobel Prize Physics",
depth="deep",
output_type="searchResults"
)返回格式
该工具按以下格式返回结果:
json
{
"success": true,
"results": [
{
"name": "Result Title",
"url": "https://example.com/result",
"content": "Content of the result..."
},
// Additional results...
]
}如果发生错误,响应将为:
json
{
"success": false,
"error": "Error message"
}错误处理
该工具会优雅地处理 API 错误并提供结构化反馈。如果 API 请求失败,该工具将返回一个包含 success: false 和错误消息的字典。
结论
LinkupSearchTool 提供了一种无缝方式,可将 Linkup 的上下文信息检索能力集成到你的 CrewAI 智能体中。通过利用此工具,智能体可以访问相关且最新的信息,以增强其决策和任务执行。