LinkupSearchTool

描述

LinkupSearchTool 提供了查询 Linkup API 获取上下文信息并检索结构化结果的能力。此工具非常适合使用来自 Linkup 的最新可靠信息丰富工作流,允许 Agent 在执行任务期间访问相关数据。

安装

要使用此工具,您需要安装 Linkup SDK

uv add linkup-sdk

入门步骤

要有效使用 LinkupSearchTool,请按照以下步骤操作

  1. API Key:获取 Linkup API 密钥。
  2. 环境设置:使用 API 密钥设置您的环境。
  3. 安装 SDK:使用上述命令安装 Linkup SDK。

示例

以下示例演示如何初始化工具并在 Agent 中使用它

代码
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”。

高级用法

您可以自定义搜索参数以获得更精确的结果

代码
# Perform a search with custom parameters
results = linkup_tool.run(
    query="Women Nobel Prize Physics",
    depth="deep",
    output_type="searchResults"
)

返回格式

工具返回结果的格式如下

{
  "success": true,
  "results": [
    {
      "name": "Result Title",
      "url": "https://example.com/result",
      "content": "Content of the result..."
    },
    // Additional results...
  ]
}

如果发生错误,响应将是

{
  "success": false,
  "error": "Error message"
}

错误处理

工具能够优雅地处理 API 错误并提供结构化反馈。如果 API 请求失败,工具将返回一个字典,其中包含 success: false 和错误消息。

结论

LinkupSearchTool 提供了一种将 Linkup 的上下文信息检索能力无缝集成到您的 CrewAI Agent 中的方式。通过利用此工具,Agent 可以访问相关且最新的信息,从而增强其决策和任务执行能力。