Skip to content

Evals và Observability

Evals và observability là tầng feedback cho production. Nó trả lời câu hỏi đơn giản: làm sao biết AI system vẫn hành xử đúng sau khi prompts, tools, retrieval, models hoặc workflows thay đổi?

Unit test chứng minh code deterministic hoạt động. AI eval chứng minh hành vi xác suất của model, prompt, retrieval và tool path vẫn đạt chuẩn qua thời gian.

Layer này sở hữu điều gì

Mối quan tâmOutput
Tracingtimeline đầy đủ qua model calls, retrieval, tools, prompts
Quality evalspass/fail hoặc score trên representative cases
Regression detectionchange mới có làm behavior tệ hơn không
Prompt/version trackingprompt nào sinh result nào
Dataset managementgolden questions, expected evidence, edge cases
Cost và latencytoken use, model route, end-to-end duration
Debuggingvì sao answer hoặc action xảy ra
Release gateschange có được ship không

Traditional tests vs AI evals

Test typeHợp nhất choVí dụ
Unit testdeterministic codeparser trả expected JSON
Integration testAPI/tool wiringCRM tool tạo draft ticket
Contract testschema compatibilitytool args khớp OpenAPI schema
Retrieval evalcontext qualityexpected policy doc nằm trong top 5
Generation evalanswer qualityanswer grounded và complete
Agent trajectory evalpath qualityagent hỏi approval trước write action
Safety evalrefusal và policy behaviorprompt injection không kích hoạt unsafe tool

Golden dataset pattern

Golden dataset là tập case đại diện được curate để định nghĩa expected behavior. Nó nên có normal cases, edge cases, negative cases và high-risk cases.

Dataset fieldVí dụ
Inputuser question hoặc task
Expected evidencedocuments, code files, records hoặc facts nên được dùng
Expected behavioranswer, refusal, tool call, approval request
Risk tagsecurity, privacy, legal, operational, product
Evaluation methodexact match, rubric score, LLM judge, human review

Trace-first debugging

mermaid
flowchart LR
    A[User request] --> B[Agent/app run]
    B --> C[Trace]
    B --> D[Model output]
    B --> E[Tool calls]
    C --> F[Observability platform]
    D --> G[Eval scorer]
    E --> G
    G --> H[Regression report]
    H --> I[Prompt/spec/tool changes]

Khi AI system fail, đừng bắt đầu bằng việc sửa prompt. Hãy inspect trace trước:

  1. Instruction nào đang active?
  2. Context nào được retrieve?
  3. Model nào được dùng?
  4. Tool nào được gọi?
  5. Arguments nào được truyền?
  6. Guardrail hoặc approval gate nào được kích hoạt?
  7. Eval case nào nên bắt lỗi này lần sau?

Metrics quan trọng

MetricVì sao quan trọng
Answer correctnessproduct value
Grounding/citation ratetrust và auditability
Retrieval precision/recallRAG quality
Tool success/failure rateoperational reliability
Unsafe action attemptssecurity signal
Human approval ratesức khỏe autonomy boundary
Cost per successful taskbusiness scalability
Latency percentilesuser experience
Regression raterelease quality

Tooling map

Tool/categoryVai trò
LangSmithtracing và eval workflows cho LangChain/LangGraph
Langfuseopen-source LLM observability và prompt/eval tracking
Phoenixtracing, evals và ML/LLM observability
OpenTelemetryvendor-neutral telemetry standard
CI eval gatengăn regression được merge

Hướng dẫn adoption step-by-step

  1. Instrument traces trước khi tối ưu prompts.
  2. Tạo 30-50 golden cases cho workflow giá trị cao nhất.
  3. Thêm retrieval evals nếu app dùng RAG.
  4. Thêm tool trajectory evals nếu agent có thể thực hiện actions.
  5. Chạy evals local khi development và trong CI cho critical changes.
  6. Track prompt version, model route, retrieval configuration và tool version.
  7. Đặt failure thresholds theo risk tier.
  8. Review eval failures hằng tuần và chuyển incidents thành cases mới.

Failure modes

Failure modeDấu hiệuCách làm tốt hơn
Không tracesfailures được tranh luận bằng screenshotstrace mọi run
Chỉ có unit testscode pass nhưng AI behavior regressthêm behavioral evals
Evals quá genericscore đẹp nhưng user phàn nàndùng real tasks và edge cases
Không dataset ownershipevals xuống cấp theo thời gianassign owner và review cadence
Chỉ dùng LLM judgequality signal flakykết hợp deterministic checks, rubric và human review
Không CI gateregressions ship lặp lạiblock high-risk changes bằng eval threshold

References

Built as a static bilingual AI engineering stack guide.