← Back to Tutorials

Microsoft AutoGen

Framework Overview

AutoGen is Microsoft's multi-agent conversation framework. Agents communicate via messages, support hierarchical conversation patterns, and can run distributed across machines.

pip install pyautogen

Agent Chat Tutorial

from autogen import AssistantAgent, UserProxyAgent

assistant = AssistantAgent(
    name="Assistant",
    llm_config={"config_list": [{"model": "gpt-4o", "api_key": "..."}]}
)

user = UserProxyAgent(
    name="User",
    human_input_mode="NEVER",
    code_execution_config=False
)

user.initiate_chat(
    assistant,
    message="Explain the concept of agentic AI in simple terms."
)

Advanced Interaction Patterns

PatternDescription
Two-Agent ChatBasic conversation between assistant and user
Group ChatMultiple agents discuss with a manager
Sequential ChatChain of agent conversations
Nested ChatChats within chats for complex workflows

Multimodal Features

AutoGen agents can process images, execute code, and scrape web content.

# Multimodal agent
assistant = AssistantAgent(
    name="MultimodalAssistant",
    llm_config={"config_list": [{"model": "gpt-4o"}]}
)

# Agent can analyze images sent as messages

AutoGen Core (Distributed)

AutoGen Core enables distributed agent communication via gRPC. Agents can run on different machines and communicate asynchronously.

Distributed Runtimes

# Agent running on a remote worker
from autogen.runtime import GrpcWorkerAgent

worker = GrpcWorkerAgent(
    name="Worker1",
    address="localhost:50051"
)

# Orchestrator sends tasks to workers
orchestrator.send_message(worker, "Process this data")

Self-Deploying Agents

Build agents that can autonomously deploy code, spin up new agents, and manage their own lifecycle.

✏️ Exercise: Build a group chat with three AutoGen agents: a Coordinator, a Researcher, and a Writer. The Coordinator manages the conversation, the Researcher fetches information, and the Writer generates the final output. Implement a sequential chat pattern where research results are passed to the writer.