mas-lab-library-eval 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mas_lab_library_eval-0.2.0/.gitignore +86 -0
- mas_lab_library_eval-0.2.0/PKG-INFO +192 -0
- mas_lab_library_eval-0.2.0/README.md +173 -0
- mas_lab_library_eval-0.2.0/docs/cli/index.md +45 -0
- mas_lab_library_eval-0.2.0/examples/README.md +18 -0
- mas_lab_library_eval-0.2.0/examples/mce/README.md +11 -0
- mas_lab_library_eval-0.2.0/examples/mce/judge-override/README.md +65 -0
- mas_lab_library_eval-0.2.0/examples/mce/judge-override/experiment.yaml +28 -0
- mas_lab_library_eval-0.2.0/examples/mce/judge-override/mas.yaml +15 -0
- mas_lab_library_eval-0.2.0/library.yaml +29 -0
- mas_lab_library_eval-0.2.0/pyproject.toml +43 -0
- mas_lab_library_eval-0.2.0/src/mas/library/eval/__init__.py +38 -0
- mas_lab_library_eval-0.2.0/src/mas/library/eval/cli/__init__.py +204 -0
- mas_lab_library_eval-0.2.0/src/mas/library/eval/evaluator.py +339 -0
- mas_lab_library_eval-0.2.0/src/mas/library/eval/mce/__init__.py +47 -0
- mas_lab_library_eval-0.2.0/src/mas/library/eval/mce/catalog.py +215 -0
- mas_lab_library_eval-0.2.0/src/mas/library/eval/mce/judge_model.py +188 -0
- mas_lab_library_eval-0.2.0/src/mas/library/eval/mce/registry_api.py +115 -0
- mas_lab_library_eval-0.2.0/src/mas/library/eval/mce/runner.py +661 -0
- mas_lab_library_eval-0.2.0/src/mas/library/eval/mce/trace_provider.py +360 -0
- mas_lab_library_eval-0.2.0/src/mas/library/eval/metrics/__init__.py +122 -0
- mas_lab_library_eval-0.2.0/src/mas/library/eval/metrics/llm_json.py +99 -0
- mas_lab_library_eval-0.2.0/src/mas/library/eval/metrics/plugins.py +87 -0
- mas_lab_library_eval-0.2.0/src/mas/library/eval/metrics/prompt.py +199 -0
- mas_lab_library_eval-0.2.0/src/mas/library/eval/metrics/scope.py +150 -0
- mas_lab_library_eval-0.2.0/src/mas/library/eval/metrics/stock.py +81 -0
- mas_lab_library_eval-0.2.0/src/mas/library/eval/metrics/toy.py +36 -0
- mas_lab_library_eval-0.2.0/src/mas/library/eval/providers/__init__.py +3 -0
- mas_lab_library_eval-0.2.0/src/mas/library/eval/providers/adversarial.py +646 -0
- mas_lab_library_eval-0.2.0/src/mas/library/eval/providers/mce.py +34 -0
- mas_lab_library_eval-0.2.0/src/mas/library/eval/providers/trip_planner_gt.py +394 -0
- mas_lab_library_eval-0.2.0/src/mas/library/eval/steps/__init__.py +158 -0
- mas_lab_library_eval-0.2.0/tests/test_eval_infra_routing.py +327 -0
- mas_lab_library_eval-0.2.0/tests/test_eval_mce_judge_logging.py +213 -0
- mas_lab_library_eval-0.2.0/tests/test_eval_mce_routing.py +145 -0
- mas_lab_library_eval-0.2.0/tests/test_eval_metric_registry.py +174 -0
- mas_lab_library_eval-0.2.0/tests/test_integration.py +59 -0
- mas_lab_library_eval-0.2.0/tests/test_llm_json.py +75 -0
- mas_lab_library_eval-0.2.0/tests/test_mce_judge_example.py +63 -0
- mas_lab_library_eval-0.2.0/tests/test_mce_judge_model.py +249 -0
- mas_lab_library_eval-0.2.0/tests/test_metric_names.py +68 -0
- mas_lab_library_eval-0.2.0/tests/test_metric_scope.py +76 -0
- mas_lab_library_eval-0.2.0/tests/test_metrics_files.py +59 -0
- mas_lab_library_eval-0.2.0/tests/test_prompt_metrics.py +249 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
*.pyc
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.egg-info/
|
|
4
|
+
.DS_Store
|
|
5
|
+
dist/
|
|
6
|
+
build/
|
|
7
|
+
.venv/
|
|
8
|
+
.demo-ui/
|
|
9
|
+
.demo-ui-mock/
|
|
10
|
+
.env
|
|
11
|
+
.env.local
|
|
12
|
+
.env.*.local
|
|
13
|
+
config.yaml
|
|
14
|
+
!lab/src/mas/lab/templates/**/config.yaml
|
|
15
|
+
!docs/tutorials/**/config.yaml
|
|
16
|
+
!labs/**/config.yaml
|
|
17
|
+
!library-samples/sample-workspace/config.yaml
|
|
18
|
+
.mypy_cache/
|
|
19
|
+
.ruff_cache/
|
|
20
|
+
.pytest_cache/
|
|
21
|
+
.test-venv/
|
|
22
|
+
node_modules/
|
|
23
|
+
*.log
|
|
24
|
+
docs/tutorials/**/logs/
|
|
25
|
+
.hypothesis/
|
|
26
|
+
compliance-report.json
|
|
27
|
+
COMPLIANCE_REPORT.md
|
|
28
|
+
compliance/results/
|
|
29
|
+
|
|
30
|
+
# MkDocs build output
|
|
31
|
+
site/
|
|
32
|
+
|
|
33
|
+
.vscode/
|
|
34
|
+
.cursor/
|
|
35
|
+
.claude/
|
|
36
|
+
|
|
37
|
+
# Test / coverage artifacts
|
|
38
|
+
.coverage
|
|
39
|
+
coverage.xml
|
|
40
|
+
coverage.json
|
|
41
|
+
**/coverage.json
|
|
42
|
+
|
|
43
|
+
# LaTeX build artifacts
|
|
44
|
+
*.fdb_latexmk
|
|
45
|
+
*.fls
|
|
46
|
+
*.aux
|
|
47
|
+
*.out
|
|
48
|
+
*.toc
|
|
49
|
+
*.synctex.gz
|
|
50
|
+
|
|
51
|
+
# Run output / artifacts
|
|
52
|
+
**/output/*.jsonl
|
|
53
|
+
**/output/benchmark
|
|
54
|
+
**/output/meta.json
|
|
55
|
+
**/output/current_run_id.txt
|
|
56
|
+
**/output/*/
|
|
57
|
+
.tutorial-cache/
|
|
58
|
+
tests/.tutorial-engine-cache/
|
|
59
|
+
.demo-cache/
|
|
60
|
+
# Local mas-ctl chat traces next to an agent (fixtures live under fixtures/ or T01 traces/)
|
|
61
|
+
docs/tutorials/**/agents/**/traces/
|
|
62
|
+
|
|
63
|
+
# Backup files
|
|
64
|
+
*.bak
|
|
65
|
+
*.bak2
|
|
66
|
+
|
|
67
|
+
# Legacy dead code (removed from repo)
|
|
68
|
+
lab/src/mas/lab/_cli_legacy.py
|
|
69
|
+
.deepeval/
|
|
70
|
+
~/.mas/
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
# Docker local secrets + data (never commit)
|
|
74
|
+
docker/.env
|
|
75
|
+
docker/data/*
|
|
76
|
+
!docker/data/.gitkeep
|
|
77
|
+
|
|
78
|
+
# Local protocol compliance checkouts and reports
|
|
79
|
+
compliance/vendor/
|
|
80
|
+
|
|
81
|
+
# Local harness playbooks (not published)
|
|
82
|
+
AGENTS.md
|
|
83
|
+
# .agents/
|
|
84
|
+
COVERAGE_REPORT.md
|
|
85
|
+
MANIFEST_SCHEMA_MAPPING.md
|
|
86
|
+
.lycheecache
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: mas-lab-library-eval
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Evaluation and quality metrics library for MAS Lab — MCE integration.
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Requires-Python: >=3.11
|
|
7
|
+
Requires-Dist: click>=8.0
|
|
8
|
+
Requires-Dist: deepeval>=4.0.0
|
|
9
|
+
Requires-Dist: mas-lab-component-bench
|
|
10
|
+
Requires-Dist: mas-lab-component-core
|
|
11
|
+
Requires-Dist: mas-lab-runtime
|
|
12
|
+
Requires-Dist: mce-metrics-plugin>=0.1.0
|
|
13
|
+
Requires-Dist: metrics-computation-engine>=0.1.0
|
|
14
|
+
Requires-Dist: pandas>=2.0.0
|
|
15
|
+
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
|
|
17
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
<!--
|
|
21
|
+
Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
|
|
22
|
+
SPDX-License-Identifier: Apache-2.0
|
|
23
|
+
-->
|
|
24
|
+
# library-eval
|
|
25
|
+
|
|
26
|
+
Scores MAS runs with quality metrics and LLM-as-judge prompts. It wraps the Metrics Computation Engine (MCE), an open-source set of LLM-as-judge metrics from the AGNTCY `telemetry-hub` project, for MAS traces.
|
|
27
|
+
|
|
28
|
+
Use it when you want a number for "did the system reach the goal" or "was the answer grounded" for one trace or a whole experiment.
|
|
29
|
+
|
|
30
|
+
## Quick start
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
uv pip install -e library-eval # from the repository root; needs Python 3.11+
|
|
34
|
+
mas-lab eval --list-metrics
|
|
35
|
+
mas-lab eval path/to/events.jsonl --metric goal_success_rate --metric groundedness
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Batch scoring over a benchmark output tree:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
mas-lab eval path/to/experiment/ --metric goal_success_rate --recursive
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`mas-lab eval SOURCE` flags:
|
|
45
|
+
|
|
46
|
+
| Flag | Meaning |
|
|
47
|
+
|------|---------|
|
|
48
|
+
| `--metric` | Metric to compute; repeatable. |
|
|
49
|
+
| `--model` | Judge model name (default `azure/gpt-4o`). |
|
|
50
|
+
| `--api-base` | LLM proxy base URL (default `https://api.openai.com/v1`). |
|
|
51
|
+
| `--api-key-env` | Environment variable holding the API key (default `OPENAI_API_KEY`). |
|
|
52
|
+
| `--json` | Print results as JSON. |
|
|
53
|
+
| `--list-metrics` | List available metrics and exit; `SOURCE` is then optional. |
|
|
54
|
+
| `--recursive` | Score every trace under the `SOURCE` directory. |
|
|
55
|
+
|
|
56
|
+
The package depends on `lab/components/core`, `lab/components/bench` and `mas-runtime` from this repository, plus the public MCE packages:
|
|
57
|
+
|
|
58
|
+
- `metrics-computation-engine`: MCE core.
|
|
59
|
+
- `mce-metrics-plugin`: quality metrics (GoalSuccessRate, Groundedness, ResponseCompleteness, ...).
|
|
60
|
+
- `deepeval`: continuous-score implementations of `answer_relevancy` and `goal_success_rate`.
|
|
61
|
+
|
|
62
|
+
## What the library provides
|
|
63
|
+
|
|
64
|
+
1. Library code (`mas.library.eval.*`): MCE integration, session entity construction, metric computation, and the `eval_metric` plugin type.
|
|
65
|
+
2. A CLI component (`mas.library.eval.cli`) that registers `mas-lab eval` through the `mas.lab.cli.components` entry point:
|
|
66
|
+
|
|
67
|
+
```toml
|
|
68
|
+
[project.entry-points."mas.lab.cli.components"]
|
|
69
|
+
eval = "mas.library.eval.cli:EvalCliComponent"
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The `eval_mce` pipeline step, which scores a run into `metrics.json`, ships in `library-lab` (`mas.library.lab.steps.eval.mce`) and calls into this library. `mas.library.eval.steps` holds an older CamelCase-metric step class that is not registered.
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
src/mas/library/eval/
|
|
76
|
+
+-- evaluator.py EvalProvider + get_provider("mce")
|
|
77
|
+
+-- providers/ mce.py: built-in MCE provider (stock + registered metrics);
|
|
78
|
+
| trip_planner_gt.py, adversarial.py: sample ground-truth / adversarial providers
|
|
79
|
+
+-- mce/
|
|
80
|
+
| +-- catalog.py one catalog: METRIC_MAP + METRIC_REGISTRY
|
|
81
|
+
| +-- runner.py native-trace MCE/deepeval compute
|
|
82
|
+
| +-- registry_api.py SessionEntity CamelCase API
|
|
83
|
+
+-- metrics/ EvalMetric, plugins, prompt_metrics, stock wrappers, toy example
|
|
84
|
+
+-- steps/ older CamelCase-metric step class (not registered)
|
|
85
|
+
+-- cli/ mas-lab eval
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Score runs in a benchmark
|
|
89
|
+
|
|
90
|
+
Attach the `eval_mce` step to a run. Metric ids are snake_case and the judge model comes from the experiment (see [Tutorial 10](../docs/tutorials/10-evaluation-metrics/README.md)):
|
|
91
|
+
|
|
92
|
+
```yaml
|
|
93
|
+
# pipeline attached with `mas-lab benchmark run ... --pipeline run:post:eval.yaml`
|
|
94
|
+
apiVersion: mas/v1
|
|
95
|
+
kind: Pipeline
|
|
96
|
+
spec:
|
|
97
|
+
steps:
|
|
98
|
+
- name: eval
|
|
99
|
+
type: eval_mce
|
|
100
|
+
per_run: true
|
|
101
|
+
in: trace
|
|
102
|
+
out: metrics
|
|
103
|
+
config:
|
|
104
|
+
metrics: [goal_success_rate, groundedness, response_completeness]
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Metric names
|
|
108
|
+
|
|
109
|
+
The CLI, the `eval_mce` step `metrics:` and the `metrics.json` keys use snake_case ids. The class names used by the `SessionEntity` API (`compute_session_metrics`) are CamelCase.
|
|
110
|
+
|
|
111
|
+
| Id (CLI and YAML) | Class name |
|
|
112
|
+
|-------------------|------------|
|
|
113
|
+
| `goal_success_rate` | `GoalSuccessRate` |
|
|
114
|
+
| `answer_relevancy` | `AnswerRelevancy` |
|
|
115
|
+
|
|
116
|
+
`mas-lab eval --list-metrics` lists the ids. The 11 stock session metrics are `answer_relevancy`, `component_conflict_rate`, `consistency`, `context_preservation`, `goal_success_rate`, `groundedness`, `information_retention`, `intent_recognition_accuracy`, `response_completeness`, `workflow_cohesion_index` and `workflow_efficiency`. The rule-based core metrics (`ToolError`, `ToolErrorRate`, `ToolUtilizationAccuracy`, `CyclesCount`, `AgentToAgentInteractions`, `AgentToToolInteractions`) are available through the CamelCase API only.
|
|
117
|
+
|
|
118
|
+
## Register your own metric (`eval_metric` plugin)
|
|
119
|
+
|
|
120
|
+
A library registers session metrics on the MCE eval provider through the `eval_metric` plugin type (`EvalProvider.register_metric`). `eval_mce` then runs any mix of stock MCE ids and registered ids into one `metrics.json`. Each metric declares the input it needs (`unit` / `evidence`). Stock MCE ids score MAS input and output, not the raw trajectory.
|
|
121
|
+
|
|
122
|
+
```yaml
|
|
123
|
+
# library.yaml
|
|
124
|
+
types:
|
|
125
|
+
- eval_metric
|
|
126
|
+
plugins:
|
|
127
|
+
- type: eval_metric
|
|
128
|
+
name: toy_echo
|
|
129
|
+
module: mas.library.eval.metrics.toy
|
|
130
|
+
class: ToyEchoMetric
|
|
131
|
+
attributes:
|
|
132
|
+
provider: mce # default
|
|
133
|
+
# A family that yields many ids from one factory:
|
|
134
|
+
- type: eval_metric
|
|
135
|
+
name: my_family
|
|
136
|
+
factory: mas.library.example.metrics:build_metrics
|
|
137
|
+
attributes:
|
|
138
|
+
provider: mce
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Rules:
|
|
142
|
+
|
|
143
|
+
- Duplicate metric ids raise at registration.
|
|
144
|
+
- Stock MCE session ids are `EvalMetric`s on `get_provider("mce")` (one batch per run).
|
|
145
|
+
- Plugins and inline `prompt_metrics` run through the same `compute_metrics` engine.
|
|
146
|
+
- Unknown ids error with the list of available ids.
|
|
147
|
+
- Metrics that share `batch_key` are computed once per run via `compute_batch`.
|
|
148
|
+
- A failing metric writes `{value: null, error: "..."}` for that id only.
|
|
149
|
+
- Optional `details` on each score is additive in `metrics.json` schema v1.
|
|
150
|
+
|
|
151
|
+
List registered ids in the `metrics:` list of an `eval_mce` step, or split families across steps with distinct `metrics_filename` values (`metrics.json`, `metrics_judge2.json`). For a one-off LLM-as-judge question, add `prompt_metrics: [{id, prompt, unit, evidence}]` to the same step without a plugin; ids must not collide with a stock or registered metric. `collect_metrics` and `metrics_to_dataframe` accept a filename, a glob or a list, and copy `details` into a JSON column.
|
|
152
|
+
|
|
153
|
+
## Programmatic use
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
import os
|
|
157
|
+
|
|
158
|
+
from mas.library.eval.mce import build_session_from_trace, compute_session_metrics
|
|
159
|
+
|
|
160
|
+
session_entity = build_session_from_trace("path/to/events.jsonl")
|
|
161
|
+
|
|
162
|
+
results = await compute_session_metrics( # async
|
|
163
|
+
session=session_entity,
|
|
164
|
+
metrics=["GoalSuccessRate", "Groundedness"],
|
|
165
|
+
llm_config={
|
|
166
|
+
"LLM_MODEL_NAME": "azure/gpt-4o",
|
|
167
|
+
"LLM_BASE_MODEL_URL": "https://api.openai.com/v1",
|
|
168
|
+
"LLM_API_KEY": os.environ["OPENAI_API_KEY"],
|
|
169
|
+
},
|
|
170
|
+
)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
`llm_config` is a dict as above, or an `LLMJudgeConfig` with the same three fields:
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
from metrics_computation_engine.models.requests import LLMJudgeConfig
|
|
177
|
+
|
|
178
|
+
llm_config = LLMJudgeConfig(
|
|
179
|
+
LLM_MODEL_NAME="azure/gpt-4o",
|
|
180
|
+
LLM_BASE_MODEL_URL="https://api.openai.com/v1",
|
|
181
|
+
LLM_API_KEY=os.environ["OPENAI_API_KEY"],
|
|
182
|
+
)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## See also
|
|
186
|
+
|
|
187
|
+
- [Tutorial 10, Evaluation metrics](../docs/tutorials/10-evaluation-metrics/README.md): how stock MCE, prompts, plugins, judge infra and trajectory wrappers fit together.
|
|
188
|
+
- [Tutorial 3, Run an experiment](../docs/tutorials/03-experiments-and-analysis/README.md): first MCE scoring.
|
|
189
|
+
- Feature example (not a sample app): [examples/mce/judge-override/](examples/mce/judge-override/)
|
|
190
|
+
- [summarization.md, MCE judge](../docs/manifests/summarization.md#mce-judge-model)
|
|
191
|
+
- [MCE documentation](https://github.com/agntcy/telemetry-hub/tree/main/metrics_computation_engine)
|
|
192
|
+
- [mce_metrics_plugin](https://github.com/agntcy/telemetry-hub/tree/main/metrics_computation_engine/plugins/mce_metrics_plugin)
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
|
|
3
|
+
SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
-->
|
|
5
|
+
# library-eval
|
|
6
|
+
|
|
7
|
+
Scores MAS runs with quality metrics and LLM-as-judge prompts. It wraps the Metrics Computation Engine (MCE), an open-source set of LLM-as-judge metrics from the AGNTCY `telemetry-hub` project, for MAS traces.
|
|
8
|
+
|
|
9
|
+
Use it when you want a number for "did the system reach the goal" or "was the answer grounded" for one trace or a whole experiment.
|
|
10
|
+
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
uv pip install -e library-eval # from the repository root; needs Python 3.11+
|
|
15
|
+
mas-lab eval --list-metrics
|
|
16
|
+
mas-lab eval path/to/events.jsonl --metric goal_success_rate --metric groundedness
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Batch scoring over a benchmark output tree:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
mas-lab eval path/to/experiment/ --metric goal_success_rate --recursive
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`mas-lab eval SOURCE` flags:
|
|
26
|
+
|
|
27
|
+
| Flag | Meaning |
|
|
28
|
+
|------|---------|
|
|
29
|
+
| `--metric` | Metric to compute; repeatable. |
|
|
30
|
+
| `--model` | Judge model name (default `azure/gpt-4o`). |
|
|
31
|
+
| `--api-base` | LLM proxy base URL (default `https://api.openai.com/v1`). |
|
|
32
|
+
| `--api-key-env` | Environment variable holding the API key (default `OPENAI_API_KEY`). |
|
|
33
|
+
| `--json` | Print results as JSON. |
|
|
34
|
+
| `--list-metrics` | List available metrics and exit; `SOURCE` is then optional. |
|
|
35
|
+
| `--recursive` | Score every trace under the `SOURCE` directory. |
|
|
36
|
+
|
|
37
|
+
The package depends on `lab/components/core`, `lab/components/bench` and `mas-runtime` from this repository, plus the public MCE packages:
|
|
38
|
+
|
|
39
|
+
- `metrics-computation-engine`: MCE core.
|
|
40
|
+
- `mce-metrics-plugin`: quality metrics (GoalSuccessRate, Groundedness, ResponseCompleteness, ...).
|
|
41
|
+
- `deepeval`: continuous-score implementations of `answer_relevancy` and `goal_success_rate`.
|
|
42
|
+
|
|
43
|
+
## What the library provides
|
|
44
|
+
|
|
45
|
+
1. Library code (`mas.library.eval.*`): MCE integration, session entity construction, metric computation, and the `eval_metric` plugin type.
|
|
46
|
+
2. A CLI component (`mas.library.eval.cli`) that registers `mas-lab eval` through the `mas.lab.cli.components` entry point:
|
|
47
|
+
|
|
48
|
+
```toml
|
|
49
|
+
[project.entry-points."mas.lab.cli.components"]
|
|
50
|
+
eval = "mas.library.eval.cli:EvalCliComponent"
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The `eval_mce` pipeline step, which scores a run into `metrics.json`, ships in `library-lab` (`mas.library.lab.steps.eval.mce`) and calls into this library. `mas.library.eval.steps` holds an older CamelCase-metric step class that is not registered.
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
src/mas/library/eval/
|
|
57
|
+
+-- evaluator.py EvalProvider + get_provider("mce")
|
|
58
|
+
+-- providers/ mce.py: built-in MCE provider (stock + registered metrics);
|
|
59
|
+
| trip_planner_gt.py, adversarial.py: sample ground-truth / adversarial providers
|
|
60
|
+
+-- mce/
|
|
61
|
+
| +-- catalog.py one catalog: METRIC_MAP + METRIC_REGISTRY
|
|
62
|
+
| +-- runner.py native-trace MCE/deepeval compute
|
|
63
|
+
| +-- registry_api.py SessionEntity CamelCase API
|
|
64
|
+
+-- metrics/ EvalMetric, plugins, prompt_metrics, stock wrappers, toy example
|
|
65
|
+
+-- steps/ older CamelCase-metric step class (not registered)
|
|
66
|
+
+-- cli/ mas-lab eval
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Score runs in a benchmark
|
|
70
|
+
|
|
71
|
+
Attach the `eval_mce` step to a run. Metric ids are snake_case and the judge model comes from the experiment (see [Tutorial 10](../docs/tutorials/10-evaluation-metrics/README.md)):
|
|
72
|
+
|
|
73
|
+
```yaml
|
|
74
|
+
# pipeline attached with `mas-lab benchmark run ... --pipeline run:post:eval.yaml`
|
|
75
|
+
apiVersion: mas/v1
|
|
76
|
+
kind: Pipeline
|
|
77
|
+
spec:
|
|
78
|
+
steps:
|
|
79
|
+
- name: eval
|
|
80
|
+
type: eval_mce
|
|
81
|
+
per_run: true
|
|
82
|
+
in: trace
|
|
83
|
+
out: metrics
|
|
84
|
+
config:
|
|
85
|
+
metrics: [goal_success_rate, groundedness, response_completeness]
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Metric names
|
|
89
|
+
|
|
90
|
+
The CLI, the `eval_mce` step `metrics:` and the `metrics.json` keys use snake_case ids. The class names used by the `SessionEntity` API (`compute_session_metrics`) are CamelCase.
|
|
91
|
+
|
|
92
|
+
| Id (CLI and YAML) | Class name |
|
|
93
|
+
|-------------------|------------|
|
|
94
|
+
| `goal_success_rate` | `GoalSuccessRate` |
|
|
95
|
+
| `answer_relevancy` | `AnswerRelevancy` |
|
|
96
|
+
|
|
97
|
+
`mas-lab eval --list-metrics` lists the ids. The 11 stock session metrics are `answer_relevancy`, `component_conflict_rate`, `consistency`, `context_preservation`, `goal_success_rate`, `groundedness`, `information_retention`, `intent_recognition_accuracy`, `response_completeness`, `workflow_cohesion_index` and `workflow_efficiency`. The rule-based core metrics (`ToolError`, `ToolErrorRate`, `ToolUtilizationAccuracy`, `CyclesCount`, `AgentToAgentInteractions`, `AgentToToolInteractions`) are available through the CamelCase API only.
|
|
98
|
+
|
|
99
|
+
## Register your own metric (`eval_metric` plugin)
|
|
100
|
+
|
|
101
|
+
A library registers session metrics on the MCE eval provider through the `eval_metric` plugin type (`EvalProvider.register_metric`). `eval_mce` then runs any mix of stock MCE ids and registered ids into one `metrics.json`. Each metric declares the input it needs (`unit` / `evidence`). Stock MCE ids score MAS input and output, not the raw trajectory.
|
|
102
|
+
|
|
103
|
+
```yaml
|
|
104
|
+
# library.yaml
|
|
105
|
+
types:
|
|
106
|
+
- eval_metric
|
|
107
|
+
plugins:
|
|
108
|
+
- type: eval_metric
|
|
109
|
+
name: toy_echo
|
|
110
|
+
module: mas.library.eval.metrics.toy
|
|
111
|
+
class: ToyEchoMetric
|
|
112
|
+
attributes:
|
|
113
|
+
provider: mce # default
|
|
114
|
+
# A family that yields many ids from one factory:
|
|
115
|
+
- type: eval_metric
|
|
116
|
+
name: my_family
|
|
117
|
+
factory: mas.library.example.metrics:build_metrics
|
|
118
|
+
attributes:
|
|
119
|
+
provider: mce
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Rules:
|
|
123
|
+
|
|
124
|
+
- Duplicate metric ids raise at registration.
|
|
125
|
+
- Stock MCE session ids are `EvalMetric`s on `get_provider("mce")` (one batch per run).
|
|
126
|
+
- Plugins and inline `prompt_metrics` run through the same `compute_metrics` engine.
|
|
127
|
+
- Unknown ids error with the list of available ids.
|
|
128
|
+
- Metrics that share `batch_key` are computed once per run via `compute_batch`.
|
|
129
|
+
- A failing metric writes `{value: null, error: "..."}` for that id only.
|
|
130
|
+
- Optional `details` on each score is additive in `metrics.json` schema v1.
|
|
131
|
+
|
|
132
|
+
List registered ids in the `metrics:` list of an `eval_mce` step, or split families across steps with distinct `metrics_filename` values (`metrics.json`, `metrics_judge2.json`). For a one-off LLM-as-judge question, add `prompt_metrics: [{id, prompt, unit, evidence}]` to the same step without a plugin; ids must not collide with a stock or registered metric. `collect_metrics` and `metrics_to_dataframe` accept a filename, a glob or a list, and copy `details` into a JSON column.
|
|
133
|
+
|
|
134
|
+
## Programmatic use
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
import os
|
|
138
|
+
|
|
139
|
+
from mas.library.eval.mce import build_session_from_trace, compute_session_metrics
|
|
140
|
+
|
|
141
|
+
session_entity = build_session_from_trace("path/to/events.jsonl")
|
|
142
|
+
|
|
143
|
+
results = await compute_session_metrics( # async
|
|
144
|
+
session=session_entity,
|
|
145
|
+
metrics=["GoalSuccessRate", "Groundedness"],
|
|
146
|
+
llm_config={
|
|
147
|
+
"LLM_MODEL_NAME": "azure/gpt-4o",
|
|
148
|
+
"LLM_BASE_MODEL_URL": "https://api.openai.com/v1",
|
|
149
|
+
"LLM_API_KEY": os.environ["OPENAI_API_KEY"],
|
|
150
|
+
},
|
|
151
|
+
)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
`llm_config` is a dict as above, or an `LLMJudgeConfig` with the same three fields:
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
from metrics_computation_engine.models.requests import LLMJudgeConfig
|
|
158
|
+
|
|
159
|
+
llm_config = LLMJudgeConfig(
|
|
160
|
+
LLM_MODEL_NAME="azure/gpt-4o",
|
|
161
|
+
LLM_BASE_MODEL_URL="https://api.openai.com/v1",
|
|
162
|
+
LLM_API_KEY=os.environ["OPENAI_API_KEY"],
|
|
163
|
+
)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## See also
|
|
167
|
+
|
|
168
|
+
- [Tutorial 10, Evaluation metrics](../docs/tutorials/10-evaluation-metrics/README.md): how stock MCE, prompts, plugins, judge infra and trajectory wrappers fit together.
|
|
169
|
+
- [Tutorial 3, Run an experiment](../docs/tutorials/03-experiments-and-analysis/README.md): first MCE scoring.
|
|
170
|
+
- Feature example (not a sample app): [examples/mce/judge-override/](examples/mce/judge-override/)
|
|
171
|
+
- [summarization.md, MCE judge](../docs/manifests/summarization.md#mce-judge-model)
|
|
172
|
+
- [MCE documentation](https://github.com/agntcy/telemetry-hub/tree/main/metrics_computation_engine)
|
|
173
|
+
- [mce_metrics_plugin](https://github.com/agntcy/telemetry-hub/tree/main/metrics_computation_engine/plugins/mce_metrics_plugin)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
|
|
3
|
+
SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
-->
|
|
5
|
+
# mas-lab-eval(1)
|
|
6
|
+
|
|
7
|
+
## NAME
|
|
8
|
+
|
|
9
|
+
`mas-lab eval` — Score traces with MCE LLM-as-judge metrics
|
|
10
|
+
|
|
11
|
+
## SYNOPSIS
|
|
12
|
+
|
|
13
|
+
```text
|
|
14
|
+
mas-lab eval [OPTIONS] [SOURCE]
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## DESCRIPTION
|
|
18
|
+
|
|
19
|
+
Library CLI component (entry point `mas.lab.cli.components`). Calls the same
|
|
20
|
+
MCE runner as the `eval_mce` pipeline step (`mas.library.eval.mce.runner`).
|
|
21
|
+
|
|
22
|
+
Metric ids are snake_case (`goal_success_rate`). `--list-metrics` prints the
|
|
23
|
+
available ids. When `--model` is omitted, the workspace infra default is used,
|
|
24
|
+
else `gpt-4o`.
|
|
25
|
+
|
|
26
|
+
## OPTIONS
|
|
27
|
+
|
|
28
|
+
| Flag | Meaning |
|
|
29
|
+
|------|------|
|
|
30
|
+
| `SOURCE` | Positional argument. |
|
|
31
|
+
| `--fixture` | Path to a fixture YAML that provides ground truth. |
|
|
32
|
+
| `--metric` | MCE metric(s) to compute (repeatable). Snake_case ids only (goal_success_rate). Defaults to ['goal_success_rate'] when omitted. Use --list-metrics to show the available metrics. |
|
|
33
|
+
| `--response-agent` | agent_id whose last execution_end is the final response. Auto-detected when omitted. |
|
|
34
|
+
| `--model` | Judge model. Default: workspace infra default, else gpt-4o. |
|
|
35
|
+
| `--list-metrics` | List the available metrics and exit. |
|
|
36
|
+
| `--json` | Output results as JSON instead of a human-readable table. |
|
|
37
|
+
| `--overlay` | Label for display (e.g. inject-C7-backend). |
|
|
38
|
+
| `--engine` | Metric computation engine: mce-v1. |
|
|
39
|
+
| `--api-key-env` | Name of the environment variable holding the API key (default: OPENAI_API_KEY). |
|
|
40
|
+
| `--recursive` | Score every events.jsonl under SOURCE when SOURCE is a directory. |
|
|
41
|
+
|
|
42
|
+
## SEE ALSO
|
|
43
|
+
|
|
44
|
+
- `mas-lab --help`
|
|
45
|
+
- [library-eval README](../../README.md)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
|
|
3
|
+
SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
-->
|
|
5
|
+
# Examples (library-eval)
|
|
6
|
+
|
|
7
|
+
Small feature scenarios for MCE evaluation — closer to functional tests than
|
|
8
|
+
to sample apps. Layout: `examples/<category>/<name>/`.
|
|
9
|
+
|
|
10
|
+
Tests load these as fixtures. `mas-ctl validate` works from the repo root.
|
|
11
|
+
|
|
12
|
+
**Not here:** use-case apps such as the trip planner. Those live in `library-samples/apps/`.
|
|
13
|
+
|
|
14
|
+
## Index
|
|
15
|
+
|
|
16
|
+
| Category | Example | Kind | What it shows |
|
|
17
|
+
|----------|---------|------|----------------|
|
|
18
|
+
| [mce](mce/) | [judge-override](mce/judge-override/) | Experiment | `experiment.models` judge vs main + per-step `config.model` |
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
|
|
3
|
+
SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
-->
|
|
5
|
+
# MCE examples
|
|
6
|
+
|
|
7
|
+
Runnable experiment snippets for `eval_mce` (LLM-as-judge). Not sample apps.
|
|
8
|
+
|
|
9
|
+
| Example | Kind | What it shows |
|
|
10
|
+
|---------|------|----------------|
|
|
11
|
+
| [judge-override](judge-override/) | Experiment | `experiment.models` (main vs judge) + per-step `config.model` |
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
|
|
3
|
+
SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
-->
|
|
5
|
+
# Example: MCE judge model (`experiment.models` + `eval_mce.config.model`)
|
|
6
|
+
|
|
7
|
+
Eval feature example. Not a sample app.
|
|
8
|
+
|
|
9
|
+
There is **no committed global model in `config.yaml`**. Pin slots on the
|
|
10
|
+
experiment (`experiment.models`), the MAS, or the Agent. Scalar
|
|
11
|
+
`experiment.model` is shorthand for `models.main`. Omitted / `any` is filled
|
|
12
|
+
at engine time from local `config.yaml` `defaults.model`.
|
|
13
|
+
|
|
14
|
+
This example pins **turn vs judge** with the slot map, then a per-step
|
|
15
|
+
override:
|
|
16
|
+
|
|
17
|
+
- `experiment.models.main` — turn default (`gpt-4o`)
|
|
18
|
+
- `experiment.models.judge` — default for every `eval_mce` that omitted `config.model`
|
|
19
|
+
- per-step `config.model` — still wins
|
|
20
|
+
- `experiment.evaluation.model` — optional judge override (wins over `models.judge`)
|
|
21
|
+
|
|
22
|
+
Metric *prompts* live inside MCE (`mce_metrics_plugin`); this library does
|
|
23
|
+
not override them. Only the model id is configurable here.
|
|
24
|
+
|
|
25
|
+
| File | Role |
|
|
26
|
+
|------|------|
|
|
27
|
+
| `experiment.yaml` | Lab spec: `models.judge` + one strict step `config.model` |
|
|
28
|
+
| `mas.yaml` | Stub Agent (`spec.models: gpt-4o`) so `applications.manifest` resolves |
|
|
29
|
+
|
|
30
|
+
## Quickstart
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
mas-ctl validate library-eval/examples/mce/judge-override/experiment.yaml
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
To run for real, point `applications` at a MAS that produced traces, then:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
mas-lab benchmark run library-eval/examples/mce/judge-override/experiment.yaml --progress
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
INFO logs: `EvalMceStep … judge model=… source=experiment.models.judge`
|
|
43
|
+
(or `eval_mce.config.model` on the strict step). Omit `models.judge` and
|
|
44
|
+
the source is `experiment.model` / `application.spec.models`.
|
|
45
|
+
|
|
46
|
+
## What is overridable
|
|
47
|
+
|
|
48
|
+
Existing `eval_mce` config (unchanged) plus **`model`**:
|
|
49
|
+
|
|
50
|
+
| Key | Default | Meaning |
|
|
51
|
+
|-----|---------|---------|
|
|
52
|
+
| `runs_dir` | pipeline output dir | Tree of `item*/r*/traces/events.jsonl` |
|
|
53
|
+
| `metrics` | all session MCE metrics | Subset to score |
|
|
54
|
+
| `overwrite` | `false` | Recompute `metrics.json` |
|
|
55
|
+
| `validate` | `true` | Schema-check artefacts |
|
|
56
|
+
| `max_workers` | `2` | Parallel judge calls |
|
|
57
|
+
| `fail_threshold` | `1.0` | Fraction of items that may fail |
|
|
58
|
+
| **`model`** | `experiment.models.judge` then `models.main` then application `spec.models[]` | LLM-as-judge model |
|
|
59
|
+
|
|
60
|
+
## Docs
|
|
61
|
+
|
|
62
|
+
- [summarization.md § MCE judge](../../../../docs/manifests/summarization.md#mce-judge-model)
|
|
63
|
+
- [experiment.md](../../../../docs/manifests/experiment.md)
|
|
64
|
+
- [pipeline-steps.md](../../../../lab/docs/pipeline-steps.md)
|
|
65
|
+
- Category: [MCE examples](../README.md)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
# Feature example for experiment.models slots and eval_mce config.model.
|
|
4
|
+
# Not a sample app. validate-only unless you point applications at a real MAS.
|
|
5
|
+
experiment:
|
|
6
|
+
name: judge-override
|
|
7
|
+
description: "Pin turn vs judge via experiment.models; per-step config.model still wins."
|
|
8
|
+
models:
|
|
9
|
+
main: gpt-4o
|
|
10
|
+
judge: gpt-4o-mini
|
|
11
|
+
application:
|
|
12
|
+
manifest: ./mas.yaml
|
|
13
|
+
evaluation:
|
|
14
|
+
method: llm_judge
|
|
15
|
+
post:
|
|
16
|
+
- type: extract_trajectories
|
|
17
|
+
- type: eval_mce
|
|
18
|
+
depends_on: [extract_trajectories]
|
|
19
|
+
- type: eval_mce
|
|
20
|
+
name: eval_mce_strict
|
|
21
|
+
depends_on: [extract_trajectories]
|
|
22
|
+
config:
|
|
23
|
+
model: gpt-4o
|
|
24
|
+
max_workers: 2
|
|
25
|
+
fail_threshold: 0.5
|
|
26
|
+
metrics:
|
|
27
|
+
- goal_success_rate
|
|
28
|
+
- answer_relevancy
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
apiVersion: mas/v1
|
|
4
|
+
kind: Agent
|
|
5
|
+
|
|
6
|
+
metadata:
|
|
7
|
+
name: qa-agent
|
|
8
|
+
|
|
9
|
+
spec:
|
|
10
|
+
models:
|
|
11
|
+
- model: gpt-4o
|
|
12
|
+
description: Stub agent for the eval_mce judge-override example.
|
|
13
|
+
context:
|
|
14
|
+
role: |
|
|
15
|
+
Answer questions clearly.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Copyright (c) 2026 Cisco Systems, Inc. and its affiliates
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
# MAS Library Metadata — Eval
|
|
4
|
+
#
|
|
5
|
+
# Declares the eval_metric plugin type and a toy metric used by tests and docs.
|
|
6
|
+
# Libraries register metrics onto the MCE eval provider.
|
|
7
|
+
|
|
8
|
+
apiVersion: mas/v1
|
|
9
|
+
kind: Library
|
|
10
|
+
|
|
11
|
+
name: eval
|
|
12
|
+
description: >
|
|
13
|
+
Evaluation metrics and LLM-as-judge scoring. Hosts the eval_metric plugin
|
|
14
|
+
type so other libraries can register session metrics onto an eval provider.
|
|
15
|
+
version: "0.2.0"
|
|
16
|
+
|
|
17
|
+
module_base: mas.library.eval
|
|
18
|
+
|
|
19
|
+
types:
|
|
20
|
+
- eval_metric
|
|
21
|
+
|
|
22
|
+
plugins:
|
|
23
|
+
- type: eval_metric
|
|
24
|
+
name: toy_echo
|
|
25
|
+
module: mas.library.eval.metrics.toy
|
|
26
|
+
class: ToyEchoMetric
|
|
27
|
+
description: Example session metric that scores 1.0 when a native trace exists.
|
|
28
|
+
attributes:
|
|
29
|
+
provider: mce
|