Đánh giá AI agentAI agent evals

Đừng hỏi agent có tốt không. Hỏi nó sai ở đâu, rồi đo đúng chỗ đó. Don’t ask if the agent is good. Ask where it fails, then measure exactly there.

Câu hỏi gốc của sơ đồ: câu trả lời có đúng, có an toàn, và agent có đi đúng quy trình không? Ba vế đó là ba thứ cần đo: kết quả, ranh giới, quá trình. The diagram’s root question: is the response correct, safe, and following the right workflow? Those are three things to measure: outcome, boundaries, process.

Mỗi loại eval nhìn vào một phần khác của cùng một traceEach eval looks at a different part of the same trace

Chọn một loại để xem nó chấm những span nào.Pick a type to see which spans it grades.

inputuser llmplan retrievetop-k tool_callfind_order() tool_out{status} llmanswer tool_callrefund()? expected ⇄ actual recall@kgrounded? name · args · effect order · loops · steps · handoffs injectionpermissionPII · policy trace → test case → dataset

Nét đứt là nhánh agent tự quyết lúc chạy: cùng input, lần sau có thể đi đường khác.The dashed line is a branch the agent decides at runtime: same input, a different path next time.

Output eval chỉ so input với câu trả lời cuối. Mọi thứ ở giữa là hộp đen.Output eval only compares input with the final answer. Everything in between is a black box.

Retrieval eval tách hai câu hỏi: tài liệu đúng có được lấy về không, và câu trả lời có bám vào tài liệu đó không.Retrieval eval splits two questions: was the right document fetched, and is the answer grounded in it.

Tool use eval chấm từng lần gọi: tên tool, tham số, kết quả và tác dụng phụ, gồm cả nhánh agent có thể chọn.Tool use eval grades each call: name, arguments, result and side effects, including branches the agent might take.

Trajectory eval nhìn cả chuỗi: thứ tự, vòng lặp, số bước. Đây là nơi duy nhất thấy được “đúng nhờ may”.Trajectory eval reads the whole chain: order, loops, step count. The only place a lucky pass becomes visible.

Safety eval đứng ở ba cửa: input (injection), hành động (vượt quyền) và output (PII, chính sách).Safety eval guards three doors: input (injection), actions (permissions) and output (PII, policy).

Vòng lặp nằm ngoài trace: mỗi trace lỗi ở production quay về thành một test case.The loop sits outside the trace: every failing production trace comes back as a test case.

Chọn cái nàoWhich one to use

Đọc từ trên xuống, dừng ở dòng đầu tiên khớp với lỗi phổ biến nhất của bạn.Read top to bottom and stop at the first row matching your most common failure.

Trước hết: có thể bạn chưa cần loại nàoFirst: you may need none of them yet

Chưa cần pipeline eval khi đang prototype, khi hệ thống chỉ có một lần gọi LLM rủi ro thấp, hoặc khi chưa từng đọc output thật. Phương án rẻ nhất: bật trace, đọc 30–50 trace, gom lỗi thành 4–6 nhóm trong một bảng tính, viết assert cho lỗi kiểm được bằng code, chạy lại 20 case đó mỗi lần đổi prompt. Nâng cấp khi bạn bắt đầu ngại sửa prompt vì không biết nó sẽ làm hỏng chỗ nào.

Skip the eval pipeline while prototyping, when the system is a single low-stakes LLM call, or when you haven’t read real output yet. Cheapest option: turn on tracing, read 30–50 traces, group failures into 4–6 categories in a spreadsheet, write assertions for anything checkable in code, and rerun those 20 cases after every prompt change. Upgrade when you start hesitating to touch the prompt because you can’t tell what it will break.

  • Chưa đọc trace thật nào, chưa biết lỗi thuộc loại gìHaven’t read real traces; failure types unknownBaseline
  • Kết quả cuối sai, dù các bước trông ổnFinal result wrong although the steps look fineOutput
  • Tài liệu đúng không được lấy vềThe right document isn’t retrievedrecall@kRetrieval
  • Có tài liệu đúng nhưng câu trả lời vẫn bịaRight document retrieved, answer still made upfaithfulnessRetrieval
  • Gọi nhầm tool, sai tham số, tool lỗiWrong tool, wrong arguments, tool errorsTool use
  • Tool đúng nhưng sai thứ tự, lặp vòng, dừng sớm, bàn giao hỏngRight tools, wrong order, loops, early stops, broken handoffsTrajectory
  • Lộ PII, nội dung độc hại, jailbreak, làm vượt quyềnPII leaks, harmful content, jailbreaks, actions beyond permissionLuôn chạy, không phụ thuộc các dòng trênAlways on, independent of the rows aboveSafety
  • Mỗi lỗi tìm được ở bất kỳ dòng nàoEvery failure found in any rowthành một test casebecomes a test caseVòng lặpLoop

Năm loại evalFive eval types

Dải ô nhỏ trên mỗi thẻ là trace ở trên, thu gọn: ô tô màu là phần loại eval đó chấm.The small strip on each card is the trace above, compressed: coloured cells are what that eval grades.

OUT

Output eval

Kết quảOutcome

Chấm kết quả cuối người dùng nhận được, bỏ qua đường đi.Grades the final result the user receives, ignoring the path.

Dùng choUse for
Agent viết code, trích xuất dữ liệu, đặt lịch: có đáp án hoặc trạng thái cuối để so.Coding, extraction, scheduling: anything with a reference answer or end state.
ĐượcGain
Gần nhất với giá trị thật; code grader gần như miễn phí.Closest to real value; code graders are nearly free.
MấtLose
Biết sai nhưng không biết sai ở bước nào; đúng nhờ may vẫn tính là đúng.Tells you it failed, not where; lucky passes still count.

Đổi khả năng chẩn đoán nguyên nhân lấy con số gần nhất với điều người dùng quan tâm.Trades root-cause diagnosis for the number closest to what users care about.

Dấu hiệu:Sign: người dùng phàn nàn về kết quả, còn bạn không quan tâm agent mất mấy bước.users complain about results, and you don’t care how many steps it took.

RET

Retrieval eval

Quá trìnhProcess

Chấm riêng hai mắt xích RAG: lấy đúng tài liệu, và trả lời bám vào tài liệu đó.Grades RAG’s two links separately: fetching the right documents, and staying grounded in them.

Dùng choUse for
Chatbot tài liệu nội bộ, trợ lý pháp lý hoặc y khoa phải trích nguồn.Internal-docs bots, legal or medical assistants that must cite.
ĐượcGain
Khoanh vùng lỗi: retriever hay LLM. Recall@k rẻ và tất định.Isolates the fault: retriever or LLM. Recall@k is cheap and deterministic.
MấtLose
Cần nhãn tài liệu đúng; faithfulness cao vẫn có thể sai nếu tài liệu đã cũ.Needs labelled documents; high faithfulness can still be wrong if the source is stale.

Đổi công gắn nhãn tài liệu lấy khả năng chỉ ra lỗi nằm ở retriever hay ở LLM.Trades labelling effort for knowing whether the retriever or the LLM is at fault.

Dấu hiệu:Sign: câu trả lời sai về một sự thật mà tài liệu của bạn có ghi.the answer gets wrong a fact your documents state.

TOOL

Tool use eval

Quá trìnhProcess

Chấm từng lần gọi tool: đúng tool, đúng tham số, thành công, không tác dụng phụ.Grades each tool call: right tool, right arguments, success, no side effects.

Dùng choUse for
Agent CRM, hoàn tiền, sinh SQL; agent có nhiều tool na ná nhau.CRM, refund and SQL agents; agents with many overlapping tools.
ĐượcGain
Chấm bằng code được; chặn hành động sai trước khi nó xảy ra thật.Gradeable in code; stops wrong actions before they happen for real.
MấtLose
Cần sandbox có trạng thái; so khớp cứng phạt oan cách gọi khác nhưng đúng.Needs a stateful sandbox; strict matching punishes valid alternatives.

Đổi chi phí dựng sandbox lấy khả năng chặn hành động sai trước khi chạm hệ thống thật.Trades sandbox cost for stopping wrong actions before they touch the real system.

Dấu hiệu:Sign: agent biết phải làm gì nhưng gọi nhầm hàm hoặc truyền sai giá trị.the agent knows what to do but calls the wrong function or passes the wrong value.

TRAJ

Trajectory eval

Quá trìnhProcess

Chấm cả chuỗi bước: thứ tự, vòng lặp, bàn giao, số bước.Grades the whole sequence: order, loops, handoffs, step count.

Dùng choUse for
Quy trình bắt buộc thứ tự, hệ multi-agent, agent nghiên cứu nhiều bước.Mandatory-order workflows, multi-agent systems, multi-step research agents.
ĐượcGain
Bắt “đúng nhờ may”, vòng lặp đốt token, vi phạm quy trình.Catches lucky passes, token-burning loops, process violations.
MấtLose
So khớp chính xác làm agent cứng nhắc; trajectory kỳ vọng vỡ khi thêm tool.Exact matching makes agents rigid; expected paths break when tools change.

Đổi một phần tự do chọn đường của agent lấy quyền kiểm soát quy trình, chi phí và độ trễ.Trades some of the agent’s freedom of path for control over process, cost and latency.

Dấu hiệu:Sign: kết quả thường đúng, nhưng chi phí và độ trễ thất thường.results are usually right, but cost and latency are erratic.

SAFE

Safety eval

Kết quảOutcome

Kiểm tra ranh giới ở cả ba cửa: input, hành động và output.Checks boundaries at all three doors: input, actions and output.

Dùng choUse for
Agent đọc email hoặc web, ngành có quy định, chatbot công khai.Agents reading email or the web, regulated industries, public chatbots.
ĐượcGain
Bắt rủi ro hiếm nhưng đắt; check PII đủ rẻ để chạy trên toàn bộ traffic.Catches rare, expensive risks; PII checks are cheap enough for all traffic.
MấtLose
Bộ tấn công lỗi thời nhanh; tối ưu một chiều gây từ chối oan.Attack sets go stale fast; one-sided tuning causes false refusals.

Đổi một phần mức hữu ích lấy xác suất thấp hơn của những sự cố hiếm nhưng đắt.Trades some helpfulness for fewer rare but expensive incidents.

Dấu hiệu:Sign: chỉ một lỗi cũng đủ thành sự cố pháp lý hoặc truyền thông.one failure is enough for a legal or PR incident.

Vòng lặp evalThe eval loop

Ảnh gốc vẽ đây là đường thẳng. Thực tế bước 05 phải nối về bước 01, nếu không bộ eval sẽ cũ dần.The original image draws this as a straight line. In practice step 05 must feed back into step 01, or the suite goes stale.

  1. 01

    Dataset

    Case thật từ log, case biên, case khó. 20–50 case là đủ để bắt đầu.Real cases from logs, edge cases, hard cases. 20–50 is enough to start.

  2. 02

    Run evals

    Code, judge và người. Mỗi case chạy 3–5 lần vì agent không tất định.Code, judges and humans. Run each case 3–5 times; agents are non-deterministic.

  3. 03

    Compare

    Trước và sau khi đổi prompt hoặc model. Đọc từng case bị lật, đừng chỉ nhìn trung bình.Before and after a prompt or model change. Read flipped cases, not just the average.

  4. 04

    Track

    Lưu kết quả theo commit, kèm chi phí và độ trễ. Báo động khi giảm.Store results per commit, with cost and latency. Alert on drops.

  5. 05

    Monitor prod

    Lấy mẫu trace thật, grader online, feedback người dùng.Sample real traces, online graders, user feedback.

Mỗi lỗi ở bước 05 thành một case mới ở bước 01.Every failure at step 05 becomes a new case at step 01.

Đổi chi phí vận hành liên tục lấy khả năng thay đổi hệ thống nhanh mà không sợ phá vỡ.Trades continuous operating cost for changing the system quickly without fear of breaking it.

Bảng đánh đổiTrade-off table

Các trục ở đây là những thứ bạn thật sự phải cân khi chọn: cần nhãn gì, tốn bao nhiêu, tín hiệu có ổn định không, và bắt được gì mà loại khác bỏ sót.The axes are what you actually weigh: what labels you need, how much it costs, how stable the signal is, and what it catches that others miss.

LoạiGrader chínhCần nhãn chuẩnChi phí mỗi lần chạyĐộ ổn định tín hiệuBắt được thứ loại khác bỏ sótChạy ở đâu
OutputCode, rồi judgeĐáp án hoặc rubricThấp đến vừaCao với code, vừa với judgeLệch so với mong muốn người dùngCI và prod
RetrievalMetric IR, judgeTài liệu đúngThấpCao (recall), vừa (faithfulness)Lỗi index, chunking, embeddingCI, mỗi khi kho tài liệu đổi
Tool useCode, sandboxCall kỳ vọngVừa (dựng sandbox)CaoHành động sai trước khi xảy ra thậtCI
TrajectoryRule, judgeMột phần: bước bắt buộcCao (trace dài)VừaLặp vòng, vi phạm quy trình, lãng phíCI và prod
SafetyClassifier, red-team, judgeChính sách viết rõThấp online, cao khi red-teamVừaRủi ro hiếm nhưng đắtCI và toàn bộ traffic
TypeMain graderGround truth neededCost per runSignal stabilityCatches what others missRuns where
OutputCode, then judgeAnswer or rubricLow to mediumHigh with code, medium with judgeMismatch with what users wantedCI and prod
RetrievalIR metrics, judgeRelevant documentsLowHigh (recall), medium (faithfulness)Index, chunking, embedding faultsCI, whenever the corpus changes
Tool useCode, sandboxExpected callsMedium (sandbox setup)HighWrong actions before they happenCI
TrajectoryRules, judgePartly: required stepsHigh (long traces)MediumLoops, process violations, wasteCI and prod
SafetyClassifiers, red-team, judgeWritten policyLow online, high for red-teamingMediumRare but expensive risksCI and all traffic

Anti-patterns

Những sai lầm phổ biến nhất khi mới bắt đầu eval agent.The most common mistakes when starting to evaluate agents.

Sai lầmVì sao saiSửa thế nào
Lấy metric có sẵn trước khi đọc traceĐo thứ dễ đo, không phải thứ đang hỏngError analysis trước, metric sinh ra từ nhóm lỗi thật
Chấm bằng thang 1–5Ranh giới các mức mơ hồ, judge và người đều chấm lệchPass/fail cho từng tiêu chí, kèm lý do
Tin judge khi chưa đối chiếu với ngườiJudge thiên lệch vị trí, độ dài, ưu ái model cùng họGán nhãn 50–100 case bằng tay, đo mức khớp trước khi dùng
Chỉ chấm câu trả lời cuốiBỏ qua đúng nhờ may, vòng lặp tốn tiền, vi phạm quy trìnhThêm tool use và trajectory eval cho bước rủi ro
Ép trajectory khớp chính xácPhạt đường đi hợp lệ, làm agent cứng nhắcChỉ ràng buộc bước bắt buộc
Chạy mỗi case một lầnAgent không tất định, một lần pass có thể là mayChạy 3–5 lần, theo dõi pass^k
Dataset không bao giờ cập nhậtOverfit dần, điểm 100% không còn nói lên gìMỗi sự cố prod thêm một case mới
Coi safety eval là lớp bảo vệ chínhPrompt injection không chặn triệt để được bằng promptGiới hạn quyền ở tầng code, eval chỉ là lớp kiểm tra
MistakeWhy it’s wrongFix
Adopting stock metrics before reading tracesMeasures what’s easy, not what’s brokenError analysis first; metrics come from real failure categories
Grading on a 1–5 scaleFuzzy level boundaries; judges and humans driftPass/fail per criterion, with a reason
Trusting a judge never checked against humansPosition and length bias, favours its own model familyHand-label 50–100 cases and measure agreement first
Grading only the final answerMisses lucky passes, costly loops, process violationsAdd tool use and trajectory evals for risky steps
Requiring exact trajectory matchesPenalises valid paths, makes the agent rigidConstrain only mandatory steps
Running each case onceAgents are non-deterministic; one pass can be luckRun 3–5 times and track pass^k
Never updating the datasetSlow overfitting; 100% stops meaning anythingAdd a case for every prod incident
Treating safety evals as the main defencePrompt injection can’t be fully blocked with promptsRestrict permissions in code; evals are a check layer

Ba câu cần nhớThree things to remember

  • Đọc trace trước, chọn metric sau: loại eval do lỗi thật quyết định, không do danh sách có sẵn.Read traces first, pick metrics second: real failures decide the eval type, not a ready-made list.
  • Chấm kết quả để biết có sai, chấm quá trình để biết sai ở đâu. Agent cần cả hai, còn safety thì chạy bất kể.Grade the outcome to know that it failed, the process to know where. Agents need both; safety runs regardless.
  • Eval là vòng lặp, không phải cổng một lần: mỗi lỗi production phải quay về thành một test case.Evals are a loop, not a one-time gate: every production failure comes back as a test case.