Bỏ qua để đến nội dung

LangGraph — Agent Reasoning & Orchestration của DataValue

Trong trang AI & Agentic, để xây một AI Agent thực sự, chỉ có LLM là chưa đủ. Một Agent doanh nghiệp có thể phải: hiểu yêu cầu người dùng; xác định dữ liệu cần lấy; gọi Semantic Layer; đọc tài liệu liên quan; đánh giá kết quả; quyết định có cần lấy thêm thông tin; dùng một hoặc nhiều tools; xin con người phê duyệt nếu cần; tiếp tục sau khi được duyệt; cuối cùng chuyển quyết định thành Business Action. Đây không còn là một lần gọi LLM — đây là một stateful, multi-step reasoning workflow.

LangGraph — Agent Reasoning & Orchestration Layer: lớp điều phối cách AI Agent suy luận, dùng context, gọi tools, quản lý state và phối hợp con người để hoàn thành một business goal. LangGraph tự mô tả là low-level orchestration framework for building stateful agents, hướng đến agent/workflow chạy dài, cần kiểm soát và tùy biến cao — hỗ trợ durable execution, persistence, memory và human-in-the-loop.

Một LLM thường: Prompt → LLM → Response. Với “doanh thu tháng này bao nhiêu?”, LLM nhận context, xử lý, trả lời. Nhưng với “tại sao doanh thu tháng này giảm và nên ưu tiên xử lý ở đâu?”, AI phải: Understand Question → Get Revenue → Compare Previous Period → Identify Declining Region → Identify Products → Identify Customers → Check Business Context → Retrieve Relevant Policies → Analyze Possible Causes → Recommend Actions. Không còn là Prompt → Response mà thành Goal → Plan → Tools → Data → Reasoning → Decision — bước chuyển từ LLM Application sang AI Agent.

Agent lấy Revenue được −12% — bước tiếp là gì? Agent cần quyết định: Which Region? → South −21% → Which Product? → Category A −32% → Which Customers?, rồi có cần đọc hợp đồng? kiểm tra pricing policy? xem service history?. Đây là một decision flow. LLM reasoning ở từng bước, nhưng cần một orchestration layer quản lý toàn bộ: STATE → STEP → DECISION → NEXT STEP → TOOL → NEW STATE → NEXT DECISION. Đó là vai trò của LangGraph.

LangGraph biểu diễn agent workflow dưới dạng graph: Nodes (các bước xử lý) và Edges (cách di chuyển giữa các bước):

flowchart TB
  S["START"] --> U["Understand Request"] --> G["Get Data"] --> A["Analyze Result"]
  A -->|"Need More?"| GM["Get More Data"] --> A
  A -->|"Enough"| R["Recommend Action"] --> E["END"]

Mỗi Node có thể là: LLM · Tool · API · Function · Retriever · Business Rule · Human Approval · Another Agent. Nhờ đó Agent không còn là black box — nó thành một controllable reasoning workflow.

Một Agent nhiều bước cần biết trạng thái hiện tại (ví dụ Sales Agent: Question, Period=August 2026, Revenue Change=−12%, Affected Region=South, Affected Product=Category A, Current Step=Customer Analysis). Đây chính là State: User Request → STATE → Node A → Update State → Node B → Update State → Node C. Không quản lý state thì mỗi bước hoạt động như một request độc lập; LangGraph được thiết kế cho stateful agents (trạng thái duy trì xuyên suốt workflow).

Ví dụ Customer Intelligence Agent (“khách hàng nào có nguy cơ rời bỏ?”): Understand → Get Customer Metrics → Find Revenue Decline → Check Purchase Frequency → Check Last Purchase → Calculate Risk → Retrieve Customer Context → Reason → Generate Recommendation. Nhưng không phải customer nào cũng đi cùng path — Risk < 50? → Yes: Monitor / No: Deep Analysis → Check Contract → Check Service → Recommend Action. Đây là nơi graph-based orchestration trở nên hữu ích.

Deterministic Workflow và AI Reasoning cùng tồn tại

Phần tiêu đề “Deterministic Workflow và AI Reasoning cùng tồn tại”

Không phải bước nào cũng nên để AI quyết. Revenue < Threshold là business rule (không cần LLM); nhưng “nguyên nhân nào giải thích sự suy giảm?” cần AI. Một Agent tốt kết hợp DETERMINISTIC LOGIC + AI REASONING (ví dụ Get Revenue → decline > 10%? → No: END / Yes: AI Analysis → Need Context? → Yes: Get Docs / No: Recommend). Tài liệu LangGraph định vị framework cho các trường hợp cần kết hợp deterministic và agentic workflows, tùy biến sâu, kiểm soát tốt execution.

Agent doanh nghiệp cần tương tác nhiều hệ thống qua tools: get_revenue(), get_customer(), get_orders(), get_inventory(), search_contract(), search_policy(), create_followup(). LLM quyết định “tôi cần Revenue data”, LangGraph điều phối gọi tool, tool trả kết quả, state cập nhật, agent reason tiếp: Reason → Choose Tool → Call Tool → Get Result → Update State → Reason Again. Đây là một nền tảng của Agentic AI.

Agent không nên tự suy luận từ hàng trăm raw tables khi business metrics đã chuẩn hóa. Tốt hơn: LangGraph Agent → Cube → Trusted Business Metrics → ClickHouse. Agent hỏi Cube (Revenue by Customer/Product/Region, Period = Last 6 Months), Cube trả về data theo định nghĩa đã governance, LangGraph reasoning tiếp. Cube giúp Agent hiểu Business Data; LangGraph điều phối cách Agent dùng Business Data đó để reasoning — hai bên không thay nhau (Cube trả lời Revenue nghĩa là gì, metric nào certified; LangGraph trả lời Agent nên làm bước nào trước, khi nào gọi Revenue, khi nào lấy thêm context, khi nào recommend).

Structured Data chỉ giải một phần. Agent phát hiện Customer A giảm doanh thu 42%, nhưng để tìm nguyên nhân cần Customer Contract, Pricing Policy, Discount Policy, Sales SOP, Service History, Product Documentation — Enterprise Knowledge. Kiến trúc: LangGraph → {Cube (structured business context), LlamaIndex (knowledge/RAG)}. Agent có thể: Cube → Customer Revenue ↓42% + LlamaIndex → Customer Contract + Pricing Policy → LangGraph → Reason across both contexts. Cô đọng: Cube = what the business data says · LlamaIndex/RAGFlow = what the enterprise knows · LangGraph = how the Agent reasons across them.

Agent không nhất thiết đi một đường cố định — path được chọn dựa trên state và kết quả tại runtime (Analyze Customer → Healthy? → Yes: END / No: Check Purchase → Need Contract? → Yes: Retrieve Contract → Reason / No: Recommend). Khác biệt lớn giữa Fixed Workflow và Agentic Workflow.

Human reasoning hiếm khi diễn ra một lần (xem dữ liệu → đặt giả thuyết → kiểm tra → chưa đủ → lấy thêm → đánh giá lại). Agent cũng vậy: Analyze → Enough Evidence? → No: Get More Data → Analyze / Yes: Recommend. Graph biểu diễn được những vòng lặp này — lý do Agent xử lý được bài toán phức tạp hơn một chuỗi prompt cố định.

AI Assistant không nên quên toàn bộ context sau mỗi interaction (“Phân tích Customer A” → “So sánh với Customer B” → “Vậy ai cần ưu tiên?”). LangGraph cung cấp nền tảng cho state và memory — cả working context trong workflow lẫn persistent memory cho interaction dài hơn (Conversation → Agent State → Memory → Next Interaction). Quan trọng với business copilots hoạt động lâu dài.

Agent workflow doanh nghiệp không phải lúc nào cũng xong trong vài giây: AI Recommendation → Manager Approval → Wait 4 Hours → Approved → Continue, hoặc Supplier Analysis → Request Information → Wait → Response Received → Continue. LangGraph hỗ trợ durable execution — workflow duy trì execution state và tiếp tục sau interruption/failure thay vì chạy lại từ đầu. Rất quan trọng khi Agent đi từ demo sang business process thực tế.

Enterprise AI không có nghĩa AI tự quyết mọi thứ. Ví dụ Agent đề xuất Discount 10% cho Customer A → Discount <= 5%? → Yes: Continue / No: Human Approval → {Approve → Execute, Reject → END}. LangGraph hỗ trợ human-in-the-loop (workflow dừng ở điểm cần con người rồi tiếp tục). DataValue không hướng tới AI → Everything mà AI → Reason → Decision Boundary → Human/Policy/Rule → Controlled Action, với phân loại LOW RISK → Automatic · MEDIUM RISK → User Confirmation · HIGH RISK → Formal Approval. Agent không chỉ thông minh mà còn phải controllable.

Cả hai đều có workflow nhưng giải hai loại khác nhau: LangGraph = Agent Reasoning Workflow (Understand → Get Data → Reason → Need More Context? → Use Tool → Reason Again → Decide); n8n = Business Automation Workflow (Create CRM Task → Assign Owner → Send Email → Request Approval → Update ERP). Vậy LangGraph = Think & Orchestrate, n8n = Automate & Act — LangGraph quyết định cần làm gì, n8n đảm bảo business workflow được thực thi thế nào (LangGraph: "Customer A churn risk cao" → Decision → n8n: Create CRM Task, Assign Salesperson, Priority High, Notify Manager).

LangGraph không phải AI model — không cạnh tranh với OpenAI/Claude/Gemini/Llama. Nó là orchestration framework nằm trên model (LLM/MODEL → LANGGRAPH). Thực tế linh hoạt hơn: LANGGRAPH → {Model A, Model B, Tools} — Agent có thể dùng model phù hợp cho từng task. LangGraph dùng được độc lập với LangChain, thiết kế như orchestration layer thay vì model provider — hợp nguyên tắc DataValue should remain model-neutral (xem chọn LLM).

Dễ nhầm. LangChain cung cấp framework & integrations để xây LLM/agent applications nhanh (Simple Agent → LangChain). LangGraph nằm ở lớp orchestration thấp hơn, cho trường hợp cần kiểm soát sâu hơn (Complex/Stateful/Controlled Agent → LangGraph). LangChain phù hợp để nhanh chóng xây agent với abstraction sẵn; LangGraph phù hợp khi cần advanced customization và controllable agent workflows. Và LangChain Agents nay cũng xây trên LangGraph để dùng persistence & human-in-the-loop.

Một bài toán lớn có thể cần nhiều specialized Agent. Ví dụ Management Agent (“tại sao profitability tháng này giảm?”): Sales Agent → Analyze Revenue, Finance Agent → Analyze Cost, Supply Agent → Analyze Logistics/Inventory, rồi Results → Management Agent → Enterprise Explanation. LangGraph dựng được graph/subgraph kiểu này. Nhưng DataValue không cần bắt đầu bằng multi-agent — nguyên tắc: use the simplest agent architecture that solves the business problem.

Sales Performance Agent (“tại sao doanh thu tháng này giảm?”): START → Understand → Query Cube (Revenue 88B vs Previous 100B = −12%) → Query by Region (South −21%, North −3%, Central +2%) → Query by Product (Category A −32%) → Query by Customer (15 khách = 72% mức giảm) → LlamaIndex (Pricing Policy, Contracts) → Reason (Data + Knowledge) → "Phần lớn mức giảm ở Distributor miền Nam Category A; 15 khách đóng góp 72%; một nhóm bị ảnh hưởng bởi thay đổi commercial terms" → Recommend follow-up 5 khách giá trị cao → Decision → n8n (Create CRM Tasks, Assign Owners, Notify Manager). Đây chính là Reasoning-to-Action.

Cùng architecture áp dụng cho Inventory Intelligence Agent (“sản phẩm nào nguy cơ thiếu hàng 14 ngày tới?” → Query Inventory Metrics → Identify Risk → Check Demand/Open PO/Supplier Lead Time → Enough Supply? → Recommend → n8n Replenishment) và Finance Intelligence Agent (“tại sao Cash Position thấp hơn kế hoạch?” → Cash Position → Compare Forecast → Analyze AR/AP → Identify Overdue → Explain Cash Gap → Recommend Collection Priorities → n8n).

DataValue không cần xây mọi Agent từ đầu — có thể chuẩn hóa patterns: Analysis Agent (Understand → Query → Analyze → Explain), Decision Agent (Understand → Gather Context → Evaluate → Recommend), Action Agent (Analyze → Decide → Validate → Approval → n8n), Management Agent (Detect Exception → Root Cause → Business Impact → Recommendation → Follow-up). Những pattern này trở thành reusable building blocks.

Từ AI Assistant đến Agentic Enterprise (4 cấp)

Phần tiêu đề “Từ AI Assistant đến Agentic Enterprise (4 cấp)”

Level 1 AI Chat (Question → Answer) · Level 2 AI Assistant (Question → Data/Knowledge → Answer) · Level 3 AI Agent (Goal → Reason → Tools → Decision) · Level 4 Agentic Enterprise (Business Event → Agent → Reason → Decision → Controlled Action → Outcome → Learning). LangGraph đặc biệt quan trọng ở Level 3–4.

Một workflow có thể có 15 Nodes, 8 Tool Calls, 3 Model Calls, 2 Retrievals, 1 Human Approval — agent thực sự đã làm gì? Cần theo dõi Execution, State, Tool Calls, Latency, Errors, Model Usage, Quality, Outcome → AI Observability & Evaluation (Langfuse): LangGraph tập trung orchestration, Langfuse tập trung observability & evaluation — bổ sung nhau.

flowchart TB
  U["Business User"] --> AG["AI Agent"] --> LG["LANGGRAPH · Reason · Orchestrate"]
  LG --> CUBE["Cube · Business Data"] & LI["LlamaIndex · Knowledge"] & OM["OpenMetadata · Data Context"]
  LG --> LLM["LLM / Model"] --> DEC["Decision"] --> N8N["n8n · Automate · Execute"] --> ACT["CRM · ERP · APIs → Outcome & Learning"]
  LF["Langfuse · Observe · Evaluate · Improve"] -. cross-cutting .-> AG

Phía dưới tất cả vẫn là Data Foundation Odoo → Airbyte → ClickHouse → dbt → Cube. LangGraph đứng chính giữa CONTEXT → LANGGRAPH → DECISION → ACTION — vị trí rất chiến lược.

Kết luận: LangGraph không phải mục tiêu — Business Decision mới là mục tiêu

Phần tiêu đề “Kết luận: LangGraph không phải mục tiêu — Business Decision mới là mục tiêu”

Đừng giới thiệu LangGraph bằng “chúng tôi dùng graph để xây Agent” — business quan tâm: Agent có hiểu vấn đề không? dùng đúng dữ liệu không? giải thích được nguyên nhân không? recommend hữu ích không? biết khi nào cần hỏi con người không? chuyển được recommendation thành action không? LangGraph là technology giúp làm những điều đó — giá trị thực không phải build a graph mà build a controllable reasoning process.

LLM mang khả năng Reasoning, nhưng trong doanh nghiệp reasoning cần một cấu trúc có thể kiểm soát: Agent cần biết mình đang làm gì, đã có context nào, cần gọi tool nào, bước tiếp là gì, khi nào cần thêm dữ liệu, khi nào hỏi con người, khi nào đủ bằng chứng để recommend, khi nào một quyết định được phép thành action. Đó là vai trò LangGraph. Trong DataValue: Cube → Trusted Business Context · LlamaIndex → Enterprise Knowledge · LLM → Reasoning Capability · LangGraph → điều phối Reasoning Process · n8n → Decision thành Controlled Action · Langfuse → quan sát & cải thiện AI.

LangGraph — Agent Reasoning & Orchestration Layer của DataValue — chuyển từ “AI trả lời câu hỏi” sang “AI hiểu mục tiêu → thu thập context → reason → dùng tools → đánh giá → quyết định → phối hợp hành động” — bước quan trọng để DataValue tiến từ AI Assistant đến Agentic Intelligence: Data → Trusted Meaning → Insight → Context → Reasoning → Decision → Controlled Action → Outcome → Learning → Value.

Chia sẻ: