587 từ
3 phút đọc
AutoGen (Microsoft): Hội thoại Multi-Agent và Sinh Code

LangGraph cho bạn graphs. CrewAI cho bạn đội. AutoGen cho bạn hội thoại.

Framework AutoGen của Microsoft được xây dựng lại từ đầu năm 2025 và khác hoàn toàn bản gốc. Kiến trúc mới bỏ hệ thống autobuild cũ để lấy mô hình agent-as-program — agents là các object Python thông thường giao tiếp qua tin nhắn có kiểu. Nó tích hợp Azure AI native, bảo mật doanh nghiệp và sandbox thực thi code không cần Docker.

Hơn 47,000 sao GitHub (trước khi rebuild) và cuộc sống thứ hai sau khi viết lại. AutoGen là cược của Microsoft vào hội thoại multi-agent như pattern tương tác chính cho hệ thống AI.


AutoGen Là Gì?#

AutoGen là framework hội thoại multi-agent từ Microsoft Research. Agents giao tiếp qua tin nhắn có cấu trúc — hãy nghĩ về nó như nền tảng nhắn tin nơi mỗi người tham gia là một AI agent với khả năng cụ thể.

from autogen_agent import Agent, ChatAgent, ToolAgent
from autogen_runtime import Runtime, GroupChat
class DataAnalyst(ChatAgent):
def __init__(self):
super().__init__(name="analyst")
self.system_prompt = "Bạn phân tích dữ liệu và tạo biểu đồ"
self.tools = [query_database, generate_chart]
class CodeReviewer(ChatAgent):
def __init__(self):
super().__init__(name="reviewer")
self.system_prompt = "Bạn review code cho bugs và bảo mật"
self.tools = [run_linter, check_security]

Agents đăng ký với Runtime và tham gia GroupChat. Tin nhắn chảy giữa các agent dựa trên routing rules hoặc vai trò được chỉ định.


Thay Đổi Lớn: 2025 Rebuild#

Khía cạnhAutoGen GốcAutoGen 2025
Agent modelAutobuild (dynamic)Agent-as-program (explicit)
Giao tiếpImplicit message passingTyped messages, declared contracts
StateẨn trong agent internalsExplicit trên Runtime
DebuggingBlack boxFull execution traces
Thực thi codeDocker bắt buộcBuilt-in sandbox (không Docker)
Azure integrationThủ côngNative Azure AI + Entra ID
MemoryKhông cóPersistent xuyên session

Khái Niệm Cốt Lõi#

Agents#

class CustomerSupportAgent(ChatAgent):
def __init__(self):
super().__init__(name="support")
self.system_prompt = """Bạn là agent L1 support.
Xử lý vấn đề thông thường:
- Reset password: dùng reset_password tool
- Billing: chuyển đến billing_agent
- Technical: chuyển đến tech_agent
"""
self.tools = [reset_password, lookup_account, search_kb]

Typed Messages#

Tin nhắn có trường kiểu, không phải text tự do:

@dataclass
class SupportTicket(Message):
ticket_id: str
customer_email: str
issue_type: str # "billing" | "technical" | "account"
description: str
priority: int

Đây là khác biệt lớn so với CrewAI. Tin nhắn typed có nghĩa:

  • Agents có thể xác thực cấu trúc tin nhắn
  • Routing dựa trên structured fields
  • Debug dễ hơn

GroupChat#

chat = GroupChat(
agents=[triage, billing, tech, escalation],
routing="round_robin",
max_turns=10,
admin_agent=escalation
)
ModeHành viUse Case
round_robinMỗi agent nói lần lượtTranh luận, brainstorming
role_basedTin nhắn route bởi to fieldSupport, workflow
broadcastTất cả agents nhận mọi tin nhắnChia sẻ thông tin
customHàm routing tự định nghĩaOrchestration phức tạp

Sandbox Thực Thi Code#

Tính năng nổi bật của AutoGen — sandbox built-in, không cần Docker:

from autogen_code import CodeExecutionAgent
coder = CodeExecutionAgent(
name="code_runner",
language="python",
sandbox="built-in",
timeout=30,
max_output_size=10000
)

Sandbox hoạt động bằng cách:

  1. Tạo process riêng cho mỗi lần thực thi
  2. Giới hạn truy cập filesystem vào thư mục temp
  3. Giới hạn network (allowlist configurable)
  4. Áp dụng memory và CPU limits
  5. Kill process vượt quá timeout

Tích Hợp Azure#

AutoGen là framework duy nhất tích hợp Azure AI native:

from autogen_azure import AzureRuntime
runtime = AzureRuntime(
model="gpt-4o",
deployment="my-deployment",
endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
auth="entra_id",
content_filter=True
)

Cho enterprise đã dùng Azure, integration này tự justify AutoGen.


AutoGen vs LangGraph vs CrewAI#

Khía cạnhAutoGenLangGraphCrewAI
Core metaphorHội thoạiGraphsVai trò
Message modelTyped messagesShared stateFreeform text
Thực thi codeBuilt-in sandboxExternal toolsExternal tools
Azure nativeKhôngKhông
HọcTrung bìnhCaoThấp
Tốt nhất choCode gen, enterprise supportWorkflow phức tạp, compliancePrototyping nhanh

Giới Hạn#

  1. Phụ thuộc Azure nặng — Content filtering, managed identity chỉ hoạt động với Azure
  2. Typed messages cần planning upfront — Chậm prototyping nhưng tốt cho correctness
  3. GroupChat có thể deadlock — Cần max_turns limit
  4. Ecosystem nhỏ hơn — Ít community tools hơn LangChain

Tiếp Theo#

BàiFramework
1LangGraph
2CrewAI
3AutoGen (bài này)
4Claude Agent SDK
5OpenAI Agents SDK
6So sánh cuối

Series: AI Agent Frameworks 2026 — So sánh Production. Bài 3: AutoGen. Bài 4: Claude Agent SDK → sắp tới.

Advertisement

AutoGen (Microsoft): Hội thoại Multi-Agent và Sinh Code
https://minixium.com/vi/posts/autogen-microsoft-multi-agent-conversations-code-generation-2026-vi/
Tác giả
Minixium
Đăng vào lúc
2026-05-23
Giấy phép bản quyền
CC BY-NC-SA 4.0

Advertisement