Home/AI Agents/llm_agents
llm_agents logo

llm_agents

Enrichment pending
mpaepper/llm_agents

Build agents which are controlled by LLMs

GraphCanon updated today · GitHub synced today

1.1k
Stars
85
Forks
3
Open issues
9
Watchers
1y
Last push
Python MITCreated Apr 4, 2023

Trust & integrity

Full report
Maintenance
Dormant (382d since push)
As of today · Source: github_public_v1
Provenance
Not a fork · Personal account
As of today · Source: github_public_v1
Security (OSV)
32 low (32 low)
As of today · Source: osv@v1

Public GitHub metadata and optional OSV dependency scans. Signals, not a guarantee. Trust methodology.

Overview

Build agents which are controlled by LLMs

Capability facts

CLI
CLI entrypoint

Source: pyproject.toml:[project.scripts] · Jul 11, 2026

Languages
python

Source: github.language+pyproject.toml · Jul 11, 2026

Categories

Compatibility

Sourced claims from the README excerpt - not unsourced marketing copy.

LangChain integrationLangChain

Source: README excerpt (regex_v1, Jul 11, 2026)

odels (LLMs) which is heavily inspired by <a href="https://github.com/hwchase17/langchain/" target="_blank">langchain</a>.
Source link
OpenAI APIOpenAI API

Source: README excerpt (regex_v1, Jul 11, 2026)

* `OPENAI_API_KEY` to use the OpenAI API (obtainable at: https://platform.openai.com/account/api-keys)
Source link
Python runtimePython

Source: README excerpt (regex_v1, Jul 11, 2026)

* 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
Source link

Tags

README

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 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:

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.