Skip to content

Commit 413d0b2

Browse files
author
SRM
committed
Update README to inclue how to create custom tools, agents & runs streamlit app
1 parent b47ea40 commit 413d0b2

File tree

1 file changed

+65
-2
lines changed

1 file changed

+65
-2
lines changed

README.md

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,70 @@ A suite of tools to perform geospatial operations using Large Language Models.
44

55
LLLLM stands for Lat-Lng-Large-Language-Model, you can call it as "el el el el emm" or "L4M".
66

7-
87
## Setup
98
1. Create the llllm-env - `mamba env create -f environment.yaml`
10-
2. Set your OpenAI API key as an environment variable - `export OPENAI_API_KEY=<your key here>`
9+
2. Set your OpenAI API key as an environment variable - `export OPENAI_API_KEY=<your key here>`
10+
11+
## Getting Started
12+
13+
### Adding a new tool
14+
15+
Tools are ways the agent can use to interact with the outside world. You can find more information on how LLMs use tools to solve new tasks at scale in this paper: [Toolformer](https://arxiv.org/pdf/2302.04761.pdf)
16+
17+
Langchain comes bundled with a set of tools like Google Search, Wikipedia, Python REPL, Shell, Wolfram Alpha & several others - find the list of pre-built tools [here](https://python.langchain.com/en/latest/modules/agents/tools.html#)
18+
19+
Creating a new tool is simple in Langchain. You can create a custom tool by:
20+
- using the `Tool` dataclass or
21+
- inhering from the `BaseTool` class
22+
23+
Both these methods need to provide:
24+
- name: unique & referred to by LLM while executing the chains
25+
- description: detailed description of when & how the LLM should use this tool
26+
- args_schema: arguments to the tool
27+
28+
Barebones of how to define a custom tool by inheriting from the `BaseTool` class
29+
```python
30+
from langchain.tools import BaseTool
31+
32+
class YourCustomTool(BaseTool):
33+
name = <name>
34+
description = <detailed-description>
35+
args_schema = <PydanticModel>
36+
37+
def _run(self, query):
38+
# functionality of the tool
39+
pass
40+
41+
def _arun(self, query):
42+
# async implementation of the tool (Optional)
43+
raise NotImplementedError
44+
```
45+
We have a few tools available in the LLLLM toolkit that you can use for reference - [MercantileTool](tools/mercantile_tool.py), [GeoPyTool](tools/geopy/), [OSMnxTool](tools/osmnx/)
46+
47+
Learn more about creating custom tools by reading this blog on [Building Custom Tools for LLM Agents from Pinecone](https://www.pinecone.io/learn/langchain-tools/) or [documention from Langchain](https://python.langchain.com/en/latest/modules/agents/tools/custom_tools.html).
48+
49+
50+
### Creating an agent
51+
52+
Agents act like routers using LLMs to decide which tools to use for the task at hand. There are different types of agents available in langchain:
53+
- [ReAct](https://python.langchain.com/en/latest/modules/agents/agents/examples/react.html) - Reason & Act agents are optimized for picking tools for best response - read more about them in this [paper](https://react-lm.github.io/)
54+
- [Conversation Agent](https://python.langchain.com/en/latest/modules/agents/agents/examples/chat_conversation_agent.html) - they are ideal to use in a conversational setting
55+
- [Structured Tool Chat Agent](https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html) - use this agent if you have tools that expect multi-input parameters. Check the OSMnx or GeoPy tool for reference.
56+
57+
Usage
58+
```python
59+
from agents.l4m_agent import base_agent
60+
61+
agent = base_agent(
62+
llm=<LLM object>, # instance of an LLM like GPT-3.5-TURBO or GPT-4
63+
tools=[<tool1>, <tool1>, ...], # list of tools the agent has access to perform its tasks
64+
name=<name of agent>, # Agent.Type for eg: zero-shot-react-description or structure-chat-zero-shot-react-description (for multi-input tools)
65+
)
66+
```
67+
68+
### Creating notebooks to test
69+
Import the tools & create an agent in jupyter notebook to interact with them. Please find example notebooks [here](/nbs/).
70+
71+
72+
### Running the streamlit app
73+
`streamlit run app.py`

0 commit comments

Comments
 (0)