Agent Evaluation and Regression Testing
توسعه عاملهای هوشمند (Agentic Ai) با Langchain و Langgraph
- Build datasets containing questions, expected evidence, expected tools, and expected outcomes.
- Evaluate final answer quality, retrieval, citation support, tool selection, and trajectory.
- Create regression checks for known failures after architecture changes.
چرا ارزیابی عامل؟
**سه پرسش مستقل**
درستی پاسخ، پشتیبانی شواهد و صحت مسیر ابزار را جداگانه بسنجید.
```mermaid
flowchart LR
Q["Question"] --> A["Agent run"]
A --> R["Final answer"]
A --> T["Tool trajectory"]
A --> E["Evidence and citations"]
R --> C["Separate checks"]
T --> C
E --> C
C --> D["Pass or diagnose"]
```
طراحی مجموعه ارزیابی
**قرارداد case**
\[\mathrm{case}=(\mathrm{question},\ \mathrm{expected\_evidence},\ \mathrm{expected\_tools},\ \mathrm{expected\_outcome})\]
**نمونه ساعت پشتیبانی**
سؤال: «ساعت پشتیبانی چیست؟»
شاهد لازم: `handbook.md#support-hours`
مسیر: `retrieve → answer`
نتیجه: «شنبه تا چهارشنبه، ۹ تا ۱۷» با citation همان قطعه.
```mermaid
flowchart TD
I["Question"] --> V["Expected evidence"]
I --> U["Expected tools"]
I --> O["Expected outcome"]
V --> C["Test case contract"]
U --> C
O --> C
C --> R["Repeatable run"]
```
سه بررسی جداگانه
**مقایسه دو citation**
پاسخ: «حداکثر اندازه ۱۰ MB است.»
شاهد مورد انتظار: `limits.md#file-size`
اگر citation به `pricing.md` وصل شود: `answer_supported = 1` و `citation_correct = 0`.
اگر citation به `limits.md#file-size` وصل شود: `answer_supported = 1` و `citation_correct = 1`.
با مسیر `retrieve → answer`، مقدار `right_tool = 1` است.
```mermaid
flowchart LR
X["Run trace"] --> F["Final answer support"]
X --> C["Citation correctness"]
X --> T["Tool selection and trajectory"]
F --> S["Independent result"]
C --> S
T --> S
```
اجرای کامل با Python
**اجرای یک case**
داده شامل سؤال، شواهد، ترتیب `retrieve → answer` و نتیجه مورد انتظار است.
خروجی فرضی:
\[\mathrm{answer\_supported}=1,\qquad \mathrm{citation\_correct}=0,\qquad \mathrm{right\_tool}=1\]
نتیجه: فقط citation نیاز به بررسی و تعمیر دارد.
```mermaid
flowchart TD
D["Dataset"] --> E["aevaluate"]
T["target"] --> E
E --> R["Agent runs"]
R --> V1["answer_supported"]
R --> V2["citation_correct"]
R --> V3["right_tool"]
V1 --> P["Per-case report"]
V2 --> P
V3 --> P
```
Regression پس از تغییر
**مقایسه baseline و اجرای جدید**
ترتیب مؤلفهها: support، citation، tool
\[\mathrm{old}=(1,1,1),\qquad \mathrm{new}=(1,0,1)\]
\[\Delta_{\mathrm{support}}=1-1=0\]
\[\Delta_{\mathrm{citation}}=0-1=-1\]
\[\Delta_{\mathrm{tool}}=1-1=0\]
پس فقط citation دچار regression شده است.
**پوشش آزمون محدود است**
قبولی dataset فعلی، ایمنی تغییرات آینده را تضمین نمیکند. failureهای تازه را به caseهای جدید تبدیل کنید.
Back to course