https://github.com/mpaepper/llm_agents Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code + Explore + All features + Documentation + GitHub Skills + Blog * Solutions + For + Enterprise + Teams + Startups + Education + By Solution + CI/CD & Automation + DevOps + DevSecOps + Case Studies + Customer Stories + Resources * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles + Repositories + Topics + Trending + Collections * Pricing [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} mpaepper / llm_agents Public * Notifications * Fork 0 * Star 20 Build agents which are controlled by LLMs www.paepper.com/blog/posts/intelligent-agents-guided-by-llms/ License MIT license 20 stars 0 forks Star Notifications * Code * Issues 0 * Pull requests 0 * Actions * Projects 0 * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Security * Insights mpaepper/llm_agents This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. main Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 2 branches 0 tags Code * Local * Codespaces * Clone HTTPS GitHub CLI [https://github.com/m] Use Git or checkout with SVN using the web URL. [gh repo clone mpaepp] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Sign In Required Please sign in to use Codespaces. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @mpaepper mpaepper Merge pull request #1 from mpaepper/add-license-1 ... 53c6ef2 Apr 4, 2023 Merge pull request #1 from mpaepper/add-license-1 Create LICENSE 53c6ef2 Git stats * 12 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time llm_agents Added __init__.py April 4, 2023 22:01 LICENSE Create LICENSE April 4, 2023 23:33 README.md Added README.md April 4, 2023 23:30 requirements.txt Added requirements and setup.py April 4, 2023 22:02 run_agent.py Added run_agent.py example script April 4, 2023 22:02 setup.py Added requirements and setup.py April 4, 2023 22:02 View code LLM Agents How it works How to use it README.md LLM Agents 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. How it works The agent works like this: * It gets instructed by a prompt which tells it the basic way to solve a task using tools * Tools are custom build components which the agent can use + So far, I've implemented the ability to execute Python code in a REPL, to use the Google search and to search on Hacker News * The agent runs in a loop of Thought, Action, Observation, Thought, ... + The Thought and Action (with the Action Input to the action) are the parts which are generated by an LLM + The Observation is generated by using a tool (for example the print outputs of Python or the text result of a Google search) * The LLM gets the new information appended to the prompt in each loop cycle and thus can act on that information * Once the agent has enough information it provides the final answer For more details on how it works, check out this blog post How to use it You can install this libaray locally by running: 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. About Build agents which are controlled by LLMs www.paepper.com/blog/posts/intelligent-agents-guided-by-llms/ Topics machine-learning deep-learning llms langchain Resources Readme License MIT license Stars 20 stars Watchers 1 watching Forks 0 forks Languages * Python 100.0% Footer (c) 2023 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.