Autonomous LLM Agents

LLM Agents Are Autonomous In Accessing & Sequencing Actions

Cobus Greyling
5 min readMay 15, 2023

--

Agents make use of pre-assigned tools in an autonomous fashion to perform one or more actions. Agents follow a chain-of-thought reasoning approach.

The concept of autonomous agents can be daunting at first. But this article is a breakdown of LLM-based agents in a step-by-step sequence.

In this article you will find complete examples of working agents. Agents developed with a pro-code and no-code approach…all in the easy accessible open-source framework of 🦜🔗LangChain, which can run in a notebook environment.

What are agents in their simplest form? Considering the simple image below:

An Agent is constituted by one or more tools.

Tools enable an Agent to take certain actions.

Actions are used by the agent to solve each step of the decomposed problem which needs to be solved.

Autonomy

Agents are autonomous with regard to:

  1. Decomposition of the problem via chain-of-thought reasoning
  2. The sequence in which tools are used.
  3. How actions related to a tool are applied to each step of the problem.
  4. Defining success or failure, and determining when the end of the chain is reached with a satisfactory answer.

These actions can use a tool, while observing the results, a thought is reached. If the answer is sufficient, it serves as the final answer. Alternatively the agent loops back to the next action in the chain to solve the question.

Consider the following complex question:

What is the square root of the year the founder of SpaceX and Tesla was born and what is the name of the first company he founded?

The agent has the following tools at its disposal:

  • OpenAI gpt-4–0314
  • Wikipedia

The output from the Agent:

> Entering new AgentExecutor chain…

I need to find the birth year of the founder of SpaceX and Tesla, and the name of the first company he founded.

Action: Wikipedia

Action Input: Elon Musk

Observation: Page: Elon Musk

Thought:I now know the final answer

Final Answer: The square root of Elon Musk’s birth year (1971) is approximately 44.4, and the first company he founded is Zip2.

> Finished chain

The square root of Elon Musk’s birth year (1971) is approximately 44.4, and the first company he founded is Zip2.

It is clear how the Agent decomposes the question in a chain-of-thought reasoning approach. At the end of the article you will find the complete pro-code version for this LangChain Agent.

Below, the no-code / low-code ⛓️LangFlow version of this agent:

Users can click on the speech bubble in the chat window below for the complete chain-of-thought reasoning path…

Human-In-The-Loop

One of the Tools available to an Agent can be a Human. Hence Human-In-The-Loop tools allow the agent to take an action where a human can be consulted.

Agent Networks

Agents make use of a Conversational UI, and natural language is used for both input and output.

Due to this fact, a network of agents can be established. This is the notion where agents can consult each-other and one agent can use the output of another..

⭐️ Please follow me on LinkedIn for updates on LLMs ⭐️

Below the complete working Python code for the Agent described above:

pip install langchain
pip install wikipedia
pip install openai
pip install openai

from langchain.agents import load_tools
from langchain.agents import initialize_agent
from langchain.agents import AgentType
from langchain.llms import OpenAI

import os
os.environ['OPENAI_API_KEY'] = str("xxxxxxxxxxxxxxxxx")
llm = OpenAI(temperature=0,model_name='gpt-4-0314')

tools = load_tools(["wikipedia"], llm=llm)

agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True)

agent.run("What is the square root of the year the founder of SpaceX and Tesla born and what is the name of the first company he founded?")

I’m currently the Chief Evangelist @ HumanFirst. I explore and write about all things at the intersection of AI and language; ranging from LLMs, Chatbots, Voicebots, Development Frameworks, Data-Centric latent spaces and more.

https://www.linkedin.com/in/cobusgreyling
https://www.linkedin.com/in/cobusgreyling

--

--

Cobus Greyling

I explore and write about all things at the intersection of AI & language; LLMs/NLP/NLU, Chat/Voicebots, CCAI. www.cobusgreyling.com