Coder Social home page Coder Social logo

anasaito / llm_agents Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mpaepper/llm_agents

0.0 0.0 0.0 13 KB

Build agents which are controlled by LLMs

Home Page: https://www.paepper.com/blog/posts/intelligent-agents-guided-by-llms/

License: MIT License

Python 100.00%

llm_agents's Introduction

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.

Some more infos are in this Hacker News discussion from April 5th 2023 and the related blog post.

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:

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.

llm_agents's People

Contributors

mpaepper avatar thingengineer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.