Articles

Two LLM Based Autonomous Agents Debate Each Other

COBUS GREYLING
August 28, 2023
.
4 min read

This working code example using the LangChain framework illustrates how two agents can debate each other after each agent has been assigned a persona and an objective. The agents have access to tools which they can leverage for their response.

As you will see below, after examining the LangSmith trace, that the LLM forms the backbone of the application and the tools provide relevant and up-to-date information.

In this LangChain example we have two Autonomous Agents having a conversation; one is named AI accelerationist and the other AI alarmist.

The two personas are described to the LLM in the following way:

AI accelerationist: A passionate visionary who sees the potential of automation and artificial intelligence as a catalyst for transformative progress. Fueled by an unwavering belief in technological advancement, you advocate for embracing and accelerating AI’s rise, confident that it will reshape industries, lead to an abundance of opportunities, and ultimately improve society.

AI alarmist: A cautious observer of technological advancements. With a mind steeped in apprehension, you perceive the growth of automation and AI as an impending threat. Your anxiety fuels your skepticism, pushing you to question the potential consequences of these technologies on the labor market and job security.

Both agents have access to the following tools to use for information retrieval to support its arguments:

  • Arxiv
  • Duck-Duck-Go Search
  • Wikipedia

The topic for the discussion is:

The current impact of automation and artificial intelligence on employment.

And the brief for each agent:

Your name is {name}.
Your description is as follows: {description}
Your goal is to persuade your conversation partner of your point of view.
DO look up information with your tool to refute your partner’s claims.
DO cite your sources.
DO NOT fabricate fake citations.
DO NOT cite any source that you did not look up.
Do not add anything else.
Stop speaking the moment you finish speaking from your perspective.

And here is the dialog between the two autonomous agents, the dialog are restricted to 6 dialog turns. The input from the moderator is in green:

With the response from the AI Alarmist in red and the AI Accelerationist in blue:

Below the completion of the six dialog turns:

Considering the view of LangChain below, it is clear how the latency increases as the prompt grows with each dialog turn. The tokens used also increase.

Here the trace is visible, with the sequence of events and the tools used are shown.

The complete code is listed here, this can be copied and pasted into any notebook and run. The only requirements are an OpenAI API Key, SerpAPI API Key and LangSmith API Key.

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

Subscribe to HumanFirst Blog

Get the latest posts delivered right to your inbox