// What is an AI Agent

AI Agent คืออะไร?

นิยาม, สถาปัตยกรรม, ReAct Loop, Tool Use และ Memory — อธิบายครบถ้วนภาษาไทย

// Definition

นิยามของ AI Agent

AI Agent คือโปรแกรม AI ที่สามารถ รับรู้สภาพแวดล้อม (Perceive), ตัดสินใจ (Decide) และลงมือทำ (Act) เพื่อบรรลุเป้าหมายที่กำหนดไว้ โดยไม่ต้องการการควบคุมทุกขั้นตอนจากมนุษย์

แตกต่างจาก Chatbot ทั่วไปที่แค่ รับ input → ส่ง output agent สามารถ วางแผน, ใช้ tools, ตรวจสอบผลลัพธ์ และปรับแผนใหม่ ได้อย่างอัตโนมัติ

พูดง่ายๆ คือ: Chatbot ตอบคำถาม, AI Agent แก้ปัญหา

Autonomous Goal-Directed Tool Use Planning Memory

📖 นิยามจาก OpenAI

"Agents are systems that independently accomplish tasks on your behalf" — ระบบที่ดำเนินงานให้คุณได้อย่างอิสระ โดยใช้ LLM เป็นสมองในการตัดสินใจ

📖 นิยามจาก Anthropic

Agentic settings คือ "LLMs operating with greater autonomy, executing long multi-step tasks, and working within larger systems" — ทำงานได้อย่างอิสระในขั้นตอนที่ยาวและซับซ้อน

// Core Loop

ReAct Loop — หัวใจของ AI Agent

ReAct (Reason + Act) คือ pattern หลักที่ agent ใช้ทำงาน — วนซ้ำจนกว่างานจะเสร็จ

01
🧠
Reason (คิด)
LLM วิเคราะห์สถานการณ์ปัจจุบัน ประเมิน context ทั้งหมด และตัดสินใจว่าควรทำอะไรต่อไป — เลือก tool ที่เหมาะสม
02
Act (ทำ)
เรียกใช้ tool ที่เลือก — อาจเป็นการค้นหาเว็บ, รัน Python, เรียก API, อ่านไฟล์ หรือส่ง email
03
👁️
Observe (สังเกต)
รับผลลัพธ์จาก tool กลับมา เพิ่มเข้าใน context แล้วเริ่ม Reason ใหม่ วนซ้ำจนงานเสร็จ
react_loop_example.py
# ตัวอย่าง ReAct Loop ในรูปแบบ Pseudocode def agent_loop(task: "Research best Python frameworks 2025"): memory = [] while not is_complete: # REASON: LLM คิดและวางแผน thought = llm.think(task, memory, available_tools) → "I need to search for recent Python framework rankings" # ACT: เรียก tool action = llm.choose_tool(thought) result = tools[action.name].run(action.params) → search("Python frameworks 2025 popularity") # OBSERVE: บันทึกผลลัพธ์ memory.append({"thought": thought, "action": action, "result": result}) → "Found: FastAPI #1, Django #2, Flask #3..." return final_answer
// Architecture

ส่วนประกอบของ AI Agent

🧠
LLM Brain (สมอง)
Large Language Model เป็น "สมอง" ของ agent — รับผิดชอบการ reason, วางแผน, ตัดสินใจเลือก action และ interpret ผลลัพธ์ เช่น GPT-4o, Claude 3.5, Gemini 1.5
🛠️
Tools (เครื่องมือ)
ชุดเครื่องมือที่ agent สามารถเรียกใช้ได้ เช่น web_search, code_interpreter, file_reader, email_sender, database_query, API calls ต่างๆ — ยิ่งมี tools มาก ยิ่งทำงานได้หลากหลาย
💾
Memory (ความจำ)
ระบบความจำหลายชั้น: Working Memory (context window), Episodic (บันทึกการกระทำ), Semantic (knowledge base), Procedural (skill memory) — ช่วยให้ agent เรียนรู้และปรับตัวได้
🎯
Planner (ผู้วางแผน)
โมดูลสำหรับแบ่งงานซับซ้อนออกเป็น subtasks ขนาดเล็ก เช่น Chain-of-Thought, Tree-of-Thought, MCTS Planning — ช่วยให้ tackle งานที่ใหญ่และซับซ้อนได้
พร้อมเรียนรู้ Agentic AI ในเชิงลึก?
ต่อด้วยหัวข้อ Agentic AI — ระดับ Autonomy และ paradigm ใหม่ของ AI