spinny:~/writing $ vim agentic-ai-frameworks-comparison.md
1~2AI Agent ได้ก้าวจากการสาธิตในงานวิจัยไปสู่ระบบ Production แล้ว คาดว่ากว่า 60% ของแอปพลิเคชัน AI ระดับองค์กรจะมีส่วนประกอบแบบ Agentic ภายในปี 2026 แต่การสร้าง Agent จากศูนย์ - จัดการ Tool Loop, State, Memory, Error Handling และการประสานงาน Multi-Agent - นั้นซับซ้อน นั่นคือจุดที่ Framework เข้ามามีบทบาท3~4สี่ Framework ที่ครองตลาดในปี 2026: **LangGraph**, **CrewAI**, **OpenAI Agents SDK** และ **Claude Agent SDK** แต่ละตัวใช้แนวทางที่แตกต่างกันโดยพื้นฐานต่อปัญหาเดียวกัน: การให้ LLM มีความสามารถในการใช้เหตุผล วางแผน ใช้เครื่องมือ และทำงานร่วมกัน5~6## ภาพรวม7~8| ด้าน | LangGraph | CrewAI | OpenAI Agents SDK | Claude Agent SDK |9|--------|-----------|--------|-------------------|-----------------|10| **โดย** | LangChain | CrewAI Inc. | OpenAI | Anthropic |11| **สถาปัตยกรรม** | แบบกราฟ | แบบบทบาท | แบบส่งต่อ | วนลูปอัตโนมัติ |12| **ปรัชญา** | ควบคุมสูงสุด | การทำงานเป็นทีม | การ Abstract น้อยที่สุด | ให้ Agent มีคอมพิวเตอร์ |13| **ภาษา** | Python, TypeScript | Python | Python | Python, TypeScript |14| **รองรับโมเดล** | ทุกโมเดล (OpenAI, Claude, Local) | ทุกโมเดล | ทุกโมเดล (แม้จะชื่อแบบนั้น) | เฉพาะ Claude |15| **GitHub stars** | ~29k | ~40k | ~21k | ~6k |16| **เหมาะที่สุดสำหรับ** | Workflow ที่ซับซ้อนและมี State | Multi-Agent เฉพาะทาง | Routing และ Triage | งานเขียนโค้ดและงานที่เน้นไฟล์ |17~18## LangGraph: ผู้สร้างกราฟ19~20LangGraph จำลอง Agent Workflow เป็น**กราฟมีทิศทางแบบวงจร** คุณกำหนด Node (ฟังก์ชันที่ทำงาน) และ Edge (การเปลี่ยนแปลงระหว่าง Node ซึ่งอาจเป็นแบบมีเงื่อนไขได้) State ไหลผ่านกราฟและถูกเก็บรักษาผ่าน Checkpointing21~22นี่คือ Framework ที่ชัดเจนและควบคุมได้มากที่สุด - คุณต่อทุกขั้นตอนด้วยตัวเอง23~24```mermaid25graph LR26 Start --> Router[Router Node]27 Router -->|needs research| Research[Research Node]28 Router -->|needs code| Code[Code Node]29 Research --> Synthesize[Synthesize Node]30 Code --> Synthesize31 Synthesize --> End32```33~34### แนวคิดหลัก35~36- **StateGraph**: การกำหนดกราฟที่มี State แบบกำหนดชนิด37- **Nodes**: ฟังก์ชัน Python ที่แปลง State38- **Edges**: การเชื่อมต่อระหว่าง Node สามารถเป็นแบบมีเงื่อนไข39- **Checkpointing**: ระบบเก็บรักษาข้อมูลในตัวสำหรับ Workflow ที่ทำงานยาวนาน40~41### ตัวอย่างโค้ด42~43```python44from langgraph.graph import StateGraph, MessagesState, START, END45from langchain_openai import ChatOpenAI46~47llm = ChatOpenAI(model="gpt-4o")48~49def call_agent(state: MessagesState):50 response = llm.invoke(state["messages"])51 return {"messages": [response]}52~53def should_continue(state: MessagesState):54 last = state["messages"][-1]55 if last.tool_calls:56 return "tools"57 return END58~59def call_tools(state: MessagesState):60 # Execute tool calls and return results61 results = []62 for tool_call in state["messages"][-1].tool_calls:63 result = execute_tool(tool_call)64 results.append(result)65 return {"messages": results}66~67graph = StateGraph(MessagesState)68graph.add_node("agent", call_agent)69graph.add_node("tools", call_tools)70graph.add_edge(START, "agent")71graph.add_conditional_edges("agent", should_continue, {"tools": "tools", END: END})72graph.add_edge("tools", "agent")73~74app = graph.compile()75result = app.invoke({"messages": [{"role": "user", "content": "What's the weather?"}]})76```77~78### จุดแข็ง79~80- ควบคุมทุกขั้นตอนและการเปลี่ยนแปลงอย่างละเอียด81- Checkpointing และ Human-in-the-Loop ในตัว82- รองรับ TypeScript อย่างเต็มรูปแบบ83- ใช้ได้กับทุก LLM Provider84- เหมาะที่สุดสำหรับ Workflow ที่ซับซ้อนมีการแยกสาขาตามเงื่อนไขและการวนลูป85~86### จุดอ่อน87~88- เส้นโค้งการเรียนรู้สูงชัน - ต้องเข้าใจแนวคิดทฤษฎีกราฟ89- ยาวเยิ่นเย้อสำหรับ Use Case ง่ายๆ - Agent พื้นฐานต้องเขียน Boilerplate มากกว่า Framework อื่น90- การ Debug กราฟอาจยากลำบากหากไม่มี LangSmith91~92### ราคา93~94Open-source (MIT) LangSmith (แพลตฟอร์ม Observability แบบจัดการ) มีแพ็กเกจเสียเงินสำหรับการ Monitor ระบบ Production95~96## CrewAI: ผู้ประกอบทีม97~98CrewAI ใช้การเปรียบเทียบกับมนุษย์: คุณรวบรวม **Crew** ของ Agent เฉพาะทาง แต่ละตัวมี **Role**, **Goal** และ **Backstory** Agent ทำงานร่วมกันใน **Task** โดยใช้ **Tool** ประสานงานด้วย **Process** (แบบลำดับ, แบบลำดับชั้น หรือแบบฉันทามติ)99~100ให้คิดว่าเหมือนการจ้างทีมที่สมาชิกแต่ละคนมีตำแหน่งงานและความเชี่ยวชาญเฉพาะ101~102```mermaid103graph TD104 Crew[Crew Manager] --> R[Researcher\nRole: Find data\nTools: WebSearch]105 Crew --> W[Writer\nRole: Write content\nTools: FileWrite]106 Crew --> E[Editor\nRole: Review quality\nTools: FileRead]107 R --> Task1[Research Task]108 W --> Task2[Writing Task]109 E --> Task3[Review Task]110 Task1 --> Task2 --> Task3111```112~113### แนวคิดหลัก114~115- **Agent**: Persona ที่มี Role, Goal, Backstory และ Tool116- **Task**: งานที่มีคำอธิบาย ผลลัพธ์ที่คาดหวัง และ Agent ที่ได้รับมอบหมาย117- **Crew**: กลุ่ม Agent ที่ทำงานร่วมกัน118- **Process**: กลยุทธ์การดำเนินงาน (แบบลำดับ, แบบลำดับชั้น, แบบฉันทามติ)119- **Flow**: ชั้น Orchestration แบบ Event-Driven สำหรับเชื่อมต่อหลาย Crew120~121### ตัวอย่างโค้ด122~123```python124from crewai import Agent, Task, Crew, Process125~126researcher = Agent(127 role="Senior Research Analyst",128 goal="Find comprehensive data about the given topic",129 backstory="You have 10 years of experience in technology research. "130 "You are thorough and always verify facts from multiple sources.",131 tools=[web_search_tool],132 verbose=True,133)134~135writer = Agent(136 role="Technical Writer",137 goal="Create clear, engaging technical content",138 backstory="You write for a developer audience. "139 "Your articles are practical and include code examples.",140 tools=[file_tool],141 verbose=True,142)143~144research_task = Task(145 description="Research the latest developments in WebAssembly in 2026. "146 "Focus on WASI, Component Model, and production use cases.",147 expected_output="A structured research document with key findings and sources.",148 agent=researcher,149)150~151writing_task = Task(152 description="Write a blog post based on the research. "153 "Include code examples and Mermaid diagrams.",154 expected_output="A complete blog post in Markdown format.",155 agent=writer,156 context=[research_task], # Writer receives researcher's output157)158~159crew = Crew(160 agents=[researcher, writer],161 tasks=[research_task, writing_task],162 process=Process.sequential,163 verbose=True,164)165~166result = crew.kickoff()167print(result.raw)168```169~170### จุดแข็ง171~172- การ Abstract แบบอิงบทบาทที่เข้าใจง่าย - ใช้เหตุผลง่าย173- Tool Integration ในตัวกว่า 100 รายการ174- Shared Memory ระหว่าง Agent (ระยะสั้น, ระยะยาว, Entity)175- ชุมชนใหญ่ที่สุด (~40k GitHub stars)176- Process แบบลำดับชั้นที่มี Agent "ผู้จัดการ" คอยมอบหมายงานและตรวจสอบ177~178### จุดอ่อน179~180- ควบคุมไม่ละเอียดเท่า LangGraph - คุณกำหนดบทบาท ไม่ใช่เส้นทางการดำเนินงานที่แน่นอน181- Process แบบลำดับชั้นอาจคาดเดาไม่ได้เมื่อ Agent มีความเห็นไม่ตรงกัน182- การ Debug การสนทนา Multi-Agent ยากกว่า Flow แบบ Single-Agent183~184### ราคา185~186Open-source แกนหลัก (ฟรี) CrewAI Platform: $99/เดือน (Teams) ถึง $120k/ปี (Enterprise) ราคาขึ้นอยู่กับจำนวน Crew ที่ใช้งานและจำนวนการดำเนินงานต่อเดือน187~188## OpenAI Agents SDK: ตัวจัดเส้นทาง189~190OpenAI Agents SDK (ผู้สืบทอดทางจิตวิญญาณของ Swarm) เน้นที่ **Handoff** - Agent ส่งต่อบทสนทนาไปยัง Agent เฉพาะทางอื่น นี่คือ Framework ที่เรียบง่ายที่สุด: Agent, Tool, Handoff และ Guardrail เท่านั้น191~192```mermaid193graph LR194 User --> Triage[Triage Agent]195 Triage -->|billing question| Billing[Billing Agent]196 Triage -->|refund request| Refund[Refund Agent]197 Triage -->|technical issue| Support[Support Agent]198 Billing --> Response[Response]199 Refund --> Response200 Support --> Response201```202~203### แนวคิดหลัก204~205- **Agent**: Model + Instructions + Tool + Handoff206- **Handoff**: การส่งต่อไปยัง Agent อื่น (ถูกจำลองเป็น Tool ที่ LLM เรียกใช้ได้)207- **Guardrail**: การตรวจสอบ Input/Output ที่ทำงานคู่ขนานกับ Agent208- **Runner**: ดำเนินการ Agent Loop209- **Tracing**: Observability ในตัวสำหรับการเรียก LLM, การเรียก Tool และ Handoff ทั้งหมด210~211### ตัวอย่างโค้ด212~213```python214from agents import Agent, Runner, handoff, InputGuardrail, GuardrailFunctionOutput215from pydantic import BaseModel216~217class SafetyCheck(BaseModel):218 is_safe: bool219 reason: str220~221async def content_safety(ctx, agent, input_text):222 result = await Runner.run(223 Agent(name="Safety", instructions="Check if input is safe. No PII."),224 input_text,225 context=ctx,226 )227 output = SafetyCheck.model_validate_json(result.final_output)228 return GuardrailFunctionOutput(229 output_info=output, tripwire_triggered=not output.is_safe230 )231~232billing_agent = Agent(233 name="Billing Agent",234 instructions="You handle billing inquiries. Be precise with numbers.",235 tools=[lookup_invoice, process_payment],236)237~238refund_agent = Agent(239 name="Refund Agent",240 instructions="You process refund requests. Always verify the order first.",241 tools=[lookup_order, issue_refund],242)243~244triage_agent = Agent(245 name="Triage Agent",246 instructions="Route the customer to the right specialist. "247 "Ask clarifying questions if needed.",248 handoffs=[billing_agent, refund_agent],249 input_guardrails=[InputGuardrail(guardrail_function=content_safety)],250)251~252result = await Runner.run(triage_agent, "I need a refund for order #4521")253print(result.final_output)254# The triage agent routes to refund_agent, which processes the refund255```256~257### จุดแข็ง258~259- รูปแบบ Handoff ที่สะอาด - เป็นธรรมชาติสำหรับ Workflow แบบ Routing/Triage260- Guardrail ทำงานคู่ขนานกับการดำเนินงาน (Fail-Fast ไม่ Blocking)261- Dashboard สำหรับ Tracing ในตัวเพื่อการ Debug262- แม้จะชื่อแบบนั้น แต่รองรับโมเดลที่ไม่ใช่ OpenAI ด้วย263- Abstract น้อยที่สุด - เข้าใจง่ายและขยายง่าย264~265### จุดอ่อน266~267- การจัดการ State ยังไม่เติบโตเท่า LangGraph268- ไม่มีระบบ Persistence หรือ Checkpointing ในตัว269- Ecosystem ของ Tool จากบุคคลที่สามมีขนาดเล็ก270- การออกแบบที่เน้น Handoff อาจไม่เหมาะกับทุกสถาปัตยกรรม271~272### ราคา273~274Open-source (MIT) คุณจ่ายตาม Token สำหรับโมเดลที่ใช้275~276## Claude Agent SDK: นักพัฒนา277~278Claude Agent SDK ใช้แนวทางที่แตกต่าง: แทนที่จะกำหนด Workflow หรือ Role คุณให้ Agent มี**ชุดเครื่องมือและปล่อยให้มันหาวิธีทำงานสำเร็จด้วยตัวเอง** มันใช้ Autonomous Loop เดียวกับที่ขับเคลื่อน Claude Code - อ่าน, ดำเนินการ, ตรวจสอบ, ทำซ้ำ279~280```mermaid281graph TD282 Prompt[User Prompt] --> Loop[Autonomous Agent Loop]283 Loop --> Reason[Reason about next step]284 Reason --> Act[Execute tool]285 Act --> Verify[Check result]286 Verify -->|not done| Loop287 Verify -->|done| Output[Final output]288```289~290### แนวคิดหลัก291~292- **query()**: จุดเข้าหลักที่เริ่ม Agent Loop293- **เครื่องมือในตัว**: Read, Write, Edit, Bash, Glob, Grep, WebSearch, WebFetch294- **Custom Tool ผ่าน MCP**: กำหนด Tool เป็น In-Process MCP Server295- **Sub-Agent**: Agent เฉพาะทางที่ Agent แม่สามารถมอบหมายงานให้296- **Sessions**: รักษา Context ข้ามการโต้ตอบหลายครั้ง297~298### ตัวอย่างโค้ด299~300```typescript301import { tool, createSdkMcpServer, query } from "@anthropic-ai/claude-agent-sdk";302import { z } from "zod";303~304const searchDocs = tool(305 "search_docs",306 "Search the internal documentation for relevant information",307 { query: z.string().describe("Search query") },308 async ({ query }) => {309 const results = await vectorStore.similaritySearch(query, 5);310 return {311 content: [{ type: "text", text: results.map(r => r.pageContent).join("\n\n") }],312 };313 }314);315~316const docsServer = createSdkMcpServer({317 name: "docs",318 version: "1.0.0",319 tools: [searchDocs],320});321~322for await (const message of query({323 prompt: "Find how authentication works in our system and write a summary",324 options: {325 mcpServers: { docs: docsServer },326 allowedTools: ["Read", "Glob", "Grep", "mcp__docs__search_docs"],327 },328})) {329 if (message.type === "result" && message.subtype === "success") {330 console.log(message.result);331 }332}333```334~335### จุดแข็ง336~337- การผสานรวม MCP ระดับ First-Class - เชื่อมต่อกับ Ecosystem ของ MCP Server ใดก็ได้338- เครื่องมือในตัวสำหรับการจัดการไฟล์ Terminal และการเข้าถึงเว็บ339- การบีบอัด Context อัตโนมัติสำหรับ Codebase ขนาดใหญ่340- การทำงานคู่ขนานของ Sub-Agent สำหรับงานที่ซับซ้อน341- Engine เดียวกับ Claude Code - ผ่านการพิสูจน์ในการทำงานจริงบน Workflow การพัฒนาจริง342~343### จุดอ่อน344~345- รองรับเฉพาะโมเดล Claude - ไม่รองรับหลาย Provider346- Framework ใหม่กว่าที่มีชุมชนเล็กกว่า347- ต้องการ Node.js Runtime แม้แต่สำหรับ Python SDK348- การควบคุม Workflow ที่ชัดเจนน้อยกว่าเมื่อเทียบกับ LangGraph349~350### ราคา351~352Open-source อัตรา Token มาตรฐานของ Claude API Managed Agents (เวอร์ชันโฮสต์): $0.08 ต่อชั่วโมง Session นอกเหนือจากค่า Token353~354## เมื่อไหร่ควรเลือกตัวไหน355~356```mermaid357graph TD358 Start{What's your priority?}359 Start -->|Full control over workflow| LG[LangGraph]360 Start -->|Multi-agent collaboration| CA[CrewAI]361 Start -->|Routing and triage| OA[OpenAI Agents SDK]362 Start -->|Coding and file automation| CS[Claude Agent SDK]363~364 LG --> LGU[Complex stateful workflows\nConditional branching\nHuman-in-the-loop]365 CA --> CAU[Team of specialized agents\nResearch + writing pipelines\nContent generation]366 OA --> OAU[Customer service routing\nMulti-step handoffs\nInput validation]367 CS --> CSU[Code generation and review\nFile-heavy automation\nMCP tool ecosystem]368```369~370### เลือก LangGraph ถ้า:371- คุณต้องการควบคุมทุกขั้นตอนของ Workflow อย่างแม่นยำ372- Use Case ของคุณเกี่ยวข้องกับ Logic เงื่อนไขที่ซับซ้อนและการวนลูป373- คุณต้องการ Persistence และ Human-in-the-Loop Checkpoint ในตัว374- คุณต้องใช้หลาย LLM Provider ใน Workflow เดียวกัน375~376### เลือก CrewAI ถ้า:377- คุณต้องการการ Abstract แบบอิงบทบาทที่เข้าใจง่าย378- งานของคุณเกี่ยวข้องกับ Agent หลายตัวที่มีความเชี่ยวชาญแตกต่างกัน379- คุณต้องการให้ Agent ทำงานร่วมกันและส่งต่อ Context ระหว่างกัน380- คุณให้ความสำคัญกับชุมชนที่ใหญ่ที่สุดและ Integration ในตัวมากที่สุด381~382### เลือก OpenAI Agents SDK ถ้า:383- รูปแบบหลักของคุณคือการจัดเส้นทางบทสนทนาไปยังผู้เชี่ยวชาญ384- คุณต้องการ Guardrail ที่ตรวจสอบ Input/Output แบบคู่ขนาน385- คุณต้องการ Abstract ที่ง่ายที่สุดด้วย Boilerplate น้อยที่สุด386- Tracing และ Observability ในตัวมีความสำคัญ387~388### เลือก Claude Agent SDK ถ้า:389- Agent ของคุณต้องอ่าน เขียน และรันโค้ด390- คุณต้องการการผสานรวม MCP Server ระดับ First-Class391- คุณต้องการ Agent อัตโนมัติที่ทำซ้ำและแก้ไขตัวเอง392- คุณใช้ Claude อยู่แล้วและต้องการการผสานรวมที่ลึกที่สุด393~394## สามารถผสมผสาน Framework ได้ไหม?395~396ได้ รูปแบบที่พบบ่อยคือใช้ Framework หนึ่งสำหรับ Orchestration และอีกตัวสำหรับ Agent แต่ละตัว:397~398- **LangGraph** สำหรับกราฟ Workflow โดยรวม399- **CrewAI** สำหรับ Node เฉพาะที่ต้องการการทำงานร่วมกันของ Multi-Agent400- **Claude Agent SDK** สำหรับ Sub-Task ที่เกี่ยวกับการเขียนโค้ดผ่าน MCP401- **OpenAI Agents SDK** สำหรับ Triage และ Routing ที่เผชิญหน้ากับลูกค้า402~403Framework เหล่านี้ไม่ได้แยกออกจากกัน ใช้สิ่งที่เหมาะกับแต่ละส่วนของระบบของคุณ404~405## บทสรุป406~407แต่ละ Framework มีทิศทางที่ชัดเจน:408~409- **LangGraph** เพิ่มประสิทธิภาพด้านการควบคุม - คุณตัดสินใจทุกการเปลี่ยนแปลง410- **CrewAI** เพิ่มประสิทธิภาพด้านการทำงานร่วมกัน - Agent ทำงานเป็นทีม411- **OpenAI Agents SDK** เพิ่มประสิทธิภาพด้านความเรียบง่าย - Abstract น้อยที่สุด Handoff ที่สะอาด412- **Claude Agent SDK** เพิ่มประสิทธิภาพด้านความเป็นอัตโนมัติ - ให้เครื่องมือและปล่อยให้มันทำงาน413~414ตัวเลือกที่ถูกต้องขึ้นอยู่กับ Workflow ทีม และ Stack เทคโนโลยีที่คุณมีอยู่ เลือกตัวที่ตรงกับ Use Case หลักของคุณ เรียนรู้มันให้ดี และดึงตัวอื่นเข้ามาเมื่อคุณพบจุดที่มันเก่ง415~
NORMAL · agentic-ai-frameworks-comparison.md [readonly]415 lines · :q to close