mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-08 15:48:29 +00:00
Merge pull request #155 from juliette0704/feat/add_linkup_tool
add linkup tool
This commit is contained in:
@@ -17,6 +17,7 @@ from .tools import (
|
||||
FirecrawlSearchTool,
|
||||
GithubSearchTool,
|
||||
JSONSearchTool,
|
||||
LinkupSearchTool,
|
||||
LlamaIndexTool,
|
||||
MDXSearchTool,
|
||||
MultiOnTool,
|
||||
|
||||
@@ -20,6 +20,7 @@ from .firecrawl_scrape_website_tool.firecrawl_scrape_website_tool import (
|
||||
from .firecrawl_search_tool.firecrawl_search_tool import FirecrawlSearchTool
|
||||
from .github_search_tool.github_search_tool import GithubSearchTool
|
||||
from .json_search_tool.json_search_tool import JSONSearchTool
|
||||
from .linkup_search_tool.linkup_search_tool import LinkupSearchTool
|
||||
from .llamaindex_tool.llamaindex_tool import LlamaIndexTool
|
||||
from .mdx_seach_tool.mdx_search_tool import MDXSearchTool
|
||||
from .multion_tool.multion_tool import MultiOnTool
|
||||
|
||||
98
src/crewai_tools/tools/linkup/README.md
Normal file
98
src/crewai_tools/tools/linkup/README.md
Normal file
@@ -0,0 +1,98 @@
|
||||
# Linkup Search Tool
|
||||
|
||||
## Description
|
||||
|
||||
The `LinkupSearchTool` is a tool designed for integration with the CrewAI framework. It provides the ability to query the Linkup API for contextual information and retrieve structured results. This tool is ideal for enriching workflows with up-to-date and reliable information from Linkup.
|
||||
|
||||
---
|
||||
|
||||
## Features
|
||||
|
||||
- Perform API queries to the Linkup platform using customizable parameters (`query`, `depth`, `output_type`).
|
||||
- Gracefully handles API errors and provides structured feedback.
|
||||
- Returns well-structured results for seamless integration into CrewAI processes.
|
||||
|
||||
---
|
||||
|
||||
## Installation
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Linkup API Key
|
||||
|
||||
### Steps
|
||||
|
||||
1. ```shell
|
||||
pip install 'crewai[tools]'
|
||||
```
|
||||
|
||||
2. Create a `.env` file in your project root and add your Linkup API Key:
|
||||
```plaintext
|
||||
LINKUP_API_KEY=your_linkup_api_key
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Usage
|
||||
|
||||
### Basic Example
|
||||
|
||||
Here is how to use the `LinkupSearchTool` in a CrewAI project:
|
||||
|
||||
1. **Import and Initialize**:
|
||||
```python
|
||||
from tools.linkup_tools import LinkupSearchTool
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
linkup_tool = LinkupSearchTool(api_key=os.getenv("LINKUP_API_KEY"))
|
||||
```
|
||||
|
||||
2. **Set Up an Agent and Task**:
|
||||
```python
|
||||
from crewai import Agent, Task, Crew
|
||||
|
||||
# Define the agent
|
||||
research_agent = Agent(
|
||||
role="Information Researcher",
|
||||
goal="Fetch relevant results from Linkup.",
|
||||
backstory="An expert in online information retrieval...",
|
||||
tools=[linkup_tool],
|
||||
verbose=True
|
||||
)
|
||||
|
||||
# Define the task
|
||||
search_task = Task(
|
||||
expected_output="A detailed list of Nobel Prize-winning women in physics with their achievements.",
|
||||
description="Search for women who have won the Nobel Prize in Physics.",
|
||||
agent=research_agent
|
||||
)
|
||||
|
||||
# Create and run the crew
|
||||
crew = Crew(
|
||||
agents=[research_agent],
|
||||
tasks=[search_task]
|
||||
)
|
||||
|
||||
result = crew.kickoff()
|
||||
print(result)
|
||||
```
|
||||
|
||||
### Advanced Configuration
|
||||
|
||||
You can customize the parameters for the `LinkupSearchTool`:
|
||||
|
||||
- `query`: The search term or phrase.
|
||||
- `depth`: The search depth (`"standard"` by default).
|
||||
- `output_type`: The type of output (`"searchResults"` by default).
|
||||
|
||||
Example:
|
||||
```python
|
||||
response = linkup_tool._run(
|
||||
query="Women Nobel Prize Physics",
|
||||
depth="standard",
|
||||
output_type="searchResults"
|
||||
)
|
||||
```
|
||||
BIN
src/crewai_tools/tools/linkup/assets/icon.png
Normal file
BIN
src/crewai_tools/tools/linkup/assets/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 32 KiB |
36
src/crewai_tools/tools/linkup/linkup_search_tool.py
Normal file
36
src/crewai_tools/tools/linkup/linkup_search_tool.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from linkup import LinkupClient
|
||||
from pydantic import PrivateAttr
|
||||
|
||||
class LinkupSearchTool:
|
||||
name: str = "Linkup Search Tool"
|
||||
description: str = "Performs an API call to Linkup to retrieve contextual information."
|
||||
_client: LinkupClient = PrivateAttr()
|
||||
|
||||
def __init__(self, api_key: str):
|
||||
"""
|
||||
Initialize the tool with an API key.
|
||||
"""
|
||||
self._client = LinkupClient(api_key=api_key)
|
||||
|
||||
def _run(self, query: str, depth: str = "standard", output_type: str = "searchResults") -> dict:
|
||||
"""
|
||||
Executes a search using the Linkup API.
|
||||
|
||||
:param query: The query to search for.
|
||||
:param depth: Search depth (default is "standard").
|
||||
:param output_type: Desired result type (default is "searchResults").
|
||||
:return: A dictionary containing the results or an error message.
|
||||
"""
|
||||
try:
|
||||
response = self._client.search(
|
||||
query=query,
|
||||
depth=depth,
|
||||
output_type=output_type
|
||||
)
|
||||
results = [
|
||||
{"name": result.name, "url": result.url, "content": result.content}
|
||||
for result in response.results
|
||||
]
|
||||
return {"success": True, "results": results}
|
||||
except Exception as e:
|
||||
return {"success": False, "error": str(e)}
|
||||
Reference in New Issue
Block a user