2022-12-19 02:51:23 +00:00
# Tools
Tools are functions that agents can use to interact with the world.
2022-12-23 18:13:07 +00:00
These tools can be generic utilities (e.g. search), other chains, or even other agents.
2022-12-19 02:51:23 +00:00
Currently, tools can be loaded with the following snippet:
```python
from langchain.agents import load_tools
tool_names = [...]
tools = load_tools(tool_names)
```
2022-12-23 18:13:07 +00:00
Some tools (e.g. chains, agents) may require a base LLM to use to initialize them.
2022-12-19 02:51:23 +00:00
In that case, you can pass in an LLM as well:
```python
from langchain.agents import load_tools
tool_names = [...]
llm = ...
tools = load_tools(tool_names, llm=llm)
```
Below is a list of all supported tools and relevant information:
2023-01-22 00:03:02 +00:00
2022-12-19 02:51:23 +00:00
- Tool Name: The name the LLM refers to the tool by.
- Tool Description: The description of the tool that is passed to the LLM.
- Notes: Notes about the tool that are NOT passed to the LLM.
- Requires LLM: Whether this tool requires an LLM to be initialized.
- (Optional) Extra Parameters: What extra parameters are required to initialize this tool.
Docs refactor (#480)
Big docs refactor! Motivation is to make it easier for people to find
resources they are looking for. To accomplish this, there are now three
main sections:
- Getting Started: steps for getting started, walking through most core
functionality
- Modules: these are different modules of functionality that langchain
provides. Each part here has a "getting started", "how to", "key
concepts" and "reference" section (except in a few select cases where it
didnt easily fit).
- Use Cases: this is to separate use cases (like summarization, question
answering, evaluation, etc) from the modules, and provide a different
entry point to the code base.
There is also a full reference section, as well as extra resources
(glossary, gallery, etc)
Co-authored-by: Shreya Rajpal <ShreyaR@users.noreply.github.com>
2023-01-02 16:24:09 +00:00
## List of Tools
2022-12-19 02:51:23 +00:00
**python_repl**
2023-01-22 00:03:02 +00:00
2022-12-19 02:51:23 +00:00
- Tool Name: Python REPL
- Tool Description: A Python shell. Use this to execute python commands. Input should be a valid python command. If you expect output it should be printed out.
- Notes: Maintains state.
- Requires LLM: No
**serpapi**
2023-01-22 00:03:02 +00:00
2022-12-19 02:51:23 +00:00
- Tool Name: Search
- Tool Description: A search engine. Useful for when you need to answer questions about current events. Input should be a search query.
- Notes: Calls the Serp API and then parses results.
- Requires LLM: No
2023-01-11 13:52:19 +00:00
**wolfram-alpha**
2023-01-22 00:03:02 +00:00
2023-01-11 13:52:19 +00:00
- Tool Name: Wolfram Alpha
- Tool Description: A wolfram alpha search engine. Useful for when you need to answer questions about Math, Science, Technology, Culture, Society and Everyday Life. Input should be a search query.
- Notes: Calls the Wolfram Alpha API and then parses results.
- Requires LLM: No
2023-01-22 00:03:02 +00:00
- Extra Parameters: `wolfram_alpha_appid` : The Wolfram Alpha app id.
2023-01-11 13:52:19 +00:00
2022-12-19 02:51:23 +00:00
**requests**
2023-01-22 00:03:02 +00:00
2022-12-19 02:51:23 +00:00
- Tool Name: Requests
- Tool Description: A portal to the internet. Use this when you need to get specific content from a site. Input should be a specific url, and the output will be all the text on that page.
- Notes: Uses the Python requests module.
- Requires LLM: No
**terminal**
2023-01-22 00:03:02 +00:00
2022-12-19 02:51:23 +00:00
- Tool Name: Terminal
- Tool Description: Executes commands in a terminal. Input should be valid commands, and the output will be any output from running that command.
- Notes: Executes commands with subprocess.
- Requires LLM: No
**pal-math**
2023-01-22 00:03:02 +00:00
2022-12-19 02:51:23 +00:00
- Tool Name: PAL-MATH
2022-12-23 18:13:07 +00:00
- Tool Description: A language model that is excellent at solving complex word math problems. Input should be a fully worded hard word math problem.
2022-12-19 02:51:23 +00:00
- Notes: Based on [this paper ](https://arxiv.org/pdf/2211.10435.pdf ).
- Requires LLM: Yes
**pal-colored-objects**
2023-01-22 00:03:02 +00:00
2022-12-19 02:51:23 +00:00
- Tool Name: PAL-COLOR-OBJ
2022-12-23 18:13:07 +00:00
- Tool Description: A language model that is wonderful at reasoning about position and the color attributes of objects. Input should be a fully worded hard reasoning problem. Make sure to include all information about the objects AND the final question you want to answer.
2022-12-19 02:51:23 +00:00
- Notes: Based on [this paper ](https://arxiv.org/pdf/2211.10435.pdf ).
- Requires LLM: Yes
**llm-math**
2023-01-22 00:03:02 +00:00
2022-12-19 02:51:23 +00:00
- Tool Name: Calculator
- Tool Description: Useful for when you need to answer questions about math.
- Notes: An instance of the `LLMMath` chain.
- Requires LLM: Yes
**open-meteo-api**
2023-01-22 00:03:02 +00:00
2022-12-19 02:51:23 +00:00
- Tool Name: Open Meteo API
- Tool Description: Useful for when you want to get weather information from the OpenMeteo API. The input should be a question in natural language that this API can answer.
- Notes: A natural language connection to the Open Meteo API (`https://api.open-meteo.com/`), specifically the `/v1/forecast` endpoint.
- Requires LLM: Yes
**news-api**
2023-01-22 00:03:02 +00:00
2022-12-19 02:51:23 +00:00
- Tool Name: News API
- Tool Description: Use this when you want to get information about the top headlines of current news stories. The input should be a question in natural language that this API can answer.
- Notes: A natural language connection to the News API (`https://newsapi.org`), specifically the `/v2/top-headlines` endpoint.
- Requires LLM: Yes
- Extra Parameters: `news_api_key` (your API key to access this endpoint)
**tmdb-api**
2023-01-22 00:03:02 +00:00
2022-12-19 02:51:23 +00:00
- Tool Name: TMDB API
- Tool Description: Useful for when you want to get information from The Movie Database. The input should be a question in natural language that this API can answer.
- Notes: A natural language connection to the TMDB API (`https://api.themoviedb.org/3`), specifically the `/search/movie` endpoint.
- Requires LLM: Yes
2022-12-23 18:13:07 +00:00
- Extra Parameters: `tmdb_bearer_token` (your Bearer Token to access this endpoint - note that this is different from the API key)
2023-01-22 00:03:02 +00:00
**google-search**
- Tool Name: Search
- Tool Description: A wrapper around Google Search. Useful for when you need to answer questions about current events. Input should be a search query.
- Notes: Uses the Google Custom Search API
- Requires LLM: No
- Extra Parameters: `google_api_key` , `google_cse_id`
- For more information on this, see [this page ](../../ecosystem/google_search.md )
Google Search API integration with serper.dev (wrapper, tests, docs, … (#909)
Adds Google Search integration with [Serper](https://serper.dev) a
low-cost alternative to SerpAPI (10x cheaper + generous free tier).
Includes documentation, tests and examples. Hopefully I am not missing
anything.
Developers can sign up for a free account at
[serper.dev](https://serper.dev) and obtain an api key.
## Usage
```python
from langchain.utilities import GoogleSerperAPIWrapper
from langchain.llms.openai import OpenAI
from langchain.agents import initialize_agent, Tool
import os
os.environ["SERPER_API_KEY"] = ""
os.environ['OPENAI_API_KEY'] = ""
llm = OpenAI(temperature=0)
search = GoogleSerperAPIWrapper()
tools = [
Tool(
name="Intermediate Answer",
func=search.run
)
]
self_ask_with_search = initialize_agent(tools, llm, agent="self-ask-with-search", verbose=True)
self_ask_with_search.run("What is the hometown of the reigning men's U.S. Open champion?")
```
### Output
```
Entering new AgentExecutor chain...
Yes.
Follow up: Who is the reigning men's U.S. Open champion?
Intermediate answer: Current champions Carlos Alcaraz, 2022 men's singles champion.
Follow up: Where is Carlos Alcaraz from?
Intermediate answer: El Palmar, Spain
So the final answer is: El Palmar, Spain
> Finished chain.
'El Palmar, Spain'
```
2023-02-16 06:47:17 +00:00
2023-02-16 07:03:57 +00:00
**searx-search**
- Tool Name: Search
- Tool Description: A wrapper around SearxNG meta search engine. Input should be a search query.
- Notes: SearxNG is easy to deploy self-hosted. It is a good privacy friendly alternative to Google Search. Uses the SearxNG API.
- Requires LLM: No
- Extra Parameters: `searx_host`
Google Search API integration with serper.dev (wrapper, tests, docs, … (#909)
Adds Google Search integration with [Serper](https://serper.dev) a
low-cost alternative to SerpAPI (10x cheaper + generous free tier).
Includes documentation, tests and examples. Hopefully I am not missing
anything.
Developers can sign up for a free account at
[serper.dev](https://serper.dev) and obtain an api key.
## Usage
```python
from langchain.utilities import GoogleSerperAPIWrapper
from langchain.llms.openai import OpenAI
from langchain.agents import initialize_agent, Tool
import os
os.environ["SERPER_API_KEY"] = ""
os.environ['OPENAI_API_KEY'] = ""
llm = OpenAI(temperature=0)
search = GoogleSerperAPIWrapper()
tools = [
Tool(
name="Intermediate Answer",
func=search.run
)
]
self_ask_with_search = initialize_agent(tools, llm, agent="self-ask-with-search", verbose=True)
self_ask_with_search.run("What is the hometown of the reigning men's U.S. Open champion?")
```
### Output
```
Entering new AgentExecutor chain...
Yes.
Follow up: Who is the reigning men's U.S. Open champion?
Intermediate answer: Current champions Carlos Alcaraz, 2022 men's singles champion.
Follow up: Where is Carlos Alcaraz from?
Intermediate answer: El Palmar, Spain
So the final answer is: El Palmar, Spain
> Finished chain.
'El Palmar, Spain'
```
2023-02-16 06:47:17 +00:00
**google-serper**
- Tool Name: Search
- Tool Description: A low-cost Google Search API. Useful for when you need to answer questions about current events. Input should be a search query.
- Notes: Calls the [serper.dev ](https://serper.dev ) Google Search API and then parses results.
- Requires LLM: No
- Extra Parameters: `serper_api_key`
- For more information on this, see [this page ](../../ecosystem/google_serper.md )