@tangle-network/agent-eval 0.109.1 → 0.110.0
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.
- package/dist/analyst/index.d.ts +10 -12
- package/dist/analyst/index.js +8 -11
- package/dist/analyst/index.js.map +1 -1
- package/dist/{analyze-runs-DJYpep3L.d.ts → analyze-runs-Dmz6LA9e.d.ts} +4 -4
- package/dist/{baseline-Bbid3WoO.d.ts → baseline-DsNteOgR.d.ts} +32 -2
- package/dist/belief-state/index.d.ts +6 -6
- package/dist/benchmarks/index.d.ts +4 -4
- package/dist/benchmarks/index.js +7 -8
- package/dist/builder-eval/index.d.ts +4 -4
- package/dist/builder-eval/index.js +1 -2
- package/dist/builder-eval/index.js.map +1 -1
- package/dist/{calibration-BPmzuVPk.d.ts → calibration-Dz8TQV4y.d.ts} +2 -2
- package/dist/campaign/index.d.ts +16 -19
- package/dist/campaign/index.js +7 -8
- package/dist/{chunk-LOJ2QVCE.js → chunk-2IY4ILP4.js} +2 -2
- package/dist/{chunk-LIEJUH2I.js → chunk-6PL5MGDL.js} +9 -9
- package/dist/{chunk-2OGPXHOB.js → chunk-7NX6ZSBG.js} +36 -7
- package/dist/chunk-7NX6ZSBG.js.map +1 -0
- package/dist/{chunk-OVPVM4JC.js → chunk-GTERJI6Q.js} +4 -4
- package/dist/{chunk-YEHAEDUD.js → chunk-IMWDSFUM.js} +604 -2
- package/dist/chunk-IMWDSFUM.js.map +1 -0
- package/dist/{chunk-JZXGWLK5.js → chunk-MHNQWM4I.js} +62 -6
- package/dist/chunk-MHNQWM4I.js.map +1 -0
- package/dist/{chunk-QRVS7MX4.js → chunk-OW47B5WA.js} +3 -5
- package/dist/{chunk-QRVS7MX4.js.map → chunk-OW47B5WA.js.map} +1 -1
- package/dist/{chunk-DBDRR6GF.js → chunk-PLOMR3HP.js} +48 -2
- package/dist/chunk-PLOMR3HP.js.map +1 -0
- package/dist/{chunk-GDZAWO2I.js → chunk-QFGTU7MT.js} +2 -2
- package/dist/{chunk-R6D7NEYJ.js → chunk-RNB2NICW.js} +11 -11
- package/dist/{chunk-V7HNA47Z.js → chunk-RSVSSZKF.js} +5 -5
- package/dist/{chunk-5PK3626Q.js → chunk-XRGOKCMO.js} +88 -17
- package/dist/chunk-XRGOKCMO.js.map +1 -0
- package/dist/{code-agent-session-rnJKlqmT.d.ts → code-agent-session-yitf9I-F.d.ts} +1 -1
- package/dist/contract/index.d.ts +20 -23
- package/dist/contract/index.js +11 -13
- package/dist/contract/index.js.map +1 -1
- package/dist/{control-B8UthSBL.d.ts → control-U8LBKUES.d.ts} +5 -6
- package/dist/control.d.ts +8 -9
- package/dist/control.js +6 -8
- package/dist/{dataset-DS7ytHZU.d.ts → dataset-NENEzRgk.d.ts} +1 -1
- package/dist/{default-registry-BswHCXnU.d.ts → default-registry-Bcf1uKVI.d.ts} +1 -2
- package/dist/{emitter-C2rqGH_l.d.ts → emitter-BRchAAAx.d.ts} +2 -2
- package/dist/{failure-cluster-DH9Flgcf.d.ts → failure-cluster-C48PiReX.d.ts} +2 -2
- package/dist/feedback-trajectory-pDcz1lQ1.d.ts +348 -0
- package/dist/{gepa-B3x5Ulcv.d.ts → gepa-BUNP3606.d.ts} +143 -2
- package/dist/hosted/index.d.ts +7 -7
- package/dist/{index-pPtfoIJO.d.ts → index-Dc3VLGhp.d.ts} +2 -2
- package/dist/index.d.ts +645 -61
- package/dist/index.js +1282 -190
- package/dist/index.js.map +1 -1
- package/dist/{insight-report-B4xrdwEK.d.ts → insight-report-D4cXFsLt.d.ts} +1 -1
- package/dist/{integrity-DqGZg3st.d.ts → integrity-qemeBAyx.d.ts} +1 -1
- package/dist/{types-D1ytG0Yg.d.ts → kind-factory-20hcaYpf.d.ts} +169 -2
- package/dist/meta-eval/index.d.ts +5 -5
- package/dist/meta-eval/index.js +1 -2
- package/dist/meta-eval/index.js.map +1 -1
- package/dist/{multi-layer-verifier-CI4jdX-q.d.ts → multi-layer-verifier-BsqKuLyN.d.ts} +1 -1
- package/dist/multishot/index.d.ts +3 -3
- package/dist/openapi.json +1 -1
- package/dist/pipelines/index.d.ts +6 -7
- package/dist/pipelines/index.js +3 -6
- package/dist/pipelines/index.js.map +1 -1
- package/dist/{policy-edit-DQUXYMDm.d.ts → policy-edit-D2bBDZDf.d.ts} +2 -2
- package/dist/{pre-registration-BUhVPzE7.d.ts → pre-registration-BepVVa6P.d.ts} +3 -3
- package/dist/{provenance-DdDhf6cg.d.ts → provenance-DMvsfknv.d.ts} +3 -5
- package/dist/{query-0aTmbmQe.d.ts → query-Ck190MOd.d.ts} +2 -2
- package/dist/{release-report-DeJpsBiA.d.ts → release-report-oBfOz8ku.d.ts} +3 -3
- package/dist/reporting.d.ts +8 -8
- package/dist/{researcher-Wc7dx6GM.d.ts → researcher-CaH0CwFC.d.ts} +6 -6
- package/dist/rl.d.ts +568 -15
- package/dist/rl.js +4 -4
- package/dist/{rubric-predictive-validity-DPnyG-CE.d.ts → rubric-predictive-validity-C-fMteAW.d.ts} +1 -1
- package/dist/{run-record-I-Z3JNvO.d.ts → run-record-DksGsfgv.d.ts} +1 -1
- package/dist/{runtime-trajectory-iW9IhV3e.d.ts → runtime-trajectory-h5i0SZUj.d.ts} +1 -1
- package/dist/{schema-m0gsnbt3.d.ts → schema-SGWcK9wa.d.ts} +1 -1
- package/dist/{semantic-concept-judge-BmNZPB_j.d.ts → semantic-concept-judge-D7z6JCLZ.d.ts} +57 -4
- package/dist/{store-BcFXE6LG.d.ts → store-BsVi7ncX.d.ts} +1 -1
- package/dist/storyboard/index.d.ts +1 -1
- package/dist/{summary-report-QMZVe3P-.d.ts → summary-report-Bz-0-t8v.d.ts} +2 -2
- package/dist/{test-graded-scenario-DeODGLra.d.ts → test-graded-scenario-mzYBKspu.d.ts} +3 -3
- package/dist/traces.d.ts +54 -11
- package/dist/traces.js +25 -27
- package/dist/{types-BdIv5dvA.d.ts → types-v--ctu-b.d.ts} +2 -2
- package/dist/wire/index.d.ts +5 -6
- package/package.json +1 -71
- package/dist/adapters/http.d.ts +0 -142
- package/dist/adapters/http.js +0 -203
- package/dist/adapters/http.js.map +0 -1
- package/dist/adapters/langchain.d.ts +0 -95
- package/dist/adapters/langchain.js +0 -34
- package/dist/adapters/langchain.js.map +0 -1
- package/dist/adapters/otel.d.ts +0 -112
- package/dist/adapters/otel.js +0 -110
- package/dist/adapters/otel.js.map +0 -1
- package/dist/chunk-2OGPXHOB.js.map +0 -1
- package/dist/chunk-45EEMHTC.js +0 -35
- package/dist/chunk-45EEMHTC.js.map +0 -1
- package/dist/chunk-5BKGXME7.js +0 -65
- package/dist/chunk-5BKGXME7.js.map +0 -1
- package/dist/chunk-5PK3626Q.js.map +0 -1
- package/dist/chunk-6SK5VFYK.js +0 -100
- package/dist/chunk-6SK5VFYK.js.map +0 -1
- package/dist/chunk-DBDRR6GF.js.map +0 -1
- package/dist/chunk-DJWX3GVS.js +0 -81
- package/dist/chunk-DJWX3GVS.js.map +0 -1
- package/dist/chunk-FOUG2VVS.js +0 -855
- package/dist/chunk-FOUG2VVS.js.map +0 -1
- package/dist/chunk-JZXGWLK5.js.map +0 -1
- package/dist/chunk-K7QEIHHJ.js +0 -613
- package/dist/chunk-K7QEIHHJ.js.map +0 -1
- package/dist/chunk-KKHDIONI.js +0 -414
- package/dist/chunk-KKHDIONI.js.map +0 -1
- package/dist/chunk-KMPRBJK4.js +0 -74
- package/dist/chunk-KMPRBJK4.js.map +0 -1
- package/dist/chunk-Q2JRAWRI.js +0 -196
- package/dist/chunk-Q2JRAWRI.js.map +0 -1
- package/dist/chunk-RZTMDUO7.js +0 -49
- package/dist/chunk-RZTMDUO7.js.map +0 -1
- package/dist/chunk-STGVSCDH.js +0 -202
- package/dist/chunk-STGVSCDH.js.map +0 -1
- package/dist/chunk-YEHAEDUD.js.map +0 -1
- package/dist/control-runtime-Acf9CGhw.d.ts +0 -182
- package/dist/corpus-eBVwhCp1.d.ts +0 -560
- package/dist/counterfactual-DlOz8PBx.d.ts +0 -85
- package/dist/diagnose.d.ts +0 -252
- package/dist/diagnose.js +0 -382
- package/dist/diagnose.js.map +0 -1
- package/dist/feedback-trajectory-C9KCo8ag.d.ts +0 -169
- package/dist/governance/index.d.ts +0 -135
- package/dist/governance/index.js +0 -18
- package/dist/governance/index.js.map +0 -1
- package/dist/groundedness/index.d.ts +0 -112
- package/dist/groundedness/index.js +0 -77
- package/dist/groundedness/index.js.map +0 -1
- package/dist/harness-optimizer-mOl9XX_O.d.ts +0 -106
- package/dist/kind-factory-DvIGo_cP.d.ts +0 -171
- package/dist/knowledge/index.d.ts +0 -103
- package/dist/knowledge/index.js +0 -18
- package/dist/knowledge/index.js.map +0 -1
- package/dist/pareto-E-pembql.d.ts +0 -81
- package/dist/perf/index.d.ts +0 -123
- package/dist/perf/index.js +0 -18
- package/dist/perf/index.js.map +0 -1
- package/dist/prm/index.d.ts +0 -104
- package/dist/prm/index.js +0 -265
- package/dist/prm/index.js.map +0 -1
- package/dist/product-benchmark/index.d.ts +0 -247
- package/dist/product-benchmark/index.js +0 -37
- package/dist/product-benchmark/index.js.map +0 -1
- package/dist/red-team-KmmiqBlY.d.ts +0 -63
- package/dist/redact-B40YG2M_.d.ts +0 -45
- package/dist/rubric-Cc6UHvUb.d.ts +0 -73
- package/dist/run-critic-CmMf05uV.d.ts +0 -56
- package/dist/sink-fetch-B1Yg4Til.d.ts +0 -101
- package/dist/telemetry/file.d.ts +0 -19
- package/dist/telemetry/file.js +0 -45
- package/dist/telemetry/file.js.map +0 -1
- package/dist/telemetry/index.d.ts +0 -38
- package/dist/telemetry/index.js +0 -130
- package/dist/telemetry/index.js.map +0 -1
- package/dist/testing-C21CHsq2.d.ts +0 -20
- package/dist/testing.d.ts +0 -1
- package/dist/testing.js +0 -8
- package/dist/testing.js.map +0 -1
- package/dist/trajectory-2TkpSEVh.d.ts +0 -33
- package/dist/workflow/index.d.ts +0 -496
- package/dist/workflow/index.js +0 -2178
- package/dist/workflow/index.js.map +0 -1
- /package/dist/{chunk-LOJ2QVCE.js.map → chunk-2IY4ILP4.js.map} +0 -0
- /package/dist/{chunk-LIEJUH2I.js.map → chunk-6PL5MGDL.js.map} +0 -0
- /package/dist/{chunk-OVPVM4JC.js.map → chunk-GTERJI6Q.js.map} +0 -0
- /package/dist/{chunk-GDZAWO2I.js.map → chunk-QFGTU7MT.js.map} +0 -0
- /package/dist/{chunk-R6D7NEYJ.js.map → chunk-RNB2NICW.js.map} +0 -0
- /package/dist/{chunk-V7HNA47Z.js.map → chunk-RSVSSZKF.js.map} +0 -0
|
@@ -1,560 +0,0 @@
|
|
|
1
|
-
import { R as RunRecord, b as RunSplitTag } from './run-record-I-Z3JNvO.js';
|
|
2
|
-
import { S as Span } from './schema-m0gsnbt3.js';
|
|
3
|
-
import { T as TraceStore } from './store-BcFXE6LG.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Preference dataset extraction — bridge from `RunRecord[]` to RL training.
|
|
7
|
-
*
|
|
8
|
-
* Production RLHF / DPO / KTO / SimPO pipelines need preference triples:
|
|
9
|
-
* `(prompt, chosen, rejected)`. The campaign artifact already contains the
|
|
10
|
-
* ingredients — every (variantId, scenarioId, seed) cell is a candidate
|
|
11
|
-
* that ran the same prompt against the same scenario, scored by the same
|
|
12
|
-
* judge — but turning that into a clean preference dataset requires
|
|
13
|
-
* deciding *what counts as a preference*.
|
|
14
|
-
*
|
|
15
|
-
* This module ships three preference-extraction strategies with explicit
|
|
16
|
-
* tradeoffs, plus a unified output type compatible with HuggingFace TRL,
|
|
17
|
-
* Anthropic finetuning JSONL, and OpenAI fine-tuning APIs. The strategies
|
|
18
|
-
* are deliberately not auto-magical — picking the wrong one corrupts the
|
|
19
|
-
* gradient.
|
|
20
|
-
*
|
|
21
|
-
* Strategies:
|
|
22
|
-
*
|
|
23
|
-
* 1. **`paired-by-scenario-and-seed`** — exact-match comparisons. For
|
|
24
|
-
* each scenario × seed pair, compare every (variantA, variantB) on
|
|
25
|
-
* that exact (scenario, seed). Matches scenarios so the comparison
|
|
26
|
-
* isolates variant effects. Highest signal-to-noise; smallest
|
|
27
|
-
* dataset (only matched pairs count).
|
|
28
|
-
*
|
|
29
|
-
* 2. **`paired-by-scenario`** — looser matching. For each scenario,
|
|
30
|
-
* compare every (variantA, variantB) where both have ≥ 1 run on the
|
|
31
|
-
* same scenario. Aggregates across seeds to compute mean scores per
|
|
32
|
-
* (variant, scenario), then forms preferences from the means. More
|
|
33
|
-
* data, lower per-pair signal.
|
|
34
|
-
*
|
|
35
|
-
* 3. **`top-vs-bottom`** — coarsest. Within each scenario, the highest-
|
|
36
|
-
* scoring run is `chosen`, the lowest is `rejected`. Smallest dataset
|
|
37
|
-
* per scenario but biggest score gap per pair. Useful for early
|
|
38
|
-
* bootstrapping when you have few variants.
|
|
39
|
-
*
|
|
40
|
-
* The output `PreferenceTriple` is *agent-eval-canonical* but trivially
|
|
41
|
-
* mappable to TRL's `DPODataset` shape (`prompt`, `chosen`, `rejected`)
|
|
42
|
-
* via the `toTRLFormat` helper.
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
type PreferenceStrategy = 'paired-by-scenario-and-seed' | 'paired-by-scenario' | 'top-vs-bottom';
|
|
46
|
-
interface PreferenceTriple {
|
|
47
|
-
/** The scenario (input) the variants were run against. */
|
|
48
|
-
scenarioId: string;
|
|
49
|
-
/** RunRecord ids on each side, for traceability. */
|
|
50
|
-
chosenRunId: string;
|
|
51
|
-
rejectedRunId: string;
|
|
52
|
-
/** Variant ids — load-bearing for the RL update. */
|
|
53
|
-
chosenVariantId: string;
|
|
54
|
-
rejectedVariantId: string;
|
|
55
|
-
/** The score gap between chosen and rejected. Larger = stronger signal. */
|
|
56
|
-
marginScore: number;
|
|
57
|
-
/**
|
|
58
|
-
* Optional `(chosen_score, rejected_score)` pair for soft-margin DPO
|
|
59
|
-
* variants. Omitted for `top-vs-bottom` runs that don't carry meaningful
|
|
60
|
-
* scalar gaps.
|
|
61
|
-
*/
|
|
62
|
-
scores?: {
|
|
63
|
-
chosen: number;
|
|
64
|
-
rejected: number;
|
|
65
|
-
};
|
|
66
|
-
/** Tie-breaker — when multiple seeds match this scenario, the one used. */
|
|
67
|
-
seed?: number;
|
|
68
|
-
/**
|
|
69
|
-
* Free-form metadata propagated from the run records — e.g. original
|
|
70
|
-
* prompt-hash, model, etc. Lets the RL trainer reconstruct the prompt.
|
|
71
|
-
*/
|
|
72
|
-
meta: {
|
|
73
|
-
chosenPromptHash: string;
|
|
74
|
-
rejectedPromptHash: string;
|
|
75
|
-
chosenConfigHash: string;
|
|
76
|
-
rejectedConfigHash: string;
|
|
77
|
-
chosenModel: string;
|
|
78
|
-
rejectedModel: string;
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
interface ExtractPreferencesOptions {
|
|
82
|
-
strategy?: PreferenceStrategy;
|
|
83
|
-
/**
|
|
84
|
-
* Minimum score gap required to admit a pair. Pairs below this are
|
|
85
|
-
* dropped — they're noise, not signal. Default 0.05 (5% of [0,1]).
|
|
86
|
-
*/
|
|
87
|
-
minMargin?: number;
|
|
88
|
-
/**
|
|
89
|
-
* Optional split tag filter — restrict to runs from one split. Default
|
|
90
|
-
* `'holdout'` (the canonical "real" signal).
|
|
91
|
-
*/
|
|
92
|
-
splitTag?: RunRecord['splitTag'];
|
|
93
|
-
/**
|
|
94
|
-
* Optional reward extractor that overrides `outcome.holdoutScore` /
|
|
95
|
-
* `outcome.searchScore`. Use to drive preferences off a verifiable
|
|
96
|
-
* reward instead of the headline score.
|
|
97
|
-
*/
|
|
98
|
-
rewardOf?: (run: RunRecord) => number | null;
|
|
99
|
-
}
|
|
100
|
-
interface PreferenceExtractionReport {
|
|
101
|
-
pairs: PreferenceTriple[];
|
|
102
|
-
/** Number of (scenario, seed) cells inspected. */
|
|
103
|
-
cellsInspected: number;
|
|
104
|
-
/** Number of pairs filtered by `minMargin`. */
|
|
105
|
-
pairsBelowMargin: number;
|
|
106
|
-
/** Number of cells with only one variant (no comparison possible). */
|
|
107
|
-
cellsSingleton: number;
|
|
108
|
-
/** Strategy used. */
|
|
109
|
-
strategy: PreferenceStrategy;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Convert `RunRecord[]` to preference triples for RL training.
|
|
113
|
-
*
|
|
114
|
-
* Returns a structured report so callers can see how much data was
|
|
115
|
-
* dropped and why (low-margin pairs, singleton cells). For production
|
|
116
|
-
* pipelines, you usually want to:
|
|
117
|
-
*
|
|
118
|
-
* 1. Run a campaign producing 5–10 variants × 50–200 scenarios × 3 seeds
|
|
119
|
-
* 2. Call this with `strategy: 'paired-by-scenario-and-seed'` and a
|
|
120
|
-
* verifiable-reward extractor as `rewardOf`
|
|
121
|
-
* 3. Pass `report.pairs` to `toTRLFormat` and pipe to your DPO trainer
|
|
122
|
-
*/
|
|
123
|
-
declare function extractPreferences(runs: RunRecord[], opts?: ExtractPreferencesOptions): PreferenceExtractionReport;
|
|
124
|
-
/**
|
|
125
|
-
* TRL-compatible export. TRL's `DPODataset` is `{ prompt, chosen, rejected }`
|
|
126
|
-
* but the prompt isn't stored on the RunRecord — only its hash. The caller
|
|
127
|
-
* passes a `promptOf(promptHash)` lookup that the TRL trainer can use.
|
|
128
|
-
*/
|
|
129
|
-
declare function toTRLFormat(triples: PreferenceTriple[], promptOf: (hash: string) => string): Array<{
|
|
130
|
-
prompt: string;
|
|
131
|
-
chosen: string;
|
|
132
|
-
rejected: string;
|
|
133
|
-
}>;
|
|
134
|
-
/**
|
|
135
|
-
* Anthropic finetuning JSONL export — `{ system, user, assistant_chosen, assistant_rejected }`
|
|
136
|
-
* shape. Same caveat as TRL: prompt + outputs are content the caller has
|
|
137
|
-
* to map back from the run record / raw event log.
|
|
138
|
-
*/
|
|
139
|
-
declare function toAnthropicFormat(triples: PreferenceTriple[]): Array<{
|
|
140
|
-
scenarioId: string;
|
|
141
|
-
chosenRunId: string;
|
|
142
|
-
rejectedRunId: string;
|
|
143
|
-
margin: number;
|
|
144
|
-
}>;
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Process reward extraction — step-level credit assignment from trace spans.
|
|
148
|
-
*
|
|
149
|
-
* RL on long-horizon agents needs *step-level* rewards, not run-level
|
|
150
|
-
* ones. The classic credit-assignment problem (Sutton & Barto) requires
|
|
151
|
-
* knowing which sub-decisions in a trajectory contributed to the
|
|
152
|
-
* outcome. Modern systems (DeepSeek-R1, OpenAI o-series, Lightman et al.
|
|
153
|
-
* "Let's Verify Step by Step" 2023) train *process reward models* (PRMs)
|
|
154
|
-
* that score every step, then do RL with the PRM as the reward signal.
|
|
155
|
-
*
|
|
156
|
-
* This module extracts `StepReward[]` from trace spans — one per
|
|
157
|
-
* meaningful step — and ships:
|
|
158
|
-
*
|
|
159
|
-
* 1. `extractStepRewards(store, runId, opts)` — span → step-reward
|
|
160
|
-
* conversion using configurable per-span scorers (LLM judge over the
|
|
161
|
-
* span output, deterministic checkers, or a learned PRM).
|
|
162
|
-
* 2. `runwiseStepRewardSummary(stepRewards)` — aggregate the per-step
|
|
163
|
-
* signal into a credit-assignment-aware run-level score.
|
|
164
|
-
* 3. `prmTrainingPairs(stepRewards, options)` — produce the
|
|
165
|
-
* `(prefix, suffix_chosen, suffix_rejected)` triples that PRM
|
|
166
|
-
* training pipelines consume.
|
|
167
|
-
*
|
|
168
|
-
* What we ship: the *extraction* and *aggregation* infrastructure plus
|
|
169
|
-
* the data shape PRM training expects. We do NOT ship the actual PRM
|
|
170
|
-
* training (gradient descent over a transformer is out of scope for a
|
|
171
|
-
* TS package). The interface is the contract; downstream consumers wire
|
|
172
|
-
* their preferred trainer.
|
|
173
|
-
*
|
|
174
|
-
* Caveat the panel will land: this is descriptive credit assignment
|
|
175
|
-
* (which steps correlate with outcome), not causal credit assignment
|
|
176
|
-
* (which steps caused outcome). For causal claims you need
|
|
177
|
-
* counterfactual rollouts or a learned dynamics model. Future work; the
|
|
178
|
-
* descriptive version is what production PRM training actually uses.
|
|
179
|
-
*/
|
|
180
|
-
|
|
181
|
-
interface StepReward {
|
|
182
|
-
/** Trace span this reward attaches to. */
|
|
183
|
-
spanId: string;
|
|
184
|
-
runId: string;
|
|
185
|
-
/** Index in the trajectory (0-based, in started-at order). */
|
|
186
|
-
stepIndex: number;
|
|
187
|
-
/** Span kind (typically 'tool', 'llm', 'judge'). */
|
|
188
|
-
kind: Span['kind'];
|
|
189
|
-
/** Span name — for the consumer's downstream filtering. */
|
|
190
|
-
name: string;
|
|
191
|
-
/** Step-level reward in [0, 1]. */
|
|
192
|
-
reward: number;
|
|
193
|
-
/**
|
|
194
|
-
* Determinism class. Mirrors the verifiable-reward distinction:
|
|
195
|
-
* deterministic = test/compile/schema check; probabilistic = LLM judge.
|
|
196
|
-
*/
|
|
197
|
-
determinism: 'deterministic' | 'probabilistic';
|
|
198
|
-
/** Optional rationale / evidence — the trainer typically discards. */
|
|
199
|
-
rationale?: string;
|
|
200
|
-
/** Optional weight — how much this step contributes to credit assignment. */
|
|
201
|
-
weight?: number;
|
|
202
|
-
}
|
|
203
|
-
interface StepScorer {
|
|
204
|
-
/** Span kinds this scorer applies to. */
|
|
205
|
-
appliesTo: Span['kind'][];
|
|
206
|
-
/** Returns null to skip the span; returns a `StepReward` shape (without index/runId/spanId, which are filled in). */
|
|
207
|
-
score(span: Span): Promise<Omit<StepReward, 'spanId' | 'runId' | 'stepIndex'>> | null | undefined;
|
|
208
|
-
}
|
|
209
|
-
interface ExtractStepRewardsOptions {
|
|
210
|
-
/**
|
|
211
|
-
* Ordered list of scorers. Each span runs through scorers in order;
|
|
212
|
-
* the first non-null result wins. If no scorer applies, the span is
|
|
213
|
-
* skipped (not all spans are training-worthy).
|
|
214
|
-
*/
|
|
215
|
-
scorers: StepScorer[];
|
|
216
|
-
/** Optional filter — return null to drop the span entirely before scoring. */
|
|
217
|
-
preFilter?: (span: Span) => boolean;
|
|
218
|
-
}
|
|
219
|
-
declare function extractStepRewards(store: TraceStore, runId: string, opts: ExtractStepRewardsOptions): Promise<StepReward[]>;
|
|
220
|
-
interface RunwiseStepSummary {
|
|
221
|
-
runId: string;
|
|
222
|
-
totalSteps: number;
|
|
223
|
-
meanReward: number;
|
|
224
|
-
/** Sum-of-rewards (weighted by `weight ?? 1`). Use as the run-level proxy. */
|
|
225
|
-
sumWeightedReward: number;
|
|
226
|
-
/** Fraction of steps where reward < 0.5 — proxy for "where the policy was wrong." */
|
|
227
|
-
failureFraction: number;
|
|
228
|
-
/** Maximum drop in reward between consecutive steps — diagnoses a step where things went sideways. */
|
|
229
|
-
worstStepDelta: number;
|
|
230
|
-
worstStepIndex: number | null;
|
|
231
|
-
}
|
|
232
|
-
declare function runwiseStepRewardSummary(stepRewards: StepReward[]): RunwiseStepSummary;
|
|
233
|
-
interface PrmTrainingTriple {
|
|
234
|
-
/** Prefix run-id (or composite key) — the trajectory up to step k-1. */
|
|
235
|
-
prefixRunId: string;
|
|
236
|
-
prefixStepIndex: number;
|
|
237
|
-
/** The step that came next on a high-reward trajectory. */
|
|
238
|
-
chosenSpanId: string;
|
|
239
|
-
chosenReward: number;
|
|
240
|
-
/** A step from a divergent low-reward trajectory at the same prefix length. */
|
|
241
|
-
rejectedSpanId: string;
|
|
242
|
-
rejectedReward: number;
|
|
243
|
-
/** The prefix run came from this run; the rejected step came from `rejectedRunId`. */
|
|
244
|
-
rejectedRunId: string;
|
|
245
|
-
marginScore: number;
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Build PRM training triples. The shape: pair runs that share an early
|
|
249
|
-
* prefix (same scenario, same first N steps) and diverge later — at the
|
|
250
|
-
* point of divergence, the high-reward run's next step is `chosen`, the
|
|
251
|
-
* low-reward run's next step is `rejected`. This is the canonical PRM
|
|
252
|
-
* training data shape from Lightman et al. and DeepSeek-R1 process
|
|
253
|
-
* supervision.
|
|
254
|
-
*
|
|
255
|
-
* Implementation note: we don't have a way to detect "same prefix" in
|
|
256
|
-
* the general agent setting (token-level prefixes require hashing model
|
|
257
|
-
* outputs). The current heuristic groups by `(scenarioId, prefixSpanName
|
|
258
|
-
* sequence)` — runs are paired when their first K span names match. For
|
|
259
|
-
* production use this should be replaced with a proper trajectory-prefix
|
|
260
|
-
* hash; the heuristic is good enough for early-stage scaffolding.
|
|
261
|
-
*/
|
|
262
|
-
declare function prmTrainingPairs(stepRewardsByRun: Map<string, StepReward[]>, opts?: {
|
|
263
|
-
minMargin?: number;
|
|
264
|
-
minPrefixLength?: number;
|
|
265
|
-
}): PrmTrainingTriple[];
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Trainer-format exporters.
|
|
269
|
-
*
|
|
270
|
-
* agent-eval produces canonical artifacts (`RunRecord[]`, `PreferenceTriple[]`,
|
|
271
|
-
* `StepReward[]`, `PrmTrainingTriple[]`). RL training pipelines consume
|
|
272
|
-
* different shapes — Hugging Face TRL, Prime Intellect's prime-rl, OpenAI
|
|
273
|
-
* fine-tuning, Anthropic finetuning, OpenRLHF, verl. Each has its own
|
|
274
|
-
* JSONL conventions. Rather than ship N adapters, this module ships the
|
|
275
|
-
* canonical formats most production pipelines accept and ergonomic helpers
|
|
276
|
-
* for the rest.
|
|
277
|
-
*
|
|
278
|
-
* Shapes:
|
|
279
|
-
* - **DPO / IPO / KTO** — `{prompt, chosen, rejected}` JSONL. Consumed
|
|
280
|
-
* by HuggingFace TRL, prime-rl's offline DPO, OpenRLHF.
|
|
281
|
-
* - **GRPO offline** — `{prompt, completions[], rewards[]}` JSONL.
|
|
282
|
-
* Consumed by prime-rl GRPO, verl, OpenRLHF.
|
|
283
|
-
* - **SFT** — `{messages[]}` JSONL with chosen completion as the final
|
|
284
|
-
* assistant turn. Consumed by HF SFT trainers, OpenAI fine-tuning,
|
|
285
|
-
* Anthropic finetuning.
|
|
286
|
-
* - **PRM** — `{prompt, prefix_steps[], chosen_step, rejected_step}` JSONL.
|
|
287
|
-
* Consumed by Lightman-style PRM trainers and prime-rl's PRM mode.
|
|
288
|
-
*
|
|
289
|
-
* Why ship this in agent-eval rather than a separate adapter package: the
|
|
290
|
-
* canonical artifacts (`RunRecord[]`, `PreferenceTriple[]`, etc.) are
|
|
291
|
-
* agent-eval's contract; without first-party exporters consumers reverse-
|
|
292
|
-
* engineer the mapping every release. The exporters codify it.
|
|
293
|
-
*
|
|
294
|
-
* The exporters take callbacks for any field that isn't on the canonical
|
|
295
|
-
* artifact (specifically: prompt + completion text, since the package
|
|
296
|
-
* stores only their hashes by design — full text is the consumer's
|
|
297
|
-
* trace store / raw event log).
|
|
298
|
-
*/
|
|
299
|
-
|
|
300
|
-
interface DpoLookups {
|
|
301
|
-
/** Resolve the prompt text for a run (typically from a trace store / raw event sink). */
|
|
302
|
-
promptOf: (runId: string) => string | Promise<string>;
|
|
303
|
-
/** Resolve the assistant completion text for a run. */
|
|
304
|
-
completionOf: (runId: string) => string | Promise<string>;
|
|
305
|
-
}
|
|
306
|
-
interface DpoExportRow {
|
|
307
|
-
prompt: string;
|
|
308
|
-
chosen: string;
|
|
309
|
-
rejected: string;
|
|
310
|
-
/** Carried-through margin. Some KTO / IPO variants use this. */
|
|
311
|
-
margin?: number;
|
|
312
|
-
/** Free-form metadata for downstream filtering / sharding. */
|
|
313
|
-
meta?: Record<string, unknown>;
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Convert preference triples to TRL-compatible DPO rows. The shape
|
|
317
|
-
* `{prompt, chosen, rejected}` is the canonical HuggingFace DPODataset
|
|
318
|
-
* entry; every major DPO trainer accepts it.
|
|
319
|
-
*/
|
|
320
|
-
declare function toDpoRows(triples: PreferenceTriple[], lookups: DpoLookups): Promise<DpoExportRow[]>;
|
|
321
|
-
/** Serialize DPO rows as JSONL. One line per row. */
|
|
322
|
-
declare function toDpoJsonl(rows: DpoExportRow[]): string;
|
|
323
|
-
interface GrpoLookups {
|
|
324
|
-
promptOf: (runId: string) => string | Promise<string>;
|
|
325
|
-
completionOf: (runId: string) => string | Promise<string>;
|
|
326
|
-
/** Optional: derive a custom reward from the run. Defaults to score. */
|
|
327
|
-
rewardOf?: (run: RunRecord) => number | null;
|
|
328
|
-
}
|
|
329
|
-
interface GrpoExportRow {
|
|
330
|
-
prompt: string;
|
|
331
|
-
completions: string[];
|
|
332
|
-
rewards: number[];
|
|
333
|
-
/** runIds in the same order as `completions[]` for traceability. */
|
|
334
|
-
runIds: string[];
|
|
335
|
-
meta?: Record<string, unknown>;
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Convert RunRecord[] grouped by `(scenarioId)` into GRPO offline rows —
|
|
339
|
-
* one row per scenario, with one completion per run on that scenario.
|
|
340
|
-
*
|
|
341
|
-
* GRPO (Shao et al. 2024 / DeepSeek-R1) trains on relative advantages
|
|
342
|
-
* within a group of completions for the same prompt; this is the
|
|
343
|
-
* canonical input format.
|
|
344
|
-
*/
|
|
345
|
-
declare function toGrpoRows(runs: RunRecord[], lookups: GrpoLookups): Promise<GrpoExportRow[]>;
|
|
346
|
-
declare function toGrpoJsonl(rows: GrpoExportRow[]): string;
|
|
347
|
-
interface SftLookups {
|
|
348
|
-
promptOf: (runId: string) => string | Promise<string>;
|
|
349
|
-
completionOf: (runId: string) => string | Promise<string>;
|
|
350
|
-
/** Optional system message. Default omits. */
|
|
351
|
-
systemOf?: (run: RunRecord) => string | null | undefined;
|
|
352
|
-
/** Filter — return false to skip the run (e.g., low score, failed cases). */
|
|
353
|
-
include?: (run: RunRecord) => boolean;
|
|
354
|
-
}
|
|
355
|
-
interface SftExportRow {
|
|
356
|
-
messages: Array<{
|
|
357
|
-
role: 'system' | 'user' | 'assistant';
|
|
358
|
-
content: string;
|
|
359
|
-
}>;
|
|
360
|
-
meta?: Record<string, unknown>;
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* Convert RunRecord[] into Hugging Face / OpenAI / Anthropic-style
|
|
364
|
-
* conversational SFT rows. By default every record becomes one row;
|
|
365
|
-
* pass `include` to filter (e.g., keep only `score >= 0.8` for
|
|
366
|
-
* rejection-sampling SFT).
|
|
367
|
-
*/
|
|
368
|
-
declare function toSftRows(runs: RunRecord[], lookups: SftLookups): Promise<SftExportRow[]>;
|
|
369
|
-
declare function toSftJsonl(rows: SftExportRow[]): string;
|
|
370
|
-
interface PrmLookups {
|
|
371
|
-
/** Resolve the prompt text for a run. */
|
|
372
|
-
promptOf: (runId: string) => string | Promise<string>;
|
|
373
|
-
/** Resolve the trajectory step text for a (runId, spanId) pair. */
|
|
374
|
-
stepTextOf: (runId: string, spanId: string) => string | Promise<string>;
|
|
375
|
-
/** Optional: sequence of prefix span ids leading up to the divergence. */
|
|
376
|
-
prefixOf?: (runId: string, prefixStepIndex: number) => string[] | Promise<string[]>;
|
|
377
|
-
}
|
|
378
|
-
interface PrmExportRow {
|
|
379
|
-
prompt: string;
|
|
380
|
-
/** Span ids for the steps before divergence — caller resolves text via `stepTextOf`. */
|
|
381
|
-
prefixSpanIds: string[];
|
|
382
|
-
prefixStepText: string[];
|
|
383
|
-
chosenStep: string;
|
|
384
|
-
rejectedStep: string;
|
|
385
|
-
chosenReward: number;
|
|
386
|
-
rejectedReward: number;
|
|
387
|
-
marginScore: number;
|
|
388
|
-
meta?: Record<string, unknown>;
|
|
389
|
-
}
|
|
390
|
-
/**
|
|
391
|
-
* Convert PRM training triples to JSONL rows. Caller's `stepTextOf`
|
|
392
|
-
* callback resolves span text from the consumer's trace store.
|
|
393
|
-
*/
|
|
394
|
-
declare function toPrmRows(triples: PrmTrainingTriple[], lookups: PrmLookups): Promise<PrmExportRow[]>;
|
|
395
|
-
declare function toPrmJsonl(rows: PrmExportRow[]): string;
|
|
396
|
-
interface StepRewardJsonlRow {
|
|
397
|
-
runId: string;
|
|
398
|
-
spanId: string;
|
|
399
|
-
stepIndex: number;
|
|
400
|
-
reward: number;
|
|
401
|
-
determinism: 'deterministic' | 'probabilistic';
|
|
402
|
-
weight: number;
|
|
403
|
-
}
|
|
404
|
-
declare function stepRewardsToJsonl(stepRewards: StepReward[]): string;
|
|
405
|
-
|
|
406
|
-
/**
|
|
407
|
-
* RL dataset packaging + datasheet — the publishable, sellable bundle.
|
|
408
|
-
*
|
|
409
|
-
* The format exporters (`toGrpoRows` / `toSftRows` / `toDpoRows`) already
|
|
410
|
-
* produce trainer-ready shapes (prime-rl GRPO, TRL DPO, conversational SFT).
|
|
411
|
-
* What turns that into a dataset someone can PUBLISH or BUY is the provenance
|
|
412
|
-
* + a datasheet: which models produced it, which prompt/agent versions, how the
|
|
413
|
-
* reward was derived (deterministic verifiable vs probabilistic judge — the
|
|
414
|
-
* credibility axis a buyer checks first), the split discipline, the reward
|
|
415
|
-
* distribution, the quality gates, the license, and the intended/out-of-scope
|
|
416
|
-
* uses. This module computes those facts from the `RunRecord[]` and renders a
|
|
417
|
-
* "Datasheet for Datasets" (Gebru et al. 2018) card alongside the format files.
|
|
418
|
-
*
|
|
419
|
-
* It composes the existing `rl/exporters` — it does not reimplement any trainer
|
|
420
|
-
* format. The renderers token-identity step (DeepSeek/Kimi/Qwen tokenization
|
|
421
|
-
* with per-token loss masks) is a downstream Python stage that consumes the
|
|
422
|
-
* `messages`/`completions` this bundle emits.
|
|
423
|
-
*/
|
|
424
|
-
|
|
425
|
-
type RewardKind = 'deterministic' | 'probabilistic' | 'mixed';
|
|
426
|
-
type DatasetFormat = 'grpo' | 'sft' | 'dpo';
|
|
427
|
-
/** Caller-declared context — the qualitative half of the datasheet that can't
|
|
428
|
-
* be computed from records. */
|
|
429
|
-
interface RlDatasetConfig {
|
|
430
|
-
name: string;
|
|
431
|
-
version: string;
|
|
432
|
-
/** Product/task domain, e.g. 'legal-m&a', 'tax-1040'. */
|
|
433
|
-
domain: string;
|
|
434
|
-
/** SPDX id or a named commercial license. Required — an unlicensed dataset
|
|
435
|
-
* cannot be published or sold. */
|
|
436
|
-
license: string;
|
|
437
|
-
/** How the reward was produced. `kind: 'deterministic'` (a test/schema/XPath
|
|
438
|
-
* decided it) is the credibility signal; 'probabilistic' = LLM-judge. */
|
|
439
|
-
reward: {
|
|
440
|
-
kind: RewardKind;
|
|
441
|
-
source: string;
|
|
442
|
-
description: string;
|
|
443
|
-
};
|
|
444
|
-
intendedUse: string;
|
|
445
|
-
outOfScope: string;
|
|
446
|
-
limitations: string;
|
|
447
|
-
/** ISO timestamp — passed in (the substrate forbids Date.now()). */
|
|
448
|
-
createdAtIso: string;
|
|
449
|
-
/** Default: ['grpo', 'sft']. */
|
|
450
|
-
formats?: DatasetFormat[];
|
|
451
|
-
/** Quality gates already run, recorded on the card for the buyer. */
|
|
452
|
-
qualityGates?: {
|
|
453
|
-
contaminationProbe?: 'passed' | 'failed' | 'not-run';
|
|
454
|
-
dedup?: boolean;
|
|
455
|
-
verifiableRewardFilter?: boolean;
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
interface RewardStats {
|
|
459
|
-
n: number;
|
|
460
|
-
mean: number;
|
|
461
|
-
median: number;
|
|
462
|
-
min: number;
|
|
463
|
-
max: number;
|
|
464
|
-
std: number;
|
|
465
|
-
}
|
|
466
|
-
interface RlDatasetStats {
|
|
467
|
-
records: number;
|
|
468
|
-
/** Record count per split — a publishable dataset must declare its holdout. */
|
|
469
|
-
splits: Record<RunSplitTag, number>;
|
|
470
|
-
reward: RewardStats;
|
|
471
|
-
/** Distinct snapshot-pinned models that produced the trajectories. */
|
|
472
|
-
models: string[];
|
|
473
|
-
/** Distinct effective-prompt hashes (the agent profile/prompt versions). */
|
|
474
|
-
promptHashes: string[];
|
|
475
|
-
commitShas: string[];
|
|
476
|
-
totalTokens: {
|
|
477
|
-
input: number;
|
|
478
|
-
output: number;
|
|
479
|
-
};
|
|
480
|
-
totalCostUsd: number;
|
|
481
|
-
}
|
|
482
|
-
interface RlDatasetManifest extends RlDatasetConfig {
|
|
483
|
-
formats: DatasetFormat[];
|
|
484
|
-
rowCounts: Partial<Record<DatasetFormat, number>>;
|
|
485
|
-
stats: RlDatasetStats;
|
|
486
|
-
}
|
|
487
|
-
interface RlDatasetBundle {
|
|
488
|
-
manifest: RlDatasetManifest;
|
|
489
|
-
/** Relative filename -> contents. Write these to a directory to publish. */
|
|
490
|
-
files: Record<string, string>;
|
|
491
|
-
}
|
|
492
|
-
/**
|
|
493
|
-
* Package graded `RunRecord[]` into a publishable RL dataset bundle: the
|
|
494
|
-
* trainer-format JSONL files + a manifest + a datasheet. DPO requires
|
|
495
|
-
* pre-extracted preference triples (pass `preferences`); GRPO/SFT derive from
|
|
496
|
-
* the records directly via the supplied lookups. Throws on an empty corpus —
|
|
497
|
-
* an empty dataset must never be published.
|
|
498
|
-
*/
|
|
499
|
-
declare function buildRlDataset(records: RunRecord[], lookups: GrpoLookups & SftLookups, config: RlDatasetConfig, preferences?: {
|
|
500
|
-
triples: PreferenceTriple[];
|
|
501
|
-
lookups: DpoLookups;
|
|
502
|
-
}): Promise<RlDatasetBundle>;
|
|
503
|
-
/** Render the "Datasheet for Datasets" card — the artifact a buyer reads. */
|
|
504
|
-
declare function datasheetToMarkdown(m: RlDatasetManifest): string;
|
|
505
|
-
|
|
506
|
-
/**
|
|
507
|
-
* RL corpus — the durable, append-only accumulation of graded RunRecords that
|
|
508
|
-
* every eval run deposits BY DEFAULT.
|
|
509
|
-
*
|
|
510
|
-
* The dataset is the free exhaust of the normal eval process: we run evals
|
|
511
|
-
* constantly to get an agent production-ready, and those runs already produce
|
|
512
|
-
* graded trajectories. Instead of writing them to an ephemeral run dir and
|
|
513
|
-
* throwing them away, `appendToCorpus` accumulates them into a durable corpus;
|
|
514
|
-
* `buildDatasetFromCorpus` later harvests the whole corpus into a publishable
|
|
515
|
-
* bundle. No separate data-collection campaign — the data accrues from work we
|
|
516
|
-
* do anyway. This is the "best things for free by our process" layer.
|
|
517
|
-
*
|
|
518
|
-
* Trajectory text rides on the record as top-level `prompt` / `completion`
|
|
519
|
-
* (what the eval harnesses capture; the RunRecord validator ignores the extra
|
|
520
|
-
* keys). The harvest reads them directly — no trace store round-trip needed.
|
|
521
|
-
*/
|
|
522
|
-
|
|
523
|
-
/** A corpus record is a RunRecord carrying the trajectory text the harness
|
|
524
|
-
* captured. `prompt`/`completion` are top-level (the validator ignores extras). */
|
|
525
|
-
type CorpusRecord = RunRecord & {
|
|
526
|
-
prompt?: string;
|
|
527
|
-
completion?: string;
|
|
528
|
-
};
|
|
529
|
-
interface CorpusAppendResult {
|
|
530
|
-
appended: number;
|
|
531
|
-
/** Skipped because a record with the same runId was already in the corpus
|
|
532
|
-
* (idempotent appends — NOT re-run collapsing; re-runs get fresh runIds). */
|
|
533
|
-
skipped: number;
|
|
534
|
-
total: number;
|
|
535
|
-
}
|
|
536
|
-
/**
|
|
537
|
-
* Append graded records to the corpus (append-only JSONL). Deduplicates by
|
|
538
|
-
* `runId` against what's already on disk so re-running the same harness is
|
|
539
|
-
* idempotent. Creates the file and parent dir. This is the call every eval
|
|
540
|
-
* harness makes by default after producing its records.
|
|
541
|
-
*/
|
|
542
|
-
declare function appendToCorpus(records: CorpusRecord[], corpusPath: string): CorpusAppendResult;
|
|
543
|
-
/** Read the full corpus. Returns [] if the corpus does not exist yet. */
|
|
544
|
-
declare function readCorpus(corpusPath: string): CorpusRecord[];
|
|
545
|
-
interface HarvestOptions {
|
|
546
|
-
/** Keep only records scoring >= this (rejection-sampling for SFT). */
|
|
547
|
-
minScore?: number;
|
|
548
|
-
/** Keep only these splits (e.g. ['holdout'] for an eval-only dataset). */
|
|
549
|
-
splits?: RunRecord['splitTag'][];
|
|
550
|
-
}
|
|
551
|
-
/**
|
|
552
|
-
* Harvest the accumulated corpus into a publishable RL dataset bundle. Reads
|
|
553
|
-
* trajectory text from each record's top-level `prompt`/`completion`; records
|
|
554
|
-
* missing either are excluded (a graded score with no trajectory can't train).
|
|
555
|
-
* Optionally filters by score / split. Throws (via buildRlDataset) if nothing
|
|
556
|
-
* survives — an empty dataset must never be published.
|
|
557
|
-
*/
|
|
558
|
-
declare function buildDatasetFromCorpus(corpusPath: string, config: RlDatasetConfig, opts?: HarvestOptions): Promise<RlDatasetBundle>;
|
|
559
|
-
|
|
560
|
-
export { prmTrainingPairs as A, readCorpus as B, type CorpusRecord as C, type DpoExportRow as D, type ExtractPreferencesOptions as E, runwiseStepRewardSummary as F, type GrpoExportRow as G, type HarvestOptions as H, stepRewardsToJsonl as I, toAnthropicFormat as J, toDpoJsonl as K, toDpoRows as L, toGrpoJsonl as M, toGrpoRows as N, toPrmJsonl as O, type PreferenceExtractionReport as P, toPrmRows as Q, type RewardKind as R, type SftExportRow as S, toSftJsonl as T, toSftRows as U, toTRLFormat as V, type DpoLookups as a, type GrpoLookups as b, type SftLookups as c, type CorpusAppendResult as d, type DatasetFormat as e, type ExtractStepRewardsOptions as f, type PreferenceStrategy as g, type PreferenceTriple as h, type PrmExportRow as i, type PrmLookups as j, type PrmTrainingTriple as k, type RewardStats as l, type RlDatasetBundle as m, type RlDatasetConfig as n, type RlDatasetManifest as o, type RlDatasetStats as p, type RunwiseStepSummary as q, type StepReward as r, type StepRewardJsonlRow as s, type StepScorer as t, appendToCorpus as u, buildDatasetFromCorpus as v, buildRlDataset as w, datasheetToMarkdown as x, extractPreferences as y, extractStepRewards as z };
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { T as TraceEmitter } from './emitter-C2rqGH_l.js';
|
|
2
|
-
import { T as TraceStore } from './store-BcFXE6LG.js';
|
|
3
|
-
import { T as Trajectory, a as TrajectoryStep } from './trajectory-2TkpSEVh.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Counterfactual replay — "what would have happened if we'd changed
|
|
7
|
-
* exactly one thing at turn N?"
|
|
8
|
-
*
|
|
9
|
-
* The framework does NOT drive the agent — it sets up the replay
|
|
10
|
-
* context (prior spans, prior state, mutation spec) and records the
|
|
11
|
-
* resulting divergence. Consumers supply an `executeFrom(ctx)` callback
|
|
12
|
-
* that runs their agent starting from turn N with the mutation applied.
|
|
13
|
-
*
|
|
14
|
-
* Counterfactual runs are recorded as a new Run with `layer='meta'` and
|
|
15
|
-
* `parentRunId = originalRunId`, so downstream diff + correlation
|
|
16
|
-
* pipelines see them natively.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
type CounterfactualMutation = {
|
|
20
|
-
kind: 'swap-model';
|
|
21
|
-
at: number;
|
|
22
|
-
newModel: string;
|
|
23
|
-
} | {
|
|
24
|
-
kind: 'swap-tool-result';
|
|
25
|
-
at: number;
|
|
26
|
-
newResult: unknown;
|
|
27
|
-
} | {
|
|
28
|
-
kind: 'truncate-after';
|
|
29
|
-
at: number;
|
|
30
|
-
} | {
|
|
31
|
-
kind: 'inject-system-message';
|
|
32
|
-
at: number;
|
|
33
|
-
content: string;
|
|
34
|
-
} | {
|
|
35
|
-
kind: 'custom';
|
|
36
|
-
at: number;
|
|
37
|
-
describe: string;
|
|
38
|
-
apply: (step: TrajectoryStep) => TrajectoryStep;
|
|
39
|
-
};
|
|
40
|
-
interface CounterfactualContext {
|
|
41
|
-
originalRunId: string;
|
|
42
|
-
originalTrajectory: Trajectory;
|
|
43
|
-
/** Steps up to (but not including) the mutation point — the prefix the
|
|
44
|
-
* replayed agent inherits as its prior conversation/tool history. */
|
|
45
|
-
prefix: TrajectoryStep[];
|
|
46
|
-
mutation: CounterfactualMutation;
|
|
47
|
-
/** Pre-applied mutation on the step at `mutation.at`. Consumers use this
|
|
48
|
-
* as the FIRST step the replayed agent emits (they decide whether to
|
|
49
|
-
* re-emit it or continue from there). */
|
|
50
|
-
mutatedStep: TrajectoryStep;
|
|
51
|
-
}
|
|
52
|
-
interface CounterfactualResult {
|
|
53
|
-
counterfactualRunId: string;
|
|
54
|
-
originalRunId: string;
|
|
55
|
-
mutation: CounterfactualMutation;
|
|
56
|
-
/** Structured delta summary — caller can extend via scoring. */
|
|
57
|
-
delta: {
|
|
58
|
-
originalOutcomeScore: number | null;
|
|
59
|
-
counterfactualOutcomeScore: number | null;
|
|
60
|
-
deltaScore: number | null;
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
interface CounterfactualRunner {
|
|
64
|
-
/**
|
|
65
|
-
* Execute the agent from `ctx.prefix` with the mutation applied.
|
|
66
|
-
* MUST emit spans into the provided emitter so they become part of
|
|
67
|
-
* the counterfactual run. MUST call emitter.endRun() with a verdict.
|
|
68
|
-
*/
|
|
69
|
-
executeFrom: (ctx: CounterfactualContext, emitter: TraceEmitter) => Promise<void>;
|
|
70
|
-
}
|
|
71
|
-
declare function runCounterfactual(store: TraceStore, originalRunId: string, mutation: CounterfactualMutation, runner: CounterfactualRunner): Promise<CounterfactualResult>;
|
|
72
|
-
/**
|
|
73
|
-
* Aggregate a batch of counterfactuals into a simple attribution table:
|
|
74
|
-
* which mutation kinds move outcomes most? (Useful when you run a grid
|
|
75
|
-
* over the same trajectory — swap-model at every llm span, swap-tool
|
|
76
|
-
* at every tool span — and want a ranked summary.)
|
|
77
|
-
*/
|
|
78
|
-
declare function attributeCounterfactuals(results: CounterfactualResult[]): Array<{
|
|
79
|
-
mutationKind: CounterfactualMutation['kind'];
|
|
80
|
-
n: number;
|
|
81
|
-
meanAbsDelta: number;
|
|
82
|
-
meanSignedDelta: number;
|
|
83
|
-
}>;
|
|
84
|
-
|
|
85
|
-
export { type CounterfactualMutation as C, attributeCounterfactuals as a, type CounterfactualRunner as b, type CounterfactualContext as c, type CounterfactualResult as d, runCounterfactual as r };
|