Agents

Autonomous Agents in the context of Large Language Models

Cobus Greyling
5 min readApr 26, 2023

--

As the implementations of Large Language Models (LLMs) expand in depth and width, a few requirements arise:

  1. The ability to program LLMs and create reusable prompts & seamlessly incorporate prompts into larger applications.
  2. Creating chains to sequence LLM interactions for larger applications.
  3. Automate impromptu chain-of-thought prompting via an agent which can act autonomous given the ambit of tools.
  4. Create scaleable prompt pipelines which can collect relevant data from various sources, all based on user input and constitute a prompt; and submit the prompt to a LLM.

“Any sufficiently advanced technology is indistinguishable from magic.”
- Arthur C. Clarke

With LLM related operations there is an obvious need for automation. Currently this automation is in the form of what is called agents.

Prompt Chaining is the execution of a predetermined and set sequence of actions.

The attraction of Agents is that Agents do not follow a predetermined sequence of events. Agents can maintain a high level of autonomy.

Considering the image below, Agents have access to a set of tools and any request which falls within the ambit of these tools can be addressed by the agent. The Execution pipeline lends autonomy to the Agent and a number of iterations might be required until the Agent reaches the Final Answer.

Actions which are executed by the agent involve:

  1. Using a tool
  2. Observing its output
  3. Cycling to another tool
  4. Returning output to the user

The diagram below shows how different action types are accessed and cycled through.

“Men have become the tools of their tools.”

- Henry David Thoreau

There is an observation, thought and eventually a final answer. The diagram shows how another action type might be invoked in cases where the final answer is not reached.

The output snipped below the diagram shows how the agent executes and how the chain is created in an autonomous fashion.

Taking LangChain as a reference, Agents have three concepts:

Tools

As was shown earlier in the article, there are a number of tools which can be used. A tool can be seen as a function that performs a specific duty.

Tools include Google Search, Database lookup, Python REPL, or even invoking existing chains.

Within the LangChain framework, the interface for a tool is a function that is expected to have:

  1. String as an input,
  2. And string as an output.

LLM

This is the language model powering the agent. Below is an example how the LLM is defined within the agent:

Agent Types

Agents use a LLM to determine which actions to take and in what order. The agent creates a chain-of-thought sequence on the fly by decomposing the user request.

Agents involve an LLM making decisions about which Actions to take, taking that Action, seeing an Observation, and repeating that until done. — Source

Agents are effective even in cases where the question is ambiguous and demands a multihop approach. This can be considered as an automated process of decomposing a complex question or instruction into a chain-of-thought process.

The image below illustrates the decomposition of the question well and how the question is answered in a piece meal chain-of-thought process:

Below is a list of agent types within the LangChain environment. Read more here for a full description of agent types.

Source

Considering the image below, the only change made to the code was the AgentType description. The change in response is clearly visible in this image, with the exact same configuration used and only a different AgentType.

For complete working code examples of LangChain Agents, read more here.

⭐️ Please follow me on LinkedIn for updates on Conversational AI ⭐️

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

--

--