Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 | 30x 30x 30x 30x 357x 14x 1x 30x 30x 5x 5x 2x 30x 30x 30x 6x 6x 30x 10x 10x 30x 5x 3x 6x 6x 6x 3x 5x 5x | /**
* The evaluation section's objects.
*
* Four words, one owner each:
*
* - A **dataset** (`TestSuite`) is cases only: what to ask and what a correct
* answer looks like. It carries no scorer, no target and no runs.
* - An **evaluation** (`Experiment`) is a recipe: one dataset, one scoring
* mechanism, one or more variants. Re-runnable.
* - A **run** (`ExperimentBatch`) is one execution of an evaluation, with its
* leaderboard, per-cell results and regression verdict.
* - A **report** row (`BatchReportRow`) is a run read across evaluations.
*
* The backend tables keep their historical names (`experiments`,
* `test_suites`), which is why the types do too.
*/
export type EvaluationStatus = "draft" | "active" | "archived";
export type EvaluationScorer =
| "manual"
| "llm"
| "exact_match"
| "contains"
| "not_contains"
| "regex"
| "json_match";
export type RunnableStatus =
"queued" | "running" | "completed" | "failed" | "cancelled";
/** How a scorer's settings are grouped in the picker's headings. */
export type ScorerGroupKey = "model" | "deterministic" | "none";
/** One setting a scorer takes, and the control that renders it. */
export interface ScorerConfigField {
key: string;
label: string;
type: "text" | "lines" | "textarea" | "boolean";
hint?: string;
placeholder?: string;
default?: unknown;
}
/**
* A scorer as described by GET /evaluations/scorers.
*
* The picker renders from this and nothing else: the label, when to reach
* for it, how the number is computed, what it needs from the dataset, and
* which settings to show. fe-core deliberately keeps no second copy of any
* of it — a scorer added to svc-core's registry arrives explained.
*/
export interface ScorerInfo {
kind: EvaluationScorer;
label: string;
/** One line: when you would reach for this scorer. */
summary: string;
description: string;
/** How the 0–1 number is arrived at, in plain words. */
how_it_scores: string;
/** What it needs from the dataset's cases. */
needs: string;
group: ScorerGroupKey;
requires_expected: boolean;
/** Whether the pass threshold changes anything — binary scorers pass on
* the match itself, so showing them one offers a setting that does
* nothing. */
uses_threshold: boolean;
/** Set on a scorer kept only so existing evaluations re-run identically.
* Never offered for a new one; shown when already selected. */
superseded_by: EvaluationScorer | null;
config_fields: ScorerConfigField[];
}
/** A picker heading: what does the grading. */
export interface ScorerGroupInfo {
key: ScorerGroupKey;
label: string;
summary: string;
}
/** GET /evaluations/scorers — the scorer vocabulary, two registries. */
export interface ScorerCatalogue {
scorers: ScorerInfo[];
groups: ScorerGroupInfo[];
default_pass_threshold: number;
}
/**
* What a variant invokes: a raw model (provider + model, or a svc-ai model
* id) or one of the user's agents.
*/
/** svc-ai's reasoning-effort levels (`ModelConfig.effort`). */
export type ModelEffortLevel = "low" | "medium" | "high" | "xhigh" | "max";
export const MODEL_EFFORT_LEVELS: ModelEffortLevel[] = [
"low",
"medium",
"high",
"xhigh",
"max",
];
/**
* What a variant runs on and with.
*
* `type` + `model_id` or `agent_id` is the base. Everything else is an
* optional override, the same list whatever the base: for an agent,
* `model_id` runs it on another model; `temperature`, `effort` and
* `max_tokens` replace the model's defaults. Omitted means "the base's own".
*/
export interface EvaluationTarget {
type?: "model" | "agent" | "swarm";
provider?: string | null;
model?: string | null;
model_id?: string | null;
agent_id?: string | null;
agent_name?: string | null;
label?: string | null;
system_prompt?: string | null;
temperature?: number | null;
max_tokens?: number | null;
/** Reasoning effort, for models that take it instead of temperature. */
effort?: ModelEffortLevel | null;
/** An agent's cost profile in place of its own (agents only). */
cost_profile?: string | null;
/** A swarm: each case is one whole run of it, its answer graded. */
swarm_id?: string | null;
/** A swarm's budget and time cap a case, in place of its defaults. */
budget_usd?: number | null;
time_cap_s?: number | null;
/** What this target can reach while it answers — see
* {@link EvaluationContextSpec}. Recorded back on the result, because a
* score is not interpretable without knowing what was attached. */
context?: EvaluationContextSpec;
}
/** The aggregate written onto a finished run. */
export interface RunSummary {
total: number;
scored: number;
passed: number;
failed: number;
errors: number;
pass_rate: number | null;
mean_score: number | null;
mean_latency_ms: number | null;
input_tokens: number;
output_tokens: number;
total_tokens: number;
duration_ms: number;
scorer?: EvaluationScorer;
/** Cases every variant answered and failed — check their labels first. */
suspect_labels?: SuspectLabel[];
/** How often each dataset criterion was met (checklist judging only). */
criteria?: CriterionPassRate[];
/** How many times each case was asked (1 on a plain run). The figures
* below are null on a plain run — one pass has no spread to measure,
* which is not the same as a spread of zero. */
repeats?: number;
/** Standard deviation of the per-pass mean score. */
score_sd?: number | null;
score_min?: number | null;
score_max?: number | null;
/** Share of cases whose verdict was the same on every repeat. */
consistency?: number | null;
/** How many (variant, case) cells flipped between repeats. */
inconsistent?: number | null;
/** The cells that flipped, on the run's summary only. */
inconsistent_cases?: InconsistentCase[];
/** Present instead of the counts when the run failed outright. */
error?: string;
}
/**
* A case every graded answer in a run failed (at least two of them). When
* independent answerers all fail one case, a wrong reference answer or an
* unsatisfiable criterion is often the likelier cause.
*/
export interface SuspectLabel {
case_id: string | null;
case_name: string;
answers: number;
reasons: string[];
}
/** A (variant, case) whose verdict changed between a run's repeats. */
export interface InconsistentCase {
variant_id: string;
case_id: string | null;
case_name: string | null;
passed: number;
answers: number;
}
/** The most repeats one run may ask for — svc-core's `spread.MAX_REPEATS`. */
export const MAX_REPEATS = 5;
export interface RunProgress {
completed: number;
total: number;
}
/** One variant's line in a run's ranking. */
export interface LeaderboardRow extends RunSummary {
variant_id: string;
target: EvaluationTarget | null;
rank: number;
/** What the variant's answers cost (not grading), from its model's price.
* Null for an unpriced model — unknown, not free. Absent on runs made
* before costs were recorded. */
cost_usd?: number | null;
cost_per_case_usd?: number | null;
}
/** One variant's result, as the dataset's best-configurations view ranks it. */
export interface BestConfigurationRow {
experiment_id: string;
experiment_name: string;
batch_id: string;
finished_at: string | null;
scorer: EvaluationScorer;
judge: EvaluationTarget | null;
variant_id: string;
variant_name: string;
target: EvaluationTarget | null;
preset: VariantPresetTag | null;
mean_score: number | null;
pass_rate: number | null;
total: number | null;
errors: number | null;
mean_latency_ms: number | null;
total_tokens: number | null;
cost_usd: number | null;
cost_per_case_usd: number | null;
repeats: number;
score_sd: number | null;
consistency: number | null;
/** Nothing else in its group is as good and as cheap. */
best_value: boolean;
}
/** Rows graded the same way — only these are ranked against each other. */
export interface BestConfigurationGroup {
key: string;
scorer: EvaluationScorer;
scorer_label: string;
judge: EvaluationTarget | null;
rows: BestConfigurationRow[];
}
export interface BestConfigurations {
dataset_version: number | null;
experiments_compared: number;
groups: BestConfigurationGroup[];
}
/**
* One run of an evaluation: its variants over its dataset.
*
* Records which dataset it asked and which revision of the dataset and of
* the evaluation was in force, so a result resolves to the exact
* configuration that produced it.
*/
export interface ExperimentBatch {
id: string;
label: string | null;
status: RunnableStatus | null;
created_at: string | null;
started_at: string | null;
finished_at: string | null;
dataset_id: string | null;
dataset_version: number | null;
evaluation_version: number | null;
/** The verdict stamped on when the run finished, if it had a baseline. */
regression?: RegressionHeadline | null;
variant_ids: string[];
config: Record<string, unknown>;
progress: RunProgress;
summary?: RunSummary | null;
leaderboard?: LeaderboardRow[] | null;
error?: string | null;
}
/**
* One run, as a report reads it across evaluations.
*
* Flatter than {@link ExperimentBatch} on purpose: these are the figures the
* backend filters and orders by in SQL, so they are columns rather than nested
* inside a summary blob. A run belongs to an evaluation and asked a dataset;
* the row names both, so "how do my agents do on this set" can be asked
* across evaluations.
*/
// ─── Assurance ────────────────────────────────────────────────────────────────
/**
* Whether the version of an agent now in force has evaluation evidence
* behind it (svc-core `services/evaluation/assurance.py`). Only runs of the
* agent *as configured* count — a variant on another model or with a
* candidate prompt is evidence about an alternative, not the agent.
*
* - `current` evaluated at this version, and at or above every dataset's
* pass mark — exactly what the evidence gate lets through
* - `failing` evaluated at this version, below a dataset's pass mark
* - `unscored` evaluated at this version, but no run is scored yet
* - `outdated` only an older version was evaluated; the agent changed since
* - `unrecorded` it was evaluated before runs recorded agent versions
* - `never` no completed run has evaluated it
* - `regressed` its latest run regressed, whatever else is true
*/
export type AssuranceStatus =
| "current"
| "failing"
| "unscored"
| "outdated"
| "unrecorded"
| "never"
| "regressed";
export interface AssuranceRun {
batch_id: string;
experiment_id: string;
experiment_name: string;
dataset_id: string | null;
dataset_name: string | null;
/** The agent's version the run evaluated; null before versions were recorded. */
evaluated_version: number | null;
regression_verdict: string | null;
/** This agent's own figures in the run (its variant's leaderboard row). */
mean_score: number | null;
pass_rate: number | null;
/** The mean score the dataset asks for (its own, or the 0.8 default). */
pass_mark: number;
/** Reached the pass mark without regressing; null when not yet scored. */
passed: boolean | null;
created_at: string | null;
/** The variant that ran the agent. */
variant_id?: string | null;
/** The agent's scored answers in the run, and their standard deviation. */
answers?: number;
answer_sd?: number | null;
/** What one of the agent's answers cost in the run, grading left out;
* null when it could not be priced. */
cost_per_answer_usd?: number | null;
/** Built-in agents: a benchmark run for this release is replacing it. */
refreshing?: boolean;
}
/** How far an answer may land from the average: a name for `sd` on the 0–1
* score scale (svc-core `evaluation/risk.py` `RISK_BANDS`). */
export type RiskBand = "low" | "moderate" | "high";
/**
* Expected quality and risk, read like an asset's return and volatility:
* the average answer score (each dataset weighted equally) and the standard
* deviation of individual answers. The variance splits into answers
* disagreeing inside a dataset (`within`) and datasets disagreeing with each
* other (`between`).
*/
export interface QualityProfile {
mean: number;
sd: number;
within_sd: number;
between_sd: number;
/** Share of the variance from inside datasets; null when there is none. */
within_share: number | null;
answers: number;
datasets: number;
/** Null with too few answers to say. */
risk: RiskBand | null;
}
/** A gold dataset CHAINR Bot has no result on yet, and where it is. */
export interface PendingDataset {
dataset_id: string;
dataset_name: string;
/** `interrupted`: cut off by a deploy or restart, and due again.
* `next_round`: run this month already, so measured again in next
* month's round (one round a month).
* `off`: this deployment does not run the benchmark. */
status:
| "running"
| "queued"
| "interrupted"
| "failed"
| "next_round"
| "off";
error: string | null;
}
export interface AgentAssurance {
agent_id: string;
agent_name: string;
current_version: number | null;
status: AssuranceStatus;
/** Completed runs that evaluated this agent. */
runs: number;
latest_run: AssuranceRun | null;
/** The newest run that evaluated the version now in force. */
current_version_run: AssuranceRun | null;
/** The newest scored run of the version in force on each dataset. */
datasets?: AssuranceRun[];
/** Average and risk over those runs; null with no scored answer. */
quality?: QualityProfile | null;
/** What an answer cost it over the same runs, each dataset weighted
* equally; null unless every one of them could be priced. */
cost_per_answer_usd?: number | null;
/** Built-in agents: the gold datasets still to report. */
pending_datasets?: PendingDataset[];
}
export interface FleetAssurance {
/** Worst first. */
agents: AgentAssurance[];
summary: Record<AssuranceStatus, number> & { total: number };
/**
* Built-in agents (CHAINR Bot), apart so the counts stay the workspace's
* own — judged on the platform benchmark plus the viewer's own runs.
*/
built_in?: AgentAssurance[];
}
// ── The platform benchmark ────────────────────────────────────────────────────
/** One completed benchmark run of one target on one dataset. */
export interface BenchmarkResult {
batch_id: string;
score: number | null;
pass_rate: number | null;
/** Reached the dataset's pass mark without regressing. */
passed: boolean;
regression_verdict: string | null;
dataset_version: number | null;
/** The deploy the run was made on. */
deploy_id: string | null;
/** CHAINR Bot's release (agent version) it evaluated; null for a model. */
agent_version: number | null;
/** Measured, the whole run with its grading; null when nothing could be
* priced. */
cost_usd: number | null;
/** What one answer cost, grading left out; null when unpriced. */
cost_per_answer_usd?: number | null;
evaluated_at: string | null;
/** Scored answers in the run, and their standard deviation. */
answers?: number;
answer_sd?: number | null;
/** The model that graded it, as "provider/model": every score is relative
* to its judge. */
judge?: string | null;
}
export interface BenchmarkRow {
experiment_id: string;
target_key: string;
kind: "agent" | "model";
name: string;
agent_id: string | null;
model_id: string | null;
/** `current`: a result on the dataset's current version. */
status: "current" | "pending" | "running";
latest: BenchmarkResult | null;
}
export interface BenchmarkDataset {
dataset_id: string;
dataset_name: string;
pass_mark: number;
dataset_version: number | null;
/** CHAINR Bot first, then the models best first. */
rows: BenchmarkRow[];
/** CHAINR Bot's runs over time, oldest first. */
bot_history: BenchmarkResult[];
}
/** `GET /evaluations/benchmark` — the same for every user. */
/** One target's average and risk across every gold dataset. */
export interface BenchmarkTarget {
target_key: string;
kind: "agent" | "model";
name: string;
quality: QualityProfile | null;
datasets_covered: number;
datasets_total: number;
/** On the efficient frontier: nothing else has as good an average for no
* more risk. Only targets with a result on every gold dataset count. */
efficient: boolean;
}
export interface PlatformBenchmark {
/** Runs on deployed hosts only (a deploy id is set). */
enabled: boolean;
deploy_id: string | null;
/** The most the benchmark may spend per calendar month (UTC). */
budget_usd: number;
/** Measured spend this calendar month. */
spend_month_usd: number | null;
/** This month, `YYYY-MM`. */
period: string | null;
/** When the budget resets: the 1st of next month, UTC. */
resets_at: string | null;
datasets: BenchmarkDataset[];
/** Every target across the gold datasets, best average first; empty when
* one dataset was asked for. */
targets: BenchmarkTarget[];
}
/** One dataset's outcome of `POST /evaluations/agents/{id}/evaluate`. */
export interface EvaluateAgentStarted {
dataset_id: string;
experiment_id: string;
batch_id: string | null;
/** `running`: a run of it was already in progress. */
status: "started" | "running";
created: boolean;
}
export interface BatchReportRow {
batch_id: string;
experiment_id: string;
experiment_name: string;
dataset_id: string | null;
/** Null once the dataset has been deleted; the run stays on record. */
dataset_name: string | null;
/** The dataset content version the run asked; runs compare only within
* one. Null for runs made before the dataset had any history. */
dataset_version?: number | null;
label: string | null;
/** Always `completed` in a report; every state when the caller asked for
* unfinished runs too (the Activity feed does). */
status: RunnableStatus | null;
/** Why it failed, for a `failed` run. */
error: string | null;
regression_verdict: RegressionVerdict | null;
scorer: EvaluationScorer | null;
mean_score: number | null;
pass_rate: number | null;
total_cases: number | null;
errors: number | null;
mean_latency_ms: number | null;
total_tokens: number | null;
duration_ms: number | null;
variants: number;
finished_at: string | null;
created_at: string | null;
}
/**
* One content version of a dataset: a stretch of its history over which the
* cases and criteria held still. A rename extends a version; editing a case
* or the criteria starts the next. Runs are compared only within one, and a
* dataset always runs at the latest.
*/
export interface DatasetVersion {
version: number;
/** The last history version in the stretch (later ones were metadata). */
through_version: number;
created_at: string | null;
criteria: CriterionItem[];
/** False for versions recorded before datasets kept their cases in full. */
cases_recorded: boolean;
case_count: number | null;
runs: number;
latest: boolean;
}
/** A case as a dataset version recorded it. */
export type DatasetVersionCase = Omit<
TestCase,
"id" | "test_suite_id" | "created_at"
> & { case_id: string };
export interface DatasetVersionDetail extends DatasetVersion {
cases: DatasetVersionCase[] | null;
}
export interface DatasetVersionList {
versions: DatasetVersion[];
/** Runs made before the dataset had any history. */
unversioned_runs: number;
}
/** Headline totals over every run in scope, aggregated in SQL. */
export interface BatchReportTotals {
since: string;
batches: number;
experiments: number;
/** Averaged over runs, not over cases — each run is one measurement of
* one configuration. Null when nothing in the window produced a score. */
mean_score: number | null;
cases: number;
errors: number;
total_tokens: number;
}
/** One variant's result within an optimisation round. */
export interface OptimisationResult extends RunSummary {
variant_id: string;
name: string;
rationale?: string | null;
}
export interface OptimisationRound {
round: number;
label: string;
results: OptimisationResult[];
best_variant_id: string;
}
/** The prompt-optimisation search stored on an evaluation. */
export interface OptimisationState {
id: string;
status: RunnableStatus;
created_at: string;
finished_at?: string;
base_variant_id: string;
rounds: number;
candidates_per_round: number;
dataset: { dataset_id?: string } | null;
instructions: string;
case_count: number;
history: OptimisationRound[];
best: {
variant_id: string;
name: string;
prompt: string | null;
mean_score: number | null;
pass_rate: number | null;
round: number;
} | null;
error?: string;
}
/**
* What `POST /evaluations/compare` answers with.
*
* The comparison is kept server-side under `comparison_id` — as a run nobody
* owns yet — so "save as evaluation" can adopt it as the evaluation's first
* run rather than discard the results just read. Unsaved comparisons are
* purged after a day.
*/
export interface Comparison {
comparison_id: string | null;
results: ComparisonResult[];
}
/** One row of an ad-hoc comparison. */
export interface ComparisonResult {
target: EvaluationTarget;
system_prompt: string;
output: string;
error: string | null;
score: number | null;
score_reason: string | null;
passed: boolean | null;
scorer: EvaluationScorer;
latency_ms: number;
input_tokens: number;
output_tokens: number;
total_tokens: number;
}
/**
* The evaluation's extension config. Grading and the dataset are columns on
* the evaluation now (`scorer`, `scorer_config`, `judge`, `dataset_id`); this
* holds what has no column yet.
*/
export interface EvaluationConfig {
concurrency?: number;
regression?: { tolerance?: Record<string, number> };
optimisation?: OptimisationState;
[key: string]: unknown;
}
/** An evaluation: one dataset, one scorer, its variants. */
export interface Experiment {
id: string;
name: string;
description: string | null;
status: EvaluationStatus;
dataset_id: string;
scorer: EvaluationScorer;
scorer_config: Record<string, unknown> | null;
/** The grading model for the llm scorer; the platform default when null. */
judge: EvaluationTarget | null;
config: EvaluationConfig | null;
is_ai_generated?: boolean;
generation_id?: string | null;
owner_user_id?: string | null;
owner_organisation_id?: string | null;
owner_project_id?: string | null;
created_at: string;
}
/** One prior turn in the conversation a case starts from. */
export interface ContextMessage {
role: "user" | "assistant" | "system";
content: string;
}
/**
* What a variant may reach while it answers — its *capability*.
*
* **Omitted is not the same as empty.** Leaving `tools` out keeps the agent's
* own; sending `[]` takes them all away. That distinction is what makes a
* with/without comparison expressible — without it there is no way to ask
* "does the compliance repository actually help?".
*
* Rules are deliberately absent: they apply at inference, and an evaluation
* that could switch them off would measure a system nobody runs. A case's
* *situation* (history, variables) is {@link CaseSituation}, never this.
*/
export interface EvaluationContextSpec {
knowledge_repository_ids?: string[];
knowledge_ids?: string[];
tools?: string[];
variables?: Record<string, string>;
}
/**
* The situation a case's question arrives in: the conversation so far and
* the values substituted into the prompt as `{{name}}`. A case never names
* knowledge or tools — those are a variant's capability.
*/
export interface CaseSituation {
history?: ContextMessage[];
variables?: Record<string, string>;
/** Named values shown to the agent after the prompt; null = not provided. */
data?: Record<string, unknown>;
/** Tools whose answers the case scripts, so live data does not move. */
tool_fixtures?: ToolFixture[];
}
/**
* A scripted tool: every call returns `response`. It replaces a real tool of
* the same name (keeping its shape) or adds one.
*/
export interface ToolFixture {
name: string;
description?: string | null;
response: string;
}
/** One tool call an agent made during a run, and what came back. */
export interface ToolCall {
name: string;
args: Record<string, unknown>;
output: string | null;
error?: boolean;
}
/** What a case expects the agent to do. Graded as a must-pass criterion. */
export type ExpectedBehaviour = "answer" | "clarify" | "decline";
export const EXPECTED_BEHAVIOUR_LABELS: Record<ExpectedBehaviour, string> = {
answer: "Answer the question",
clarify: "Ask for clarification",
decline: "Decline to answer",
};
/** A question an agent paused to ask (ask_user) instead of answering. */
export interface ClarificationQuestion {
id?: string;
question: string;
kind?: string;
options?: { value: string; label: string }[];
}
/**
* One thing a good answer does. A `gate` is must-pass: failing it scores the
* case 0 whatever else was met.
*/
export interface CriterionItem {
text: string;
gate: boolean;
}
/**
* Something a correct answer states, checked by code: a number within
* `tolerance_pct` (default 1%), or text / accepted spellings.
*/
export interface CaseFact {
label?: string | null;
value: number | string | string[];
tolerance_pct?: number | null;
gate?: boolean;
}
/** One criterion or fact, as the scorer judged it on a cell. */
export interface CriterionVerdict {
text: string;
source: "dataset" | "case" | "fact" | "tool" | "behaviour";
gate: boolean;
met: boolean;
reason: string | null;
}
/** How often one dataset criterion was met across a run. */
export interface CriterionPassRate {
text: string;
gate: boolean;
met: number;
total: number;
}
/**
* Criteria as items, whatever shape they were stored in. Results recorded
* before criteria were items carry one block of text.
*/
export const criteriaItems = (
value: CriterionItem[] | string | null | undefined,
): CriterionItem[] => {
if (!value) return [];
if (Array.isArray(value)) return value.filter((i) => i && i.text);
return value.trim() ? [{ text: value.trim(), gate: false }] : [];
};
/**
* A case's mechanical checks — part of its label, beside its criteria,
* reference answer and graded examples.
*
* Facts about the answer, never how strictly to judge it. Only the case
* says what is correct: an experiment's scorer settings cannot carry checks
* or criteria (svc-core refuses them), and the experiment decides only which
* scorer runs and at what pass mark.
*/
export interface CaseExpectation {
format?: "text" | "json" | "markdown";
schema?: Record<string, unknown>;
must_contain?: string[];
must_not_contain?: string[];
pattern?: string;
facts?: CaseFact[];
/** Tools the agent must call — and must not. */
must_use_tools?: string[];
must_not_use_tools?: string[];
}
/**
* An answer graded in advance. Examples anchor an LLM judge's scale: "this
* is a 0.3, and why" is steadier evidence than any adjective in criteria.
*/
export interface CaseExample {
output: string;
/** 0.0–1.0 */
score: number;
note?: string | null;
}
/** A field an import could not use, why, and which cases carried it. */
export interface ImportIgnoredField {
field: string;
reason: string;
cases: string[];
}
/** What a bulk import made, and what it had to leave out. */
export interface ImportCasesResult {
created: TestCase[];
ignored: ImportIgnoredField[];
}
/** Most graded examples a case may carry; svc-core refuses more. */
export const MAX_CASE_EXAMPLES = 8;
/** What a preset-made variant varies, and its value there. */
export interface VariantPresetTag {
key: string;
dimension: string;
value: string | number;
label: string;
}
/** One parameter a preset takes. `type` decides the control the form draws. */
export interface PresetParam {
key: string;
label: string;
type:
| "models"
| "agents"
| "agent"
| "base"
| "temperatures"
| "effort_levels"
| "swarms"
| "repositories"
| "tools"
| "prompt";
hint: string;
required: boolean;
min_items?: number;
max_items?: number;
}
/** A variant preset: one question, expanded into several variants. */
export interface PresetInfo {
key: string;
label: string;
summary: string;
dimension: string;
params: PresetParam[];
}
export interface PresetCatalogue {
presets: PresetInfo[];
max_variants: number;
}
/** What applying a preset makes, and what a run would then cost. */
export interface PresetResult {
variants: {
id?: string;
name: string;
prompt: string | null;
config: ExperimentVariant["config"];
}[];
calls: {
new_variants: number;
variants_after: number;
cases: number;
answers_per_run: number;
judge_calls_per_run: number;
/** The most the new swarm variants may spend in one run of the
* experiment: each its budget a case, every case. */
swarm_budget_per_run_usd?: number;
};
}
export interface ExperimentVariant {
id: string;
experiment_id: string;
name: string;
prompt: string | null;
config: {
target?: EvaluationTarget;
/** What this variant may reach while it answers. */
context?: EvaluationContextSpec;
/** Set on variants a preset made: what they vary, and their value on it.
* Results are read along `dimension`. */
preset?: VariantPresetTag;
/** Set on candidates the optimiser generated. */
optimisation?: {
id: string;
round: number;
parent_variant_id: string;
rationale?: string;
};
[key: string]: unknown;
} | null;
created_at: string;
}
/** Per-invocation telemetry recorded alongside every result. */
/**
* The model a routing rule moved a cell to, on runs from before routing rules
* were removed (October 2026). The variant names the model it started on; this
* is the one that answered. Nothing records it any more.
*/
export interface RoutedModel {
id: string | null;
model_name?: string | null;
display_name?: string | null;
}
export interface RunMetadata {
latency_ms?: number;
input_tokens?: number;
output_tokens?: number;
total_tokens?: number;
case_name?: string;
case_id?: string;
tags?: string[];
error?: string;
/** Set when the agent paused on ask_user: the questions it asked. */
clarification?: ClarificationQuestion[];
/** Every tool the agent called, in order. */
tool_calls?: ToolCall[];
/** For a swarm's cell, the run that answered it. */
swarm_run?: {
id: string;
status: string;
wrap_up_reason?: string | null;
tasks?: number;
approach?: string | null;
} | null;
/** Set on an older run when a routing rule moved the cell to another model. */
routed_model?: RoutedModel | null;
[key: string]: unknown;
}
/** The name of the model a routing rule moved a cell to, or null when the
* cell ran on the model its variant names. */
export const routedModelName = (
meta: RunMetadata | null | undefined,
): string | null => {
const routed = meta?.routed_model;
if (!routed) return null;
return routed.display_name || routed.model_name || "another model";
};
/**
* One scored (variant, case) cell of a run.
*
* `test_case_id` names the dataset case it scored; `variant_id` the variant
* that answered. Both are what per-case regression keys on.
*/
export interface ExperimentRun {
id: string;
experiment_id: string | null;
variant_id: string | null;
batch_id: string | null;
test_case_id: string | null;
input: {
prompt?: string;
name?: string;
case_id?: string | null;
expected_output?: string | null;
/** The label the cell was graded against, as it stood at run time. */
criteria?: CriterionItem[] | string | null;
dataset_criteria?: CriterionItem[] | string | null;
examples?: CaseExample[];
expectation?: CaseExpectation;
} | null;
output: string | null;
score: { value?: number | null; [key: string]: unknown } | null;
score_reason: string | null;
scorer: EvaluationScorer | null;
passed: boolean | null;
run_metadata: RunMetadata | null;
status: RunnableStatus | null;
started_at: string | null;
finished_at: string | null;
created_at: string;
}
/**
* The mean score a model or agent must reach on a dataset to pass it, when
* the dataset sets none (svc-core `evaluation.evidence.DEFAULT_PASS_MARK`).
*/
export const DEFAULT_PASS_MARK = 0.8;
/** A dataset's pass mark, or the platform default. */
export const passMarkOf = (suite: Pick<TestSuite, "pass_mark"> | null) =>
suite?.pass_mark ?? DEFAULT_PASS_MARK;
/** A dataset: cases, and what every good answer to them must do. */
export interface TestSuite {
id: string;
name: string;
description: string | null;
status: EvaluationStatus;
/** Inherited by every case, which adds its own. */
criteria?: CriterionItem[] | null;
/**
* The mean score that passes the dataset; null for the platform default
* ({@link DEFAULT_PASS_MARK}). Varies with the use case the cases stand
* for, and is what the evidence gate and Assurance judge runs against.
*/
pass_mark?: number | null;
/** How many cases it holds (served on the listing and the read). */
case_count?: number | null;
/** A gold dataset: maintained by CHAIN-R, readable and runnable by every
* user, copied rather than edited. */
is_system?: boolean;
config: Record<string, unknown> | null;
is_ai_generated?: boolean;
generation_id?: string | null;
owner_user_id?: string | null;
owner_organisation_id?: string | null;
owner_project_id?: string | null;
created_at: string;
}
/**
* One case of a dataset: the data (a question and the situation it arrives
* in) and its label (criteria, reference answer, graded examples, checks).
*/
export interface TestCase {
id: string;
test_suite_id: string;
name: string | null;
input: Record<string, unknown>;
expected_output: string | null;
/** Added to the dataset's criteria. */
criteria?: CriterionItem[] | null;
examples?: CaseExample[] | null;
expected_behaviour?: ExpectedBehaviour | null;
expectation: CaseExpectation | null;
situation: CaseSituation | null;
tags: string[] | null;
created_at: string;
}
/**
* How one run compared to the run before it.
*
* `no_baseline` is the first run of an evaluation; `incomparable` means
* earlier runs exist but none measured the same thing (a different scorer).
* Neither is a pass, and neither is a failure.
*/
export type RegressionVerdict =
"regressed" | "improved" | "unchanged" | "no_baseline" | "incomparable";
/** One tracked figure, measured on both runs and judged. */
export interface RegressionMetric {
key: string;
label: string;
direction: "higher_is_better" | "lower_is_better";
/** Whether moving the wrong way is enough to fail the comparison. Latency
* and token spend are reported but never gate — they move with provider
* load rather than with the change under test. */
gating: boolean;
baseline: number | null;
current: number | null;
delta: number | null;
relative_delta: number | null;
/** Movement treated as noise, in the metric's own units. */
tolerance: number | null;
regressed: boolean;
improved: boolean;
}
/** One case, as it did before and as it did now. */
export interface RegressionCaseDelta {
case_id: string;
case_name: string | null;
baseline_passed: boolean | null;
current_passed: boolean | null;
baseline_score: number | null;
current_score: number | null;
delta: number | null;
kind: "broke" | "fixed" | "score_drop" | "score_gain";
}
export interface RegressionCases {
compared: number;
added: number;
removed: number;
broke: number;
fixed: number;
score_drops: number;
score_gains: number;
truncated: boolean;
deltas: RegressionCaseDelta[];
}
/** Which run a comparison is about. */
export interface RegressionRunRef {
run_id: string;
label: string | null;
scorer: EvaluationScorer | null;
target: EvaluationTarget | null;
total: number | null;
finished_at: string | null;
created_at: string | null;
}
/** The full comparison, from `GET .../batches/{id}/regression`. */
export interface RegressionReport {
verdict: RegressionVerdict;
reasons: string[];
current: RegressionRunRef;
baseline: RegressionRunRef | null;
metrics: RegressionMetric[];
cases: RegressionCases;
/** Something other than the prompt changed too. Attribution, not a reason to
* dismiss the verdict — a model swap that scores worse is the point. */
target_changed: boolean;
dataset_changed: boolean;
}
/** The headline stamped onto a run when it finishes. The full report is always
* recomputable from the endpoint; this is what a list can show without it. */
export interface RegressionHeadline {
verdict: RegressionVerdict;
baseline_run_id: string | null;
regressed_metrics: string[];
broke: number;
fixed: number;
target_changed: boolean;
reasons: string[];
}
// ─── Write payloads ───────────────────────────────────────────────────────────
//
// A create body is not a partial resource, and typing it as one is how a real
// 422 stayed invisible: `Partial<ExperimentVariant>` made every field optional
// on this side while the API required `name`. These say exactly what each
// endpoint accepts, so the compiler can hold the contract.
//
// The parent id is deliberately absent from every nested create: it is in the
// URL, and the server takes it from there.
export interface ExperimentCreate {
name: string;
description?: string | null;
scorer?: EvaluationScorer;
scorer_config?: Record<string, unknown> | null;
judge?: EvaluationTarget | null;
config?: EvaluationConfig | null;
owner_organisation_id?: string | null;
owner_project_id?: string | null;
/** Where the cases come from — exactly one of the three. */
dataset_id?: string;
/** Inline cases that create a dataset of the same name alongside. */
cases?: TestCaseCreate[];
/** A Quick try to adopt as this evaluation's first run. The server derives
* the case, scorer and variants from what that comparison actually ran. */
comparison_id?: string;
/** Variants to create with the evaluation, in one transaction. Not with a
* `comparison_id`, which brings its own. */
variants?: VariantCreate[];
}
/** An experiment's dataset is fixed for life, so it is not updatable. */
export interface ExperimentUpdate {
name?: string;
description?: string | null;
status?: EvaluationStatus;
scorer?: EvaluationScorer;
scorer_config?: Record<string, unknown> | null;
judge?: EvaluationTarget | null;
config?: EvaluationConfig | null;
}
export interface VariantCreate {
name: string;
prompt?: string | null;
config?: ExperimentVariant["config"];
}
export type VariantUpdate = Partial<VariantCreate>;
export interface TestSuiteCreate {
name: string;
description?: string | null;
criteria?: CriterionItem[] | null;
pass_mark?: number | null;
config?: Record<string, unknown> | null;
owner_organisation_id?: string | null;
owner_project_id?: string | null;
}
export type TestSuiteUpdate = Partial<TestSuiteCreate> & {
status?: EvaluationStatus;
};
/** Copy a dataset — a gold one, usually — into one of your own. */
export interface TestSuiteCopy {
/** Defaults to the source's name. */
name?: string;
owner_organisation_id?: string | null;
owner_project_id?: string | null;
}
export interface TestCaseCreate {
/** Required: a case with no input has nothing to run. */
input: Record<string, unknown>;
name?: string | null;
expected_output?: string | null;
criteria?: CriterionItem[] | null;
examples?: CaseExample[] | null;
expected_behaviour?: ExpectedBehaviour | null;
expectation?: CaseExpectation | null;
situation?: CaseSituation | null;
tags?: string[] | null;
}
export type TestCaseUpdate = Partial<TestCaseCreate>;
/** Read the flat score off a score column, whatever scorer produced it. */
export const scoreValue = (
score: { value?: number | null } | null | undefined,
): number | null => {
const raw = score?.value;
return typeof raw === "number" ? raw : null;
};
/** Which pass of a repeated run a cell came from (0 for older rows). */
export const runRepeat = (run: ExperimentRun): number => {
const raw = run.run_metadata?.repeat;
return typeof raw === "number" ? raw : 0;
};
/**
* One (variant, case) cell of a run, however many times it was asked: its
* answers in repeat order, their mean score and how many passed. With one
* answer this is that answer's score and verdict.
*/
export interface CellSummary {
runs: ExperimentRun[];
meanScore: number | null;
passed: number;
judged: number;
}
export const summariseCell = (runs: ExperimentRun[]): CellSummary => {
const ordered = [...runs].sort((a, b) => runRepeat(a) - runRepeat(b));
const scores = ordered
.map((r) => scoreValue(r.score))
.filter((v): v is number => v !== null);
const judged = ordered.filter((r) => r.passed !== null);
return {
runs: ordered,
meanScore: scores.length
? scores.reduce((sum, v) => sum + v, 0) / scores.length
: null,
passed: judged.filter((r) => r.passed).length,
judged: judged.length,
};
};
|