π οΈTools
What is Tool?
Tool is a functionality based on which the data is fetched to the Agent for further analysis and decision making. A wide array of tools is cataloged in the tools database, designed to support activities such as internet searches, email dispatch, interactions with Git repositories, and much more. Users have the flexibility to create their own tools and seamlessly integrate them into the framework's operations.
Note: Some of the tools are not pre-installed with the OpenAGI library. If you encounter an
OpenAGIException
due to an Import Error, you'll need to manually install the required package to use the tool.
Tool configuration
1. DuckDuckGoSearch Tool
The DuckDuckGoSearch tool is a tool that can be used to search for words, documents, images, videos, news, maps and text translation using the DuckDuckGo.com search engine. DuckDuckGo Search is a web search engine that DuckDuckGo is an independent Google alternative that lets you search and browse the web, but it emphasises protecting user privacy and avoiding the filter bubble of personalised search results.
2. Serper Search Tool
Serper is a low-cost Google Search API that can be used to add answer box, knowledge graph, and organic results data from Google Search. This tool is mainly helps user to query the Google results with less throughput and latency.
Setup API
Get your API key: https://serper.dev/
3. Google Serp API Search
Serp API is yet another solution to integrate search data. SERP stands for Search Engine Results Page. It refers to the page displayed by a search engine in response to a user's query.
Setup API
Get your API key: https://serpapi.com/manage-api-key/
4. Github Search Tool
The Github SearchTool is used for retrieving information from Github repositories using natural language queries. This tool provides functionality for querying Github repositories for various information, such as code changes, commits, active pull requests, issues, etc., using natural language input. It is designed to be used as part of a larger AI-driven agent system.
Setup API
Get your GitHub Access Token: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens
5. YouTube Search Tool
The YouTube Search tool allows users to search for videos on YouTube using natural language queries. This tool retrieves relevant video content based on user-defined search parameters, making it easier to find specific videos or topics of interest.
The YouTube Search tool does not require an API key but does require the installation of specific libraries. You need to install yt-dlp
and youtube-search
to use this tool.
Code Snippet To initialize the YouTube Search tool, you can use the following code:
6. Tavily QA Search Tool
The Tavily QA Search tool is designed to provide answers to user queries by fetching data from various online sources. This tool enhances the capability of the agent to retrieve precise information and answer questions effectively.
Installation
For the Tavily QA Search tool, you also need to set up the API key in your environment variables:
Code Snippet To initialize the Tavily QA Search tool, you can use the following code:
7. Exa Search Tool
The Exa Search tool allows users to query the Exa API to retrieve relevant responses based on user-defined questions. This tool is particularly useful for extracting information and insights from various data sources using natural language queries.
Installation
To use the Exa Search tool, you need to set up the API key in your environment variables. Hereβs how to do that:
Code Snippet
8. Unstructured PDF Loader Tool
The Unstructured PDF Loader tool is designed to extract content, including metadata, from PDF files. It utilizes the Unstructured library to partition the PDF and chunk the content based on titles. This tool is useful for processing large volumes of PDF documents and making their contents accessible for further analysis.
Installation
Code Snippet
How to build a custom Tool?
In OpenAGI, building a custom tool is straightforward by wrapping your custom logic inside a class that inherits from BaseAction
and implementing the execute
method. This setup allows you to encapsulate the necessary configurations and operations within the custom tool, making it easy to integrate and use within the OpenAGI framework.
Syntax
Import Necessary Modules:
Begin by importing the necessary modules from
pydantic
andopenagi
.Field
is used to define parameters, andBaseAction
is the base class for creating custom actions in OpenAGI.
Define the Custom Tool Class:
Create a class
CustomToolName
that inherits fromBaseAction
. This class represents your custom tool.Within the class, define a variable
vars
usingField()
frompydantic
. This variable will hold any parameters required by your tool. Replacedtype
with the actual data type of the parameter (e.g.,str
,int
,List[str]
).
Implement the
execute
Method:The
execute
method is where the core logic of your tool will be implemented. This method will be called when the tool is executed.Inside the
execute
method, write the code necessary, this might include loading data, processing it, and returning the desired output.Make sure the execute function returns
str
data.
Example
In this custom tool integration example, we will implement the Unstructured IO data loading tool. This custom tool provides the flexibility to act as a wrapper for Unstructured IO as an action tool in OpenAGI.
The execute
function is where the magic happens; if any variables or parameters need to be defined, they should be declared within the Custom Tool class. This setup ensures that all necessary configurations and parameters are encapsulated within the tool, allowing for seamless and efficient data loading and processing.
For more examples of Tools integration, check reference code snippets here: https://github.com/aiplanethub/openagi/tree/main/src/openagi/actions/tools
Last updated