CrewAI Tools
CrewAI provides agents with specialized tools to perform specific tasks like web scraping, file management, database interaction and image generation. These tools enable agents to collect and process data from websites, manage files efficiently, interact with databases and generate visual content. By integrating these tools, CrewAI agents can perform task-specific actions autonomously while maintaining context within collaborative workflows.
Installing CrewAI Tools
To begin, we need to install the crewai_tools package by running the following command:
pip install crewai_tools
Listing Available Tools
We can list all the tools available in crewai_tools by running the following code:
from crewai_tools import tools
for i in dir(tools):
print(i)
Output:
AIMindTool
ApifyActorsTool
ArxivPaperTool
BraveSearchTool
BrightDataDatasetTool
BrightDataSearchTool
BrightDataWebUnlockerTool
...............
Tool Documentation and Usage
Each tool in CrewAI has detailed documentation. To explore the usage of any specific tool, such as ScrapeWebsiteTool, we can use the help() function in Python to view the tool’s description and available parameters. Here's an example of how to use it:
from crewai_tools import ScrapeWebsiteTool
help(ScrapeWebsiteTool)
Output:
Help on class ScrapeWebsiteTool in module crewai_tools.tools.scrape_website_tool.scrape_website_tool:
class ScrapeWebsiteTool(crewai.tools.base_tool.BaseTool)
| ScrapeWebsiteTool(website_url: Optional[str] = None, cookies: Optional[dir......
Some Popular Tools in CrewAI
Below are some popular tools in CrewAI, commonly used for tasks like web scraping, file management, database interaction and more.
1. RAG Tool (Retrieval-Augmented Generation)
The RAG Tool is designed to combine retrieval and generation models. It first retrieves relevant documents from external sources and then generates meaningful responses by combining the retrieved data with the agent's built-in knowledge. This is useful when we need the agent to provide responses based on both prior knowledge and new data retrieved dynamically.
- name: Defines the name of the tool.
- description: A description that provides context on how the tool functions.
- result_as_answer: If True, the tool returns only the final generated answer, ignoring intermediary steps.
- summarize: This flag helps the tool to summarize large chunks of text, making it more efficient for answering questions based on long documents.
- verbose: Logs detailed information for debugging and monitoring the tool's activity.
import os
os.environ['OPENAI_API_KEY'] ="Your_API_Key"
from crewai_tools import RagTool
rag_tool = RagTool(
name='Knowledge base',
description='A knowledge base that can be used to answer questions.',
result_as_answer=True,
summarize=True,
verbose=True
)
response= rag_tool.run("What are the latest AI advancements?")
print(response)
Output:
Using Tool: Knowledge base
Relevant Content:
Recent advancements in AI have focused on several key areas..........
2. ScrapeWebsiteTool
The ScrapeWebsiteTool allows agents to extract and scrape content from websites. It works by scraping the raw HTML content of a page, extracting meaningful data from it.
- website_url: The URL of the website you want to scrape.
import os
os.environ['OPENAI_API_KEY'] ="Your_API_Key"
from crewai_tools import ScrapeWebsiteTool
scraper = ScrapeWebsiteTool(website_url="https://geeksforgeeks.org")
response = scraper.run()
print(response)
Output:
Using Tool: Read website content
GeeksforGeeks | Your All-in-One Learning Portal Tutorials Courses Go Premium Data......
3. SerperDevTool
The SerperDevTool helps agents retrieve relevant search results from the web. Unlike traditional scraping, it interacts directly with search engines (like Google) to pull search results in a structured format
- name: Name of the tool for identification.
- description: A short description about what the tool does.
- verbose: When True, provides detailed logs of the tool's execution.
from crewai_tools import SerperDevTool
import os
os.environ["SERPER_API_KEY"]="Your_SERPER_API_KEY"
os.environ['OPENAI_API_KEY'] ="Your_API_Key"
serper_tool = SerperDevTool(
name="Web Search Tool",
description="A tool to perform web searches and retrieve search results.",
verbose=True
)
search_results = serper_tool.run(query="What are the latest AI advancements?")
print("Search Results:")
print(search_results)
Output:
Using Tool: Web Search Tool
Search Results:
{'searchParameters': {'q': 'What are the latest AI advancements?', 'type': 'sear...........
4. File Read Tool
The File Read Tool allow agents to read files which is useful when dealing with persistent storage or managing local files. These tools help agents interact with file systems for data extraction and creation.
- file_path: Path to the file to be read.
import os
os.environ['OPENAI_API_KEY'] ="Your_API_Key"
from crewai_tools import FileReadTool
file_reader = FileReadTool(file_path="/content/data.txt")
output = file_reader.run()
print(output)
Output:
Using Tool: Read a file's content
Hello Geeks!
5. DaLLE Tool
The DaLLE Tool is used to generate images based on textual descriptions. It integrates with OpenAI’s DALL-E model, allowing the agent to create unique and high-quality images from user-provided prompts.
- image_description: The textual description that tells the model what to generate.
import os
os.environ['OPENAI_API_KEY'] ="Your_API_Key"
from crewai_tools import DallETool
dalle_tool = DallETool()
image_url = dalle_tool.run(image_description="A futuristic city skyline")
print(image_url)
Output:
Using Tool: Dall-E Tool
{"image_url": "https://oaidalleapiprodscus.blob.core.windows.net/priv..................