Small library to build agents which are controlled by large language models (LLMs) which is heavily inspired by langchain.
The goal was to get a better grasp of how such an agent works and understand it all in very few lines of code.
Langchain is great, but it already has a few more files and abstraction layers, so I thought it would be nice to build the most important parts of a simple agent from scratch.
Some more infos are in this Hacker News discussion from April 5th 2023 and the related blog post.
The agent works like this:
For more details on how it works, check out this blog post
You can install this library locally by running:
pip install -r requirements.txt
pip install -e .
inside it's directory after cloning it.
You also need to provide the following env variables:
OPENAI_API_KEY to use the OpenAI API (obtainable at: https://platform.openai.com/account/api-keys)SERPAPI_API_KEY to use the Google Search in case you use that tool (obtainable at: https://serpapi.com/)You can simply export them in bash like: export OPENAI_API_KEY='sh-lsdf....'
Then you can run the script python run_agent.py and ask your question.
To construct your own agent do it like this:
from llm_agents import Agent, ChatLLM, PythonREPLTool, HackerNewsSearchTool, SerpAPITool
agent = Agent(llm=ChatLLM(), tools=[PythonREPLTool(), SerpAPITool(), HackerNewsSearchTool()])
result = agent.run("Your question to the agent")
print(f"Final answer is {result}")
Of course, you can also build your custom tools or omit tools, for exmaple if you don't want to create a SERPAPI key.
34 followers · starred Jul 2023
108 followers · starred Apr 2023
4,358 followers · starred Apr 2023
205 followers · starred Apr 2023
Small library to build agents which are controlled by large language models (LLMs) which is heavily inspired by langchain.
The goal was to get a better grasp of how such an agent works and understand it all in very few lines of code.
Langchain is great, but it already has a few more files and abstraction layers, so I thought it would be nice to build the most important parts of a simple agent from scratch.
Some more infos are in this Hacker News discussion from April 5th 2023 and the related blog post.
The agent works like this:
For more details on how it works, check out this blog post
You can install this library locally by running:
pip install -r requirements.txt
pip install -e .
inside it's directory after cloning it.
You also need to provide the following env variables:
OPENAI_API_KEY to use the OpenAI API (obtainable at: https://platform.openai.com/account/api-keys)SERPAPI_API_KEY to use the Google Search in case you use that tool (obtainable at: https://serpapi.com/)You can simply export them in bash like: export OPENAI_API_KEY='sh-lsdf....'
Then you can run the script python run_agent.py and ask your question.
To construct your own agent do it like this:
from llm_agents import Agent, ChatLLM, PythonREPLTool, HackerNewsSearchTool, SerpAPITool
agent = Agent(llm=ChatLLM(), tools=[PythonREPLTool(), SerpAPITool(), HackerNewsSearchTool()])
result = agent.run("Your question to the agent")
print(f"Final answer is {result}")
Of course, you can also build your custom tools or omit tools, for exmaple if you don't want to create a SERPAPI key.
34 followers · starred Jul 2023
108 followers · starred Apr 2023
4,358 followers · starred Apr 2023
205 followers · starred Apr 2023