XIMNET - The Leading Tech Agency In Malaysia
What is Agentic AI?

You might have heard the term "Agentic AI" in addition to LLMs and RAG chatbots. So, what is Agentic AI? Let's ask some of the AI systems:

Copilot:
Agentic AI is a type of advanced artificial intelligence that can perform tasks and make decisions independently, with minimal help from humans. It learns from past experiences, improves over time, and can handle complex tasks by breaking them down into smaller steps. This type of AI is used in areas like supply management, system security, and customer service, making work easier and faster by doing much of the thinking and planning on its own.

Gemini:
Agentic AI is a new breed of artificial intelligence that enables software agents to autonomously solve complex problems, make decisions, and take actions in the real world. These agents can analyze vast amounts of data, learn from their experiences, and adapt to changing circumstances, making them invaluable tools across industries like healthcare, finance, manufacturing, and logistics.

I feel the explanations above are too broad and vague. Let's dive deeper into the world of Agentic AI by exploring one of the frameworks: AutoGen. What is AutoGen? AutoGen is an open-source framework designed for building AI agent systems. It streamlines the creation of scalable and resilient applications by using an event-driven architecture. This enables AI agents to operate autonomously, collaborate efficiently, and handle distributed tasks with or without human supervision.

Coincidentally, there is a course on this topic, AI Agentic Design Patterns with AutoGen. Let's have some fun and take a look at the course.

Two-agents chat

We'll start with the simplest Agentic AI pattern by AutoGen, which involves two agents. In our example, adapted from the course, we have two agents: Xiao Ming, the funny foodie, and Ahmad, the serious foodie, as illustrated in the diagram below. In addition to the agents, there is also a loop with logic that determines when to stop.

Agentic AI using Autogen. Diagram generated with Claude's Artifacts.
Agentic AI using Autogen. Diagram generated with Claude's Artifacts.

Before we look at how to set up this example, let's first examine the outcome. It shows how two agents discussing a topic (Malaysian food) with each other and stopped after 3 turns:

First part of the conversation between two foodie agents,
First part of the conversation between two foodie agents,
Second part of the conversation between two foodie agents,
Second part of the conversation between two foodie agents,

As you can see, the two agents converse with each other without any human interruption. Let's look at the Autogen code below. Each agent is given its own system message (prompt) and configuration. The conversation is initiated by providing a starting message (prompt) and a maximum number of turns the chat can run.

Parts of Autogen code to set up Agentic AI
Parts of Autogen code to set up Agentic AI

What shown here is the Two-agent chat pattern, which is one of the many Conversation Patterns in Agentic AI by Autogen. You can customize the agent's system prompts to suit your needs.

Two-agent chat is the simplest form of conversation pattern, where two agents chat with each other.

Besides this pattern, there are other patterns such as:

Sequential chat: A series of dialogues between two agents, linked by a system that transfers the summary from one chat to inform the next.

Group chat: A single conversation that includes multiple agents.

Nested chat: Consolidates your workflow into one streamlined agent, making it easy to incorporate into larger processes.

Sequential chat

According to Autogen's documentation, a Sequential chat involves a sequence of interactions between two agents, connected through a carryover mechanism. This mechanism brings the summary of the previous chat into the context of the next one.

Here's the plan for the agents we will create:

Collect Name Agent - Asks for the customer's name.

Burger Patties Preference Agent - Inquires about the customer's preferred type of burger.

Fun Facts Agent - Shares an interesting fact based on the customer's selected patty.

So, in this sequence, there are interactions between two agents at each step:

Step 1: Collect Name Agent and Customer

Step 2: Burger Patties Preference Agent and Customer

Step 3: Fun Facts Agent and Customer

These agents will work together seamlessly to create an engaging and personalized experience for the customer. Below is a diagram that illustrates this agentic process.

Parts of Autogen code to set up Agentic AI
Flow of Sequential Chat pattern in Autogen

Let's look at the outcome. You can refer to the setup in the documentation for sequential chat or the course. The outcome may be different from what you see here since the LLM is non-deterministic.

Sequential Chat in Autogen
Sequential Chat pattern in AutoGen

After Emily replies that she wants a chicken patty, the next agent, the Fun Facts Agent, will step in and share some fun facts to keep Emily entertained while she waits for her burger.

Sequential Chat in Autogen
Sequential Chat in Autogen
Sequential Chat pattern in AutoGen

The Agentic AI flow may use many prompts and multiple calls to large language models (LLMs). Therefore, it may be expensive to use due to the large token usage. To find out the token usage, we can use the built-in token checker and cost calculator with the codes below

     for chat_result in chat_results:
          print(chat_result.cost)
          print("\n")

{
   "usage_including_cached_inference": {
   "total_cost": 0,
   "gpt-4o-2024-05-13": {   
        "cost": 0,
        "prompt_tokens": 50,
        "completion_tokens": 6,
        "total_tokens": 56
}
},
   "usage_excluding_cached_inference": {
   "total_cost": 0,
   "gpt-4o-2024-05-13": {
        "cost": 0,
        "prompt_tokens": 50,
        "completion_tokens": 6,
        "total_tokens": 56
   }
  }
}

If you notice that the total cost is 0, I suspect this is because the AutoGen framework is not updated with the latest GPT-4 model yet. If we use an older model like GPT-3.5-turbo, we can see the cost besides the token usage.

Challenges so far include...

In the two agents example, which is fully autonomous, the result seems to be very good. However, for the sequential agentic AI pattern that involves human input, there are some challenges if we want to use it for real-world applications.

  1. Hit or miss in collecting names. Sometimes the LLM cannot get the name and returns the context with an empty name.
  2. Too helpful in deciding for humans. When I tested the patty agent, I selected lamb, which is not one of the available patties, but the LLM returned the context as beef.
  3. If we try to ask for the name and location in the first step and set the max turn to 2, it will still be stuck at the second step even though the human has already replied with the name and location in the first turn.

Agentic AI Challenges
In this output, the sequential agent does not proceed to the second agent (patties selection) even though the name and location are collected because the maximum turn is set to 2.
Agentic AI Challenges
In this output, the sequential agent randomly picked beef when human choose lamb which is not a part of the selection.

It is obvious that this pattern cannot be used in real-world burger ordering since human beings are inherently unpredictable and capable of making complex decisions based on a multitude of factors. For challenges 1 & 2, we need a strategy to make the agent check and reask for relevant information.

Can LLMs with proper prompting and framework alone solve all real-world scenarios involving nested dialogs, branching, and looping? Or do we need to mix LLMs with other strategies? Stay tuned for our future exploration.


XIMNET is a digital solutions provider with two decades of track records specialising in web application development, AI Chatbot and system integration in Malaysia. XIMNET is launching a brand new way of building ChatGPT-powered AI Chatbot with XTOPIA.IO. Get in touch with us to find out more.
about the article

XIMNET is one of the leading tech agency for AI Chatbot in Malaysia.

other good reads
Copyright 2024 © XIMNET MALAYSIA SDN BHD (516045-V).  All rights reserved   |  Privacy Policy  |  Get in Touch  |  Powered by XTOPIA.IO
Ooops!
Generic Popup2