Multi-Agent RAG

Một câu hỏi, nhiều chuyên gia.One question, many specialists.

Orchestrator tách câu hỏi cho các agent chuyên biệt. Mỗi agent truy xuất đúng nguồn của mình qua MCP, rồi kết quả được gộp thành một câu trả lời có dẫn nguồn.An orchestrator splits the question across specialist agents. Each one retrieves from its own source through MCP, and the findings are merged into one answer with citations.

Mạnh với câu hỏi rộng, nhiều nguồn. Tốn khoảng 15 lần token so với chat thường. Hầu hết bài toán không cần đến nó.Strong on broad, multi-source questions. Costs roughly 15× the tokens of a normal chat. Most problems don’t need it.

Multi-agent RAG pipeline: query, orchestrator with memory and planning, three agents fanned out at runtime, MCP layer, three data sources, generative model, answer with sources. Lớp giao thức MCP MCP protocol layer Query Memoryngắn + dài hạnshort + long Orchestratorphân rã · gộpsplit · merge PlanningReAct / CoT Agent A Agent B Agent C Dữ liệu nội bộPrivate data Web search Cloud tóm tắt có trích dẫn condensed, cited findings Generative model Trả lời + nguồnAnswer + sources
Nét đứt xanh: orchestrator quyết định lúc chạy gọi bao nhiêu agent, agent nào. Nét chấm hồng: kết quả quay về để tổng hợp.Green dashes: the orchestrator decides at runtime how many agents to call, and which. Pink dots: findings flowing back for synthesis.

Ảnh gốc dễ gây hiểu nhầm ở đâuWhere the original diagram misleads

Sơ đồ đúng về tinh thần. Trang này đã chỉnh năm chỗ dưới đây.The diagram is right in spirit. The five points below are corrected on this page.

  • “Aggregator” thực chất là orchestrator: nó phân rã và giao việc trước, rồi mới gộp kết quả.The “Aggregator” is really an orchestrator: it decomposes and dispatches first, then merges.
  • MCP không phải nguồn dữ liệu, mà là giao thức chuẩn hoá cách agent gọi tool và đọc dữ liệu.MCP is not a data source; it’s a protocol that standardizes how agents call tools and read data.
  • Generative model tách riêng là tuỳ chọn. Thường chính orchestrator viết câu trả lời cuối.A separate generative model is optional. Usually the orchestrator writes the final answer itself.
  • Có nguồn chưa chắc đã đúng. Citation có thể trỏ sai hoặc không ủng hộ khẳng định.Cited doesn’t mean correct. Citations can point to the wrong place or fail to support the claim.
  • Multi-agent không mặc định tốt hơn RAG một retriever. Nó tốn khoảng 15 lần token và chỉ đáng khi câu hỏi tách song song được.Multi-agent isn’t automatically better than single-retriever RAG. It costs about 15× the tokens and only pays off on parallelizable questions.

Trước hết: có cần gì không?First: do you need any of this?

Phần lớn bài toán hỏi đáp trên tài liệu dừng ở một trong các dòng dưới đây.Most document Q&A problems stop at one of the rows below.

Tình huốngSituationPhương án rẻ nhấtCheapest option
Toàn bộ tài liệu vừa context windowAll documents fit in the context windowĐưa thẳng vào prompt + prompt caching. Không retrieval.Put them in the prompt + prompt caching. No retrieval.
Câu hỏi tra cứu, một nguồnLookup questions, one sourceRAG thường: hybrid search + reranker.Plain RAG: hybrid search + reranker.
Dữ liệu có cấu trúcStructured dataText-to-SQL hoặc gọi API. Không cần vector.Text-to-SQL or an API call. No vectors.
Câu hỏi lặp lạiRepeated questionsFAQ hoặc cache câu trả lời.FAQ or an answer cache.
Kiến thức phổ thông, ổn địnhGeneral, stable knowledgeHỏi thẳng model.Ask the model directly.

Quy tắc: chỉ nâng lên một bậc phức tạp khi đã đo được bậc hiện tại thất bại trên câu hỏi thật.Rule: move up one level of complexity only after measuring the current level fail on real questions.

Chọn kiến trúc nào trong 30 giâyPick an architecture in 30 seconds

Câu hỏi cần dữ liệu nằm ngoài model?
├─ Không ─► Hỏi thẳng model.
└─ Có ─► Toàn bộ dữ liệu vừa context window?
    ├─ Có ─► Long context + prompt caching.
    └─ Không ─► Chỉ cần MỘT nguồn, MỘT lượt tra?
        ├─ Có ─► RAG thường (hybrid + reranker).
        └─ Không ─► Bước sau phụ thuộc kết quả bước trước?
            ├─ Có ─► Agentic RAG một agent (ReAct).
            └─ Không, tách song song được
                 ─► Chấp nhận token gấp nhiều lần?
                    ├─ Có ─► Multi-agent RAG.
                    └─ Không ─► Một agent, gọi tool song song.
Does the question need data outside the model?
├─ No ─► Ask the model directly.
└─ Yes ─► Does all the data fit in the context window?
    ├─ Yes ─► Long context + prompt caching.
    └─ No ─► ONE source, ONE lookup?
        ├─ Yes ─► Plain RAG (hybrid + reranker).
        └─ No ─► Does each step depend on the previous result?
            ├─ Yes ─► Single-agent agentic RAG (ReAct).
            └─ No, it splits into parallel parts
                 ─► Can you afford many times the tokens?
                    ├─ Yes ─► Multi-agent RAG.
                    └─ No ─► One agent, parallel tool calls.

Các khối trong sơ đồThe blocks in the diagram

Mỗi thẻ một khối. Màu thẻ là nhóm chức năng, xem quy ước ở cuối trang.One card per block. Card color is the functional group; see the key at the bottom.

Điều phốiControl

Orchestrator

Ảnh gọi là Aggregator agentCalled Aggregator agent in the image

Agent trung tâm: phân rã câu hỏi, gửi brief cho từng agent con, nhận về tóm tắt, quyết định đã đủ hay cần thêm vòng.The central agent: decomposes the question, sends each subagent a brief, collects summaries, and decides whether it has enough or needs another round.

Đánh đổiTrade-offĐổi chi phí token và khả năng dự đoán lấy khả năng phủ rộng nhiều nguồn cùng lúc.Trades token cost and predictability for broad, simultaneous coverage of many sources.

Dùng choUse for

  • Thẩm định nhà cung cấpVendor due diligence
  • Điều tra sự cố: log, ticket, runbookIncident investigation: logs, tickets, runbooks
  • Hỏi đáp xuyên nhiều hệ thống nội bộQ&A across several internal systems

ĐượcGain

  • Song song: giảm tới 90% thời gian với truy vấn phức tạpParallelism: up to 90% less time on complex queries
  • Vượt cấu hình một agent 90,2% trên eval của AnthropicBeat single-agent by 90.2% on Anthropic’s eval
  • Thêm nguồn bằng cách thêm agentAdd a source by adding an agent

MấtLose

  • Kế hoạch sai thì mọi agent cùng saiA bad plan misdirects every agent
  • Khoảng 15× token so với chatRoughly 15× the tokens of chat
  • Khó tái hiện lỗiHard to reproduce failures

Dấu hiệu:Telltale sign: câu hỏi có nhiều vế độc lập, mỗi vế nằm ở một hệ thống khác.the question has independent parts that live in different systems.

Điều phốiControl

Planning

ReAct · Chain-of-Thought

CoT viết ra các bước suy luận trước khi trả lời. ReAct lặp Thought → Action (gọi tool) → Observation, dùng kết quả mỗi vòng để chỉnh bước sau.CoT writes out reasoning before answering. ReAct loops Thought → Action (tool call) → Observation, using each result to adjust the next step.

Đánh đổiTrade-offĐổi độ trễ và token lấy độ chính xác trên câu hỏi nhiều bước.Trades latency and tokens for accuracy on multi-step questions.

Dùng choUse for

  • Câu hỏi nhiều bước (multi-hop)Multi-hop questions
  • So sánh có tính toánComparisons with arithmetic
  • Quyết định có cần tra thêmDeciding whether to search more

ĐượcGain

  • Chính xác hơn rõ rệt trên câu nhiều bướcClearly more accurate on multi-step questions
  • Vết suy luận đọc đượcA readable reasoning trace
  • Tự sửa khi gặp kết quả bất ngờSelf-corrects on surprises

MấtLose

  • Dễ lặp vô hạnProne to infinite loops
  • Mỗi vòng thêm độ trễ và tokenEach round adds latency and tokens
  • Suy luận viết ra chưa chắc là quá trình thậtWritten reasoning may not reflect the real process

Dấu hiệu:Telltale sign: câu trả lời phụ thuộc kết quả của một lượt tra trước.the answer depends on an earlier lookup’s result.

Điều phốiControl

Memory

Ngắn hạn + dài hạnShort + long term

Ngắn hạn là trạng thái trong phiên, nằm trong context window. Dài hạn là kho bên ngoài lưu fact và sở thích qua nhiều phiên.Short-term is in-session state inside the context window. Long-term is an external store keeping facts and preferences across sessions.

Đánh đổiTrade-offĐổi rủi ro dữ liệu lỗi thời và nghĩa vụ riêng tư lấy tính liên tục giữa các phiên.Trades stale-data risk and privacy obligations for continuity across sessions.

Dùng choUse for

  • Hỗ trợ khách nhớ lịch sử ticketSupport that remembers ticket history
  • Nghiên cứu kéo dài nhiều ngàyMulti-day research
  • Task vượt một context windowTasks larger than one context window

ĐượcGain

  • Không phải giải thích lạiNo re-explaining
  • Tái dùng kết quả đã traReuses past lookups
  • Giữ mạch task dàiKeeps long tasks on track

MấtLose

  • Memory cũ bị dùng như sự thậtStale memories reused as fact
  • Phân vùng sai làm rò rỉ dữ liệuBad partitioning leaks data
  • Nghĩa vụ xoá theo yêu cầuDeletion obligations

Dấu hiệu:Telltale sign: người dùng phải nhắc lại cùng một thông tin lần thứ hai.users repeat the same information a second time.

Thực thiWorkers

Specialist agents

Agent 1 · 2 · 3

Agent con phạm vi hẹp: một nguồn, một bộ tool, context riêng. Tự lặp tìm kiếm rồi trả về tóm tắt có trích dẫn, không trả dữ liệu thô.Narrow-scope subagents: one source, one toolset, their own context. They search iteratively and return cited summaries, never raw dumps.

Đánh đổiTrade-offĐổi sự nhất quán của một context chung lấy context sạch và khả năng chạy song song.Trades the coherence of one shared context for clean contexts and parallelism.

Dùng choUse for

  • Agent hợp đồng, agent số liệu, agent tin tứcContracts, metrics and news agents
  • Tách tìm code khỏi tìm tài liệuCode search apart from doc search
  • Hệ nhiều mức quyềnSystems with tiered permissions

ĐượcGain

  • Context không nhiễuNoise-free context
  • Model rẻ cho việc đơn giảnCheap models for simple work
  • Quyền tối thiểu theo agentLeast privilege per agent

MấtLose

  • Không thấy nhau, dễ mâu thuẫnBlind to each other; contradictions
  • Chi phí khởi tạo nhân theo số agentStartup overhead multiplies
  • Kém với việc cần quyết định nhất quánWeak on work needing consistent decisions

Dấu hiệu:Telltale sign: các nguồn cần cách truy vấn khác hẳn nhau (SQL, theo nghĩa, theo từ khoá).sources need very different query styles (SQL, semantic, keyword).

Truy cập dữ liệuData access

MCP servers

Model Context Protocol

Chuẩn mở (Anthropic, 11/2024) quy định cách agent kết nối tool và dữ liệu. Server khai báo tools, resources, prompts; agent gọi qua JSON-RPC. Là giao thức, không phải kho dữ liệu.An open standard (Anthropic, Nov 2024) for how agents connect to tools and data. Servers declare tools, resources and prompts; agents call them over JSON-RPC. A protocol, not a data store.

Đánh đổiTrade-offĐổi một lớp hạ tầng và bề mặt tấn công mới lấy integration viết một lần, dùng mọi nơi.Trades a new infrastructure layer and attack surface for integrations written once, used everywhere.

Dùng choUse for

  • Kết nối Drive, Notion, Jira, SlackConnecting Drive, Notion, Jira, Slack
  • Một server dùng chung nhiều agentOne server shared by many agents
  • Bọc DB hoặc API nội bộWrapping internal DBs or APIs

ĐượcGain

  • M × N integration thành M + NM × N integrations become M + N
  • Credential nằm ở server, không ở promptCredentials live in the server, not the prompt
  • Đổi model không viết lạiSwap models without rewrites

MấtLose

  • Prompt injection qua kết quả toolPrompt injection via tool output
  • Rủi ro chuỗi cung ứngSupply-chain risk
  • Mô tả tool ngốn contextTool descriptions eat context

Dấu hiệu:Telltale sign: bạn đang viết cùng một integration lần thứ hai.you’re writing the same integration a second time.

Truy cập dữ liệuData access

Nguồn dữ liệuData sources

Local data · Web search · Cloud

Ảnh chia theo vị trí. Phân biệt hữu ích hơn là riêng tư hay công khai, tĩnh hay đang đổi. Mỗi loại cần cách truy xuất riêng.The image splits by location. The more useful split is private vs. public, static vs. changing. Each kind needs its own retrieval.

Đánh đổiTrade-offĐổi độ phức tạp đồng bộ và kiểm soát chất lượng lấy độ phủ thông tin.Trades sync complexity and quality control for broader coverage.

Dùng choUse for

  • Nội bộ: quy trình, chính sáchPrivate: processes, policies
  • Web: tin tức, giá hiện tạiWeb: news, current prices
  • Cloud: dữ liệu sẵn trên S3, SharePointCloud: data already in S3, SharePoint

ĐượcGain

  • Kết hợp độ mới và độ chính xácFreshness plus accuracy
  • Hybrid search mạnh với tên riêng, mã sốHybrid search handles names and IDs
  • Reranker: cải thiện rẻ nhấtReranker: the cheapest win

MấtLose

  • Retrieval kém chặn trần chất lượngWeak retrieval caps quality
  • Chunking sai làm mất ngữ cảnhBad chunking loses context
  • Phải giữ quyền truy cập khi indexPermissions must survive indexing

Dấu hiệu:Telltale sign: câu trả lời cần cả thông tin nội bộ lẫn thông tin mới bên ngoài.the answer needs both internal and fresh external information.

Tổng hợpSynthesis

Trả lời có nguồnGrounded answer

Generative model → Answer + sources

Bước cuối: LLM viết câu trả lời chỉ từ bằng chứng đã gộp, mỗi khẳng định gắn một nguồn, nói rõ khi thiếu thông tin.The final step: an LLM writes the answer only from merged evidence, ties each claim to a source, and says so when information is missing.

Đánh đổiTrade-offĐổi độ trôi chảy và đôi khi độ đầy đủ lấy khả năng kiểm chứng.Trades fluency, and sometimes completeness, for verifiability.

Dùng choUse for

  • Trợ lý pháp lý, y tế, tài chínhLegal, medical, finance assistants
  • Báo cáo nghiên cứuResearch reports
  • Hỗ trợ khách trích đúng điều khoảnSupport quoting exact clauses

ĐượcGain

  • Kiểm chứng được từng ýEvery point verifiable
  • Ít bịa đặt hơnLess fabrication
  • Có vết kiểm toánAn audit trail

MấtLose

  • Citation có thể trỏ saiCitations can be wrong
  • Mâu thuẫn bị gộp thành giọng chắc chắnConflicts flattened into certainty
  • Mất sắc thái khi nénNuance lost in condensing

Dấu hiệu:Telltale sign: người đọc cần kiểm chứng trước khi hành động.readers must verify before acting.

Bảng đánh đổi giữa các kiến trúcArchitecture trade-offs

Các khối ở trên là bộ phận, không phải lựa chọn thay nhau. Quyết định thật nằm ở cấp kiến trúc. Số token là bậc độ lớn theo đo đạc của Anthropic.The blocks above are parts, not alternatives. The real decision is at the architecture level. Token figures are orders of magnitude from Anthropic’s measurements.

TrụcAxisLong contextRAG thườngPlain RAGAgentic RAG (1 agent)Agentic RAG (1 agent)Multi-agent RAG
Token / câu hỏiTokens / questionThấp nếu cacheLow with caching~1×~4×~15×
Độ trễLatencyThấpLowThấpLowTrung bìnhMediumCao, nhưng nhanh hơn làm tuần tựHigh, but beats sequential
Câu hỏi rộng, nhiều nguồnBroad, multi-sourceKém nếu không vừaPoor if it doesn’t fitKémPoorKháFairTốt nhấtBest
Nhiều bước phụ thuộcDependent multi-stepKháFairKémPoorTốtGoodKháFair
Dễ gỡ lỗiDebuggabilityRất dễVery easyDễEasyTrung bìnhMediumKhóHard
Độ khó vận hànhOperational burdenThấpLowThấpLowTrung bìnhMediumCaoHigh

Anti-patterns

Sai lầmMistakeVì sao saiWhy it’s wrongSửa thế nàoFix
Multi-agent cho câu hỏi một nguồnMulti-agent for one-source questionsToken gấp nhiều lần, chất lượng không tăngMany times the tokens, no quality gainRAG thường + rerankerPlain RAG + reranker
Brief cho agent con chỉ một dòngOne-line subagent briefsLàm trùng, lệch phạm vi, bỏ sótDuplicated work, scope drift, gapsMục tiêu, định dạng, tool, ranh giớiGoal, format, tools, boundaries
Agent con trả dữ liệu thôSubagents return raw dataContext orchestrator phình và nhiễuOrchestrator context bloatsTóm tắt nén có trích dẫnCondensed, cited summaries
Không giới hạn vòng lặpNo loop capChi phí bùng nổRunaway costSố vòng tối đa + ngân sách tokenMax rounds + token budget
Đánh giá bằng cảm giácJudging by feelKhông biết thay đổi nào có íchCan’t tell what helpedEval 20–50 câu hỏi thật từ tuần đầu20–50 real-question eval from week one
Coi nội dung tool là chỉ thịTreating tool output as instructionsPrompt injectionNội dung trả về chỉ là dữ liệuReturned content is data only
Kiểm soát quyền bằng promptAccess control by promptLLM không phải lớp bảo mậtAn LLM is not a security layerLọc quyền ở tầng retrievalFilter at the retrieval layer
Đổ lỗi cho modelBlaming the modelLỗi thường nằm ở retrievalThe fault is usually retrievalĐo recall@k riêngMeasure recall@k separately

3 điều cần nhớ3 things to remember

  • Multi-agent RAG dành cho câu hỏi rộng, nhiều nguồn, tách song song được. Nó không phải bản nâng cấp mặc định của RAG.Multi-agent RAG is for broad, multi-source, parallelizable questions. It is not the default upgrade to RAG.
  • Chất lượng câu trả lời bị chặn trên bởi retrieval và chất lượng brief giữa các agent, không phải bởi số agent.Quality is capped by retrieval and by the briefs between agents, not by how many agents you run.
  • Bắt đầu từ baseline rẻ nhất, dựng eval trước, chỉ thêm agent khi số liệu cho thấy cần.Start from the cheapest baseline, build evals first, add agents only when the numbers say so.