// Multi-Agent Systems

Multi-Agent Systems

ออกแบบระบบ agents หลายตัวทำงานร่วมกัน — Orchestration, Communication Patterns และ Design Principles

// Why Multi-Agent

ทำไมต้องใช้ หลาย Agents?

🎯
Specialization
แต่ละ agent ถูก fine-tune สำหรับ role เฉพาะ เช่น Researcher, Coder, Reviewer — ทำงาน domain ของตัวได้ดีกว่า generalist
Parallelism
tasks ที่ independent สามารถรันพร้อมกันได้ ลด latency และเพิ่ม throughput อย่างมีนัยสำคัญ
📏
Scale
งานที่ใหญ่เกิน context window ของ agent เดียว สามารถแบ่งให้หลาย agents ช่วยกันได้
// Orchestration Patterns

Patterns การ Orchestrate

🎭
Orchestrator → Worker
Agent กลาง (Orchestrator) รับงาน แบ่งเป็น subtasks และกระจายให้ Worker agents ต่างๆ แล้วรวม output — เหมาะสำหรับงานที่มีขั้นตอนชัดเจน
Orchestrator → [Researcher, Writer, Editor, QA]
🔗
Sequential Pipeline
Output ของ agent หนึ่งเป็น input ของ agent ถัดไป เหมือน assembly line — ง่ายต่อการ debug และ monitor
Collect → Analyze → Summarize → Format → Deliver
🏅
Peer-to-Peer (Debate)
Agents คุยกันโดยตรง แลกเปลี่ยนความเห็น โต้เถียง และหาฉันทามติ — ช่วยเพิ่มคุณภาพ output ผ่าน critical thinking
Agent A proposes → Agent B critiques → A refines
🗳️
Voting / Ensemble
หลาย agents ตอบคำถามเดียวกัน แล้วเลือกคำตอบที่ดีที่สุดจาก majority vote หรือ ranking — เพิ่ม reliability
3 agents → vote → best answer wins
// Code Example

ตัวอย่าง Multi-Agent ด้วย AutoGen

from autogen import AssistantAgent, UserProxyAgent, GroupChat, GroupChatManager import os config = [{"model": "gpt-4o", "api_key": os.environ["OPENAI_API_KEY"]}] # 1. สร้าง specialized agents researcher = AssistantAgent( name="Researcher", system_message="คุณเป็น researcher ผู้เชี่ยวชาญ ค้นหาข้อมูลและข้อเท็จจริง", llm_config={"config_list": config}, ) writer = AssistantAgent( name="Writer", system_message="คุณเป็น content writer เขียนบทความที่น่าสนใจและชัดเจน", llm_config={"config_list": config}, ) critic = AssistantAgent( name="Critic", system_message="คุณ review งานอย่างสร้างสรรค์ ชี้จุดปรับปรุง พร้อม approve เมื่อดีพอ", llm_config={"config_list": config}, ) user = UserProxyAgent(name="User", human_input_mode="NEVER", max_consecutive_auto_reply=0) # 2. สร้าง GroupChat group = GroupChat( agents=[user, researcher, writer, critic], messages=[], max_round=8, speaker_selection_method="round_robin", ) manager = GroupChatManager(groupchat=group, llm_config={"config_list": config}) # 3. เริ่มงาน user.initiate_chat(manager, message="เขียนบทความเรื่อง 'อนาคต AI Agents ในประเทศไทย' ความยาว 500 คำ")
ต้องการปรึกษาการออกแบบระบบ Agent?
ทีมเราช่วยออกแบบ Multi-Agent architecture ที่เหมาะกับ use case ของคุณ