AutoGen: Microsoft's Multi-Agent Conversation Framework

# AutoGen: Framework Multi-Agent Conversation dari Microsoft AutoGen adalah framework open-source dari Microsoft Research yang memungkinkan pengembangan aplikasi berbasis Large Language Model (LLM) m...

By Ruby Abdullah · · tutorial
AutoGenMulti-AgentMicrosoftLLMPython

AutoGen: Microsoft's Multi-Agent Conversation Framework

AutoGen is an open-source framework from Microsoft Research that enables the development of LLM-based applications using a multi-agent conversation architecture. With AutoGen, you can create multiple AI agents that communicate, collaborate, and solve complex tasks automatically.

In this tutorial, we will learn how to use AutoGen from installation, creating various types of agents, building multi-agent conversations, to building a virtual software development team consisting of a planner, coder, and tester.

Why AutoGen?

Before we begin, let's understand why AutoGen has become a popular choice for building multi-agent systems:

  • Multi-Agent Conversation: Agents can communicate with each other naturally
  • Customizable: Each agent can be configured with different behaviors, tools, and LLMs
  • Human-in-the-Loop: Supports human intervention in conversation flows
  • Code Execution: Agents can write and execute code automatically
  • Teachable Agents: Agents can learn from previous interactions
  • Nested Chats: Supports hierarchical conversations for complex workflows

Installation

Prerequisites

Make sure you have Python 3.8 or later installed on your system.

Basic Installation

pip install pyautogen

Installation with Additional Features

# With Docker support for code execution

pip install pyautogen[docker]

With teachable agents support

pip install pyautogen[teachable]

Full installation

pip install pyautogen[docker,teachable]

LLM Configuration

AutoGen requires access to an LLM. Create a configuration file OAICONFIGLIST:

[

{

"model": "gpt-4",

"apikey": "sk-your-openai-api-key"

},

{

"model": "gpt-3.5-turbo",

"apikey": "sk-your-openai-api-key"

}

]

Or use environment variables:

import os

os.environ["OPENAIAPIKEY"] = "sk-your-openai-api-key"

Core Agent Concepts

ConversableAgent

ConversableAgent is the base class for all agents in AutoGen. Every agent that can communicate inherits from this class.
import autogen

configlist = autogen.configlistfromjson("OAICONFIGLIST")

llmconfig = {

"configlist": configlist,

"temperature": 0,

}

Create a basic ConversableAgent

agent = autogen.ConversableAgent(

name="basicagent",

llmconfig=llmconfig,

systemmessage="You are a helpful assistant.",

humaninputmode="NEVER",

)

Important humaninputmode parameters:

  • "ALWAYS": Always asks for human input before responding
  • "NEVER": Never asks for human input
  • "TERMINATE": Asks for input only when the conversation is about to end

AssistantAgent

AssistantAgent is an agent designed to be an AI assistant. By default, it uses an LLM to generate responses.
assistant = autogen.AssistantAgent(

name="assistant",

llmconfig=llmconfig,

systemmessage="""You are an AI assistant that helps complete tasks.

Provide clear and structured solutions.

Reply with 'TERMINATE' when the task is complete."""

)

UserProxyAgent

UserProxyAgent acts as a proxy for a human user. It can execute code and forward input from humans.
userproxy = autogen.UserProxyAgent(

name="userproxy",

humaninputmode="TERMINATE",

maxconsecutiveautoreply=10,

isterminationmsg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"),

codeexecutionconfig={

"workdir": "coding",

"usedocker": False, # Set True for security

},

)

Two-Agent Conversations

The simplest conversation involves two agents communicating with each other.

Related Articles

CrewAI Tutorial: Building Multi-Agent AI Framework

CrewAI - Framework AI Multi-Agen Daftar Isi Pendahuluan Prasyarat Instalasi dan Pengaturan Konsep Dasar 5...

Complete LangGraph Tutorial: Building Complex AI Agents

Tutorial Lengkap LangGraph: Membangun AI Agents yang Kompleks LangGraph adalah library dari LangChain untuk membangun st...

TRL Tutorial: LLM Post-Training with SFT, DPO, and Reward Modeling

Post-Training LLM dengan TRL: SFT, Reward Modeling, dan DPO Setelah sebuah base language model selesai dipretraining, mo...

Axolotl Tutorial: Configuration-Driven LLM Fine-Tuning

Fine-Tuning LLM Berbasis Konfigurasi dengan Axolotl Kebanyakan proyek fine-tuning dimulai dengan cara yang sama: seseora...