Agentic AI in Action – Part 4 – Exploring Conversable Agents with AutoGen

Introduction 

This is Part – 4 of the multi-blog series on Agentic AI. In one of the earlier blogs (Part 2 of the Series), we explored a use case involving Autogen Assistant and User Proxy agents and hinted at covering Autogen Conversable Agents in a future blog. This blog delves into that topic, focusing on Conversable Agents—AI-driven entities designed to engage in dynamic, interactive dialogues with users or other agents. The AutoGen framework provides an intuitive way to create and manage these agents, enabling them to carry out discussions, exchange information, and simulate diverse conversational behaviors. In this blog, we will explore the implementation of conversable agents in AutoGen. 

Introduction to Autogen: 

AutoGen is a cutting-edge framework from Microsoft Research designed to simplify the creation of agentic AI systems and multi-agent collaboration. It enables developers to build autonomous agents that can collaborate, make decisions, and interact with users and external systems in a seamless manner. The core concept of AutoGen revolves around creating dynamic workflows where agents, driven by specific objectives, work together to achieve a desired outcome.  ConversableAgent in AutoGen is a customizable class for building conversational AI agents capable of managing contextual interactions and collaborating with other agents in dynamic workflows. 

The use case: 

This guide walks through a sample implementation where two agents, Joe and Jane, engage in a debate about remote work versus traditional office work. We will break down the code with detailed explanations. 

1. Import OS to interact with operating system variables


os provides a way to interact with the operating system and is used to manage environment variables. warnings.filterwarnings(‘ignore’) suppresses warning messages to keep the output clean.

2. Configuring the Model 

This defines a configuration list for the gpt-4o model. The “api_key” retrieves the OpenAI API key from environment variables to authenticate API calls

3. Creating a Conversable Agent ConversableAgent is a class from Microsoft’s Autogen framework, which is designed for multi-agent collaboration using Large Language Models (LLMs). It enables the creation of agents that can interact with each other, execute tasks, and dynamically adapt their behavior. 

With ConversableAgent from Autogen, we gain access to an LLM-powered agent that can: 

  • Engage in multi-agent conversations 
  • Execute automated workflows 
  • Process user queries and interact with other agents 
  • Leverage LLMs to assist in task completion 

The above code initializes a ConversableAgent named chatbot. It is configured to operate without requiring human input (human_input_mode=”NEVER”). 

4. Testing a Simple Agent Response


Th lets_test_the_agent function sends a user query to the agent, requesting a brief summary of Agentic AI in less than eight words. The output is printed to verify the agent’s ability to generate concise responses. 

5. Defining Two Agents with Contrasting Views

Let’s consider two AI agents – Jane and Joe, the former advocating for working from office and the latter an advocate of remote work. We will go ahead and define, configure the two agents. 


Joe’s system message defines his persona and instructs him to advocate for WFH with fun and concise responses. The is_termination_msg function allows Joe to exit the conversation when he detects “bye” in a message. 

Similarly, the Jane agent is created but supports traditional office work:

As seem above, Jane is configured to argue in favor of office work. Like Joe, her persona is predefined, and she exits the chat when “bye” is detected. 

6. Initiating a Debate Between the Agents 

Joe initiates a conversation with Jane, claiming that “work from home is just so cool.” The reflection_with_llm method is used to summarize the conversation after it ends.The max_turns parameter ensures that the chat does not exceed four exchanges.

A screenshot of part of the conversation output is displayed below.

We will format it for better display. 

7. Displaying the Chat History  


This code prints the chat_history of agents_chat in a structured and readable format using pprint, which is useful for inspecting complex data like conversation logs.

The result is displayed as follows:


8. Extracting the Conversation Summary 
This retrieves the summary of the conversation generated by the model as shown below. Again, we print this using pprint for better readability

9. Checking the Cost of the Interaction

Finally, we check the cost incurred. It is always a good practice to do this, so we are able to monitor costs. This calculates the cost of the LLM-generated conversation, along with the token details and is useful for API monitoring. 


This blog provided a step-by-step breakdown of how AutoGen can be used to create and manage conversable agents that engage in meaningful discussions. The example of Joe and Jane demonstrates how AI personas can be configured with unique viewpoints, enabling dynamic and interactive conversations. AutoGen ConversableAgents allow for structured AI conversations where can be programmed with specific viewpoints and personas. We also saw that conversations can be monitored, summarized, and cost-evaluated. 

Industry Use Cases: Conversable agents that communicate with each other, open exciting use cases across industries. For example, in customer support, one agent can handle customer queries while another gathers information from internal systems or databases, creating a seamless support experience.  

In healthcare, conversable agents can collaborate to streamline administrative processes – one agent can monitor and manage appointment scheduling by checking clinician availability, while another ensures insurance eligibility and pre-authorization for the patient. This interaction between agents reduces manual effort, minimizes scheduling errors, and ensures a smoother administrative workflow in medical facilities. 

In education, agents can work together as a teaching pair, with one explaining concepts while the other assesses a student’s progress or generates quizzes dynamically. For workplace productivity, agents can coordinate inter-departmental tasks, such as scheduling meetings where one agent finds available slots while another collects agenda points from team members. In legal services, one agent can draft or summarize legal documents while another cross-references case laws or compliance requirements, enhancing accuracy and efficiency. In finance, agents can collaborate by analyzing market data, with one focusing on real-time price trends while the other calculates optimal investment strategies. These use cases showcase the immense potential of conversable agents working together to provide intelligent, context-aware solutions. 

As seen in this blog, this framework opens the door for AI-driven debates, customer service bots, or interactive storytelling applications. Start experimenting with your own agent personas today! 

If you are interested in exploring and implementing use cases in Data and AI, please feel free toreach out to us. Our expertise spans across various domains, including finance, travel, healthcare, retail, logistics, and more. We help businesses unlock the potential of their data through innovative data and AI solutions. 

 



Leave a Reply