spinny:~/writing $ vim agentic-ai-frameworks-comparison.md
1~2AI Agent da chuyen tu cac ban demo nghien cuu sang he thong production. Du kien hon 60% ung dung AI doanh nghiep se bao gom cac thanh phan agentic vao nam 2026. Nhung viec xay dung Agent tu dau - quan ly tool loop, state, memory, xu ly loi va phoi hop multi-agent - rat phuc tap. Do la ly do framework ra doi.3~4Bon framework thong tri nam 2026: **LangGraph**, **CrewAI**, **OpenAI Agents SDK** va **Claude Agent SDK**. Moi framework co cach tiep can hoan toan khac nhau cho cung mot van de: trao cho LLM kha nang suy luan, lap ke hoach, su dung cong cu va hop tac.5~6## Tong quan7~8| Khia canh | LangGraph | CrewAI | OpenAI Agents SDK | Claude Agent SDK |9|--------|-----------|--------|-------------------|-----------------|10| **Nha phat trien** | LangChain | CrewAI Inc. | OpenAI | Anthropic |11| **Kien truc** | Dua tren do thi | Dua tren vai tro | Dua tren ban giao | Vong lap tu chu |12| **Triet ly** | Kiem soat toi da | Hop tac nhom | Truu tuong toi thieu | Cho Agent mot may tinh |13| **Ngon ngu** | Python, TypeScript | Python | Python | Python, TypeScript |14| **Ho tro model** | Bat ky (OpenAI, Claude, local) | Bat ky | Bat ky (bat chap ten goi) | Chi Claude |15| **GitHub stars** | ~29k | ~40k | ~21k | ~6k |16| **Phu hop nhat cho** | Workflow phuc tap co state | Chuyen mon hoa multi-agent | Routing va triage | Lap trinh va tac vu nang ve file |17~18## LangGraph: Nha xay dung do thi19~20LangGraph mo hinh hoa workflow cua Agent duoi dang **do thi co huong co chu ky**. Ban dinh nghia cac node (ham thuc hien cong viec) va edge (chuyen tiep giua chung, co the la co dieu kien). State chay qua do thi va duoc luu tru thong qua checkpointing.21~22Day la framework ro rang va kiem soat duoc nhat - ban tu tay noi tung buoc.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### Khai niem cot loi35~36- **StateGraph**: dinh nghia do thi voi state co kieu37- **Nodes**: ham Python chuyen doi state38- **Edges**: ket noi giua cac node, co the co dieu kien39- **Checkpointing**: luu tru tich hop cho workflow chay dai40~41### Vi du code42~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### Diem manh79~80- Kiem soat chi tiet tung buoc va tung chuyen tiep81- Checkpointing va human-in-the-loop tich hop82- Ho tro TypeScript day du83- Hoat dong voi bat ky LLM provider nao84- Phu hop nhat cho workflow phuc tap co phan nhanh dieu kien va vong lap85~86### Diem yeu87~88- Duong cong hoc tap doc - can hieu cac khai niem ly thuyet do thi89- Dai dong cho use case don gian - agent co ban can nhieu boilerplate hon cac framework khac90- Debug luong do thi co the kho khan neu khong co LangSmith91~92### Gia ca93~94Open-source (MIT). LangSmith (nen tang observability quan ly) co cac goi tra phi cho giam sat production.95~96## CrewAI: Nha to chuc nhom97~98CrewAI su dung phep an du cua con nguoi: ban tap hop mot **crew** gom cac agent chuyen biet, moi agent co **role**, **goal** va **backstory**. Cac agent hop tac tren cac **task** su dung **tool**, duoc dieu phoi boi **process** (tuan tu, phan cap hoac dong thuan).99~100Hay nghi ve no nhu viec tuyen mot doi ngu ma moi thanh vien co mot chuc danh va chuyen mon cu the.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### Khai niem cot loi114~115- **Agent**: persona co role, goal, backstory va tool116- **Task**: nhiem vu co mo ta, dau ra ky vong va agent duoc chi dinh117- **Crew**: nhom agent lam viec cung nhau118- **Process**: chien luoc thuc thi (tuan tu, phan cap, dong thuan)119- **Flow**: lop orchestration huong su kien de ket noi nhieu crew120~121### Vi du code122~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### Diem manh171~172- Truu tuong dua tren vai tro truc quan - de suy luan173- Hon 100 tool integration tich hop174- Bo nho chia se giua cac agent (ngan han, dai han, entity)175- Cong dong lon nhat (~40k GitHub stars)176- Process phan cap voi agent "quan ly" uy quyen va xac nhan177~178### Diem yeu179~180- Kiem soat it chi tiet hon LangGraph - ban dinh nghia vai tro, khong phai duong thuc thi chinh xac181- Process phan cap co the kho du doan khi cac agent bat dong182- Debug cuoc hoi thoai multi-agent kho hon luong single-agent183~184### Gia ca185~186Open-source core (mien phi). CrewAI Platform: $99/thang (Teams) den $120k/nam (Enterprise). Gia dua tren so crew hoat dong va so lan thuc thi hang thang.187~188## OpenAI Agents SDK: Bo dinh tuyen189~190OpenAI Agents SDK (nguoi ke thua tinh than cua Swarm) tap trung vao **handoff** - agent chuyen cuoc hoi thoai cho agent chuyen biet khac. Day la framework toi gian nhat: agent, tool, handoff va guardrail. Chi vay thoi.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### Khai niem cot loi204~205- **Agent**: model + instructions + tool + handoff206- **Handoff**: chuyen tiep den agent khac (duoc mo hinh hoa nhu tool ma LLM co the goi)207- **Guardrail**: xac thuc input/output chay song song voi agent208- **Runner**: thuc thi agent loop209- **Tracing**: observability tich hop cho moi cuoc goi LLM, tool va handoff210~211### Vi du code212~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### Diem manh258~259- Mau handoff gon gang - tu nhien cho workflow routing/triage260- Guardrail chay song song voi thuc thi (fail-fast, khong blocking)261- Dashboard tracing tich hop de debug262- Bat chap ten goi, ho tro cac model khong phai cua OpenAI263- Truu tuong toi thieu - de hieu va de mo rong264~265### Diem yeu266~267- Quan ly state chua truong thanh bang LangGraph268- Khong co persistence hoac checkpointing tich hop269- Ecosystem tool cua ben thu ba nho hon270- Thiet ke lay handoff lam trung tam co the khong phu hop moi kien truc271~272### Gia ca273~274Open-source (MIT). Ban tra phi theo token cho bat ky model nao su dung.275~276## Claude Agent SDK: Nha phat trien277~278Claude Agent SDK co cach tiep can khac: thay vi dinh nghia workflow hay role, ban cho agent **mot bo cong cu va de no tu tim cach hoan thanh nhiem vu**. No su dung cung vong lap tu chu nhu Claude Code - doc, hanh dong, xac minh, lap lai.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### Khai niem cot loi291~292- **query()**: diem vao chinh khoi dong agent loop293- **Cong cu tich hop**: Read, Write, Edit, Bash, Glob, Grep, WebSearch, WebFetch294- **Custom tool qua MCP**: dinh nghia tool la in-process MCP server295- **Sub-agent**: agent chuyen biet ma agent cha co the uy quyen296- **Sessions**: duy tri context qua nhieu lan tuong tac297~298### Vi du code299~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### Diem manh336~337- Tich hop MCP cap first-class - ket noi voi bat ky ecosystem MCP server nao338- Cong cu tich hop cho thao tac file, terminal va truy cap web339- Tu dong nen context cho codebase lon340- Sub-agent song song cho cac tac vu phuc tap341- Cung engine voi Claude Code - da duoc thu nghiem thuc te tren workflow phat trien that342~343### Diem yeu344~345- Chi ho tro model Claude - khong ho tro nhieu provider346- Framework moi hon voi cong dong nho hon347- Can Node.js runtime ngay ca voi Python SDK348- Kiem soat workflow it ro rang hon so voi LangGraph349~350### Gia ca351~352Open-source. Gia token Claude API tieu chuan. Managed Agents (phien ban hosted): $0.08 moi gio session ngoai chi phi token.353~354## Khi nao chon cai nao355~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### Chon LangGraph neu:371- Ban can kiem soat chinh xac tung buoc cua workflow372- Use case cua ban lien quan den logic dieu kien phuc tap va vong lap373- Ban can persistence va human-in-the-loop checkpoint tich hop374- Ban can su dung nhieu LLM provider trong cung mot workflow375~376### Chon CrewAI neu:377- Ban muon truu tuong dua tren vai tro truc quan378- Nhiem vu cua ban lien quan den nhieu agent co chuyen mon khac nhau379- Ban can cac agent hop tac va truyen context cho nhau380- Ban coi trong cong dong lon nhat va nhieu integration tich hop nhat381~382### Chon OpenAI Agents SDK neu:383- Mau chinh cua ban la dinh tuyen cuoc hoi thoai den chuyen gia384- Ban can guardrail xac thuc input/output song song385- Ban muon truu tuong don gian nhat voi boilerplate toi thieu386- Tracing va observability tich hop la quan trong387~388### Chon Claude Agent SDK neu:389- Agent cua ban can doc, viet va thuc thi code390- Ban muon tich hop MCP server cap first-class391- Ban can agent tu chu co kha nang lap lai va tu sua loi392- Ban da su dung Claude va muon tich hop sau nhat393~394## Co the ket hop cac framework khong?395~396Co. Mot mau pho bien la su dung mot framework cho orchestration va mot framework khac cho tung agent rieng le:397~398- **LangGraph** cho do thi workflow tong the399- **CrewAI** cho node cu the can hop tac multi-agent400- **Claude Agent SDK** cho sub-task lien quan den lap trinh qua MCP401- **OpenAI Agents SDK** cho triage va routing huong toi khach hang402~403Cac framework nay khong loai tru lan nhau. Hay su dung cai phu hop voi tung phan cua he thong.404~405## Ket luan406~407Moi framework co mot dinh huong ro rang:408~409- **LangGraph** toi uu hoa cho kiem soat - ban quyet dinh tung chuyen tiep410- **CrewAI** toi uu hoa cho hop tac - cac agent lam viec nhu mot doi411- **OpenAI Agents SDK** toi uu hoa cho su don gian - truu tuong toi thieu, handoff gon gang412- **Claude Agent SDK** toi uu hoa cho tu chu - cho no cong cu va de no lam viec413~414Lua chon dung phu thuoc vao workflow, doi ngu va stack cong nghe hien tai cua ban. Chon cai phu hop voi use case chinh, hoc ky no va dua cac framework khac vao khi ban gap the manh cua chung.415~
NORMAL · agentic-ai-frameworks-comparison.md [readonly]415 lines · :q to close