Home Technology peripherals AI Hands-on Guide to Building Multi Agent Chatbots with Autogen

Hands-on Guide to Building Multi Agent Chatbots with Autogen

Mar 19, 2025 am 09:51 AM

AutoGen empowers sophisticated multi-agent chatbot development, moving beyond simple question-answer systems. This article details how AutoGen facilitates advanced conversation patterns like sequential and nested chats, enabling dynamic, multi-participant interactions for complex workflows. We previously explored two-agent chatbots; this expands upon that foundation.

Table of Contents

  • What are Multi-Agent Chatbots?
  • AutoGen's Conversation Patterns
  • Understanding Sequential Chat
  • Prerequisites
  • Implementation
    • Defining Tasks
    • Defining Agents
    • Example Conversation
    • Analyzing Results
  • Conclusion
  • Frequently Asked Questions

What are Multi-Agent Chatbots?

Multi-agent chatbots leverage multiple specialized AI agents working collaboratively to handle intricate tasks or conversations. Each agent possesses expertise in a specific area (e.g., question answering, recommendation generation, data analysis). This division of labor results in more accurate and efficient responses. The coordinated efforts of multiple agents provide richer, more nuanced interactions than single-agent systems, making them suitable for complex scenarios in customer service, e-commerce, and education.

AutoGen's Conversation Patterns

AutoGen offers several conversation patterns for managing multi-agent interactions:

  1. Sequential Chat: A series of two-agent conversations, where each chat's summary informs the next.
  2. Group Chat: A single conversation involving multiple agents, requiring strategic agent response management.
  3. Nested Chat: Encapsulates a workflow within a single agent for reuse in larger workflows.

This article focuses on implementing Sequential Chat.

Understanding Sequential Chat

Sequential Chat involves a chain of two-agent conversations. The summary of one chat becomes the context for the subsequent chat.

Hands-on Guide to Building Multi Agent Chatbots with Autogen

The diagram illustrates a sequence of chats, potentially with a common agent across chats or different agents for each interaction. This approach is valuable when a task is divisible into interdependent sub-tasks, each best handled by a specialized agent.

Prerequisites

Before building AutoGen agents, obtain necessary LLM API keys and set up Tavily for web searching. Load API keys into a .env file. Define the LLM configuration:

config_list = {
    "config_list": [{"model": "gpt-4o-mini", "temperature": 0.2}]
}
Copy after login

Install autogen-agentchat (version 0.2.37 or later).

Implementation

This example creates a stock analysis system using Nvidia and Apple as examples.

Defining Tasks

financial_tasks = [
    """What are the current stock prices of NVDA and AAPL, and how is the performance over the past month in terms of percentage change?""",
    """Investigate possible reasons for the stock performance leveraging market news.""",
]

writing_tasks = ["""Develop an engaging blog post using any information provided."""]
Copy after login

Defining Agents

import autogen

financial_assistant = autogen.AssistantAgent(name="Financial_assistant", llm_config=config_list)
research_assistant = autogen.AssistantAgent(name="Researcher", llm_config=config_list)
writer = autogen.AssistantAgent(name="writer", llm_config=config_list, system_message="""
    You are a professional writer, known for your insightful and engaging articles.
    You transform complex concepts into compelling narratives.
    Reply "TERMINATE" in the end when everything is done.
    """)

user_proxy_auto = autogen.UserProxyAgent(name="User_Proxy_Auto", human_input_mode="ALWAYS",
                                         is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"),
                                         code_execution_config={"work_dir": "tasks", "use_docker": False})

user_proxy = autogen.UserProxyAgent(name="User_Proxy", human_input_mode="ALWAYS",
                                    is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"),
                                    code_execution_config=False)
Copy after login

user_proxy_auto handles code execution (set human_input_mode="ALWAYS" for code review). user_proxy interacts with the writer agent.

Example Conversation

chat_results = autogen.initiate_chats([
    {"sender": user_proxy_auto, "recipient": financial_assistant, "message": financial_tasks[0], "clear_history": True, "silent": False, "summary_method": "last_msg"},
    {"sender": user_proxy_auto, "recipient": research_assistant, "message": financial_tasks[1], "summary_method": "reflection_with_llm"},
    {"sender": user_proxy, "recipient": writer, "message": writing_tasks[0]}
])
Copy after login

Analyzing Results

The chat_results variable contains the conversation history for each agent. The example shows the writer agent's output:

Hands-on Guide to Building Multi Agent Chatbots with Autogen

Conclusion

AutoGen's sequential chat pattern enables the creation of sophisticated multi-agent chatbots capable of handling complex tasks and conversations. This approach is highly beneficial for various applications requiring collaborative AI agents.

Frequently Asked Questions

Q1. What are multi-agent chatbots, and how do they work? Multi-agent chatbots utilize multiple specialized agents to collaboratively manage complex conversations by dividing tasks.

Q2. What conversation patterns does AutoGen support? AutoGen supports sequential, group, and nested chat patterns for efficient multi-agent coordination.

Q3. How does Sequential Chat function in AutoGen? Sequential Chat chains two-agent conversations, using each chat's summary as context for the next.

Q4. What are practical applications of AutoGen's multi-agent patterns? These patterns are valuable in customer service, finance, e-commerce, and other fields requiring complex, adaptive chatbot interactions.

The above is the detailed content of Hands-on Guide to Building Multi Agent Chatbots with Autogen. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1670
14
PHP Tutorial
1273
29
C# Tutorial
1256
24
How to Build MultiModal AI Agents Using Agno Framework? How to Build MultiModal AI Agents Using Agno Framework? Apr 23, 2025 am 11:30 AM

While working on Agentic AI, developers often find themselves navigating the trade-offs between speed, flexibility, and resource efficiency. I have been exploring the Agentic AI framework and came across Agno (earlier it was Phi-

How to Add a Column in SQL? - Analytics Vidhya How to Add a Column in SQL? - Analytics Vidhya Apr 17, 2025 am 11:43 AM

SQL's ALTER TABLE Statement: Dynamically Adding Columns to Your Database In data management, SQL's adaptability is crucial. Need to adjust your database structure on the fly? The ALTER TABLE statement is your solution. This guide details adding colu

Beyond The Llama Drama: 4 New Benchmarks For Large Language Models Beyond The Llama Drama: 4 New Benchmarks For Large Language Models Apr 14, 2025 am 11:09 AM

Troubled Benchmarks: A Llama Case Study In early April 2025, Meta unveiled its Llama 4 suite of models, boasting impressive performance metrics that positioned them favorably against competitors like GPT-4o and Claude 3.5 Sonnet. Central to the launc

OpenAI Shifts Focus With GPT-4.1, Prioritizes Coding And Cost Efficiency OpenAI Shifts Focus With GPT-4.1, Prioritizes Coding And Cost Efficiency Apr 16, 2025 am 11:37 AM

The release includes three distinct models, GPT-4.1, GPT-4.1 mini and GPT-4.1 nano, signaling a move toward task-specific optimizations within the large language model landscape. These models are not immediately replacing user-facing interfaces like

How ADHD Games, Health Tools & AI Chatbots Are Transforming Global Health How ADHD Games, Health Tools & AI Chatbots Are Transforming Global Health Apr 14, 2025 am 11:27 AM

Can a video game ease anxiety, build focus, or support a child with ADHD? As healthcare challenges surge globally — especially among youth — innovators are turning to an unlikely tool: video games. Now one of the world’s largest entertainment indus

New Short Course on Embedding Models by Andrew Ng New Short Course on Embedding Models by Andrew Ng Apr 15, 2025 am 11:32 AM

Unlock the Power of Embedding Models: A Deep Dive into Andrew Ng's New Course Imagine a future where machines understand and respond to your questions with perfect accuracy. This isn't science fiction; thanks to advancements in AI, it's becoming a r

Rocket Launch Simulation and Analysis using RocketPy - Analytics Vidhya Rocket Launch Simulation and Analysis using RocketPy - Analytics Vidhya Apr 19, 2025 am 11:12 AM

Simulate Rocket Launches with RocketPy: A Comprehensive Guide This article guides you through simulating high-power rocket launches using RocketPy, a powerful Python library. We'll cover everything from defining rocket components to analyzing simula

Google Unveils The Most Comprehensive Agent Strategy At Cloud Next 2025 Google Unveils The Most Comprehensive Agent Strategy At Cloud Next 2025 Apr 15, 2025 am 11:14 AM

Gemini as the Foundation of Google’s AI Strategy Gemini is the cornerstone of Google’s AI agent strategy, leveraging its advanced multimodal capabilities to process and generate responses across text, images, audio, video and code. Developed by DeepM

See all articles