@tangle-network/agent-eval 0.77.0 → 0.80.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/README.md +50 -19
- package/dist/adapters/http.d.ts +2 -2
- package/dist/adapters/langchain.d.ts +2 -2
- package/dist/adapters/otel.d.ts +4 -4
- package/dist/{agent-profile-DYRboYWu.d.ts → agent-profile-aSEaJ9Pl.d.ts} +1 -1
- package/dist/analyst/index.d.ts +42 -8
- package/dist/analyst/index.js +32 -2
- package/dist/analyst/index.js.map +1 -1
- package/dist/authenticity/index.d.ts +54 -1
- package/dist/authenticity/index.js +88 -1
- package/dist/authenticity/index.js.map +1 -1
- package/dist/belief-state/index.d.ts +188 -0
- package/dist/belief-state/index.js +486 -0
- package/dist/belief-state/index.js.map +1 -0
- package/dist/benchmarks/index.d.ts +2 -2
- package/dist/calibration-Cpr3WaX3.d.ts +101 -0
- package/dist/campaign/index.d.ts +11 -11
- package/dist/campaign/index.js +4 -4
- package/dist/chunk-4DIJWVUT.js +131 -0
- package/dist/chunk-4DIJWVUT.js.map +1 -0
- package/dist/{chunk-7W4SM7FD.js → chunk-5LVWPNS5.js} +91 -91
- package/dist/chunk-5LVWPNS5.js.map +1 -0
- package/dist/{chunk-WYIHD6EB.js → chunk-CF67I6QY.js} +1 -1
- package/dist/chunk-CF67I6QY.js.map +1 -0
- package/dist/{chunk-XPILG2CA.js → chunk-GXHLRXDI.js} +2 -2
- package/dist/{chunk-F3SRAAZO.js → chunk-KWRRMR3J.js} +15 -1
- package/dist/chunk-KWRRMR3J.js.map +1 -0
- package/dist/chunk-NPCTHQIO.js +91 -0
- package/dist/chunk-NPCTHQIO.js.map +1 -0
- package/dist/{chunk-JYE3WOTE.js → chunk-RPLZ4OIB.js} +10 -1
- package/dist/chunk-RPLZ4OIB.js.map +1 -0
- package/dist/{chunk-6EKXFFGQ.js → chunk-RTWFUK6A.js} +2 -2
- package/dist/{chunk-XGNCBAVZ.js → chunk-XQL22JDG.js} +2 -2
- package/dist/{chunk-GJJNJVIR.js → chunk-XXNIODOM.js} +2 -2
- package/dist/contract/index.d.ts +128 -15
- package/dist/contract/index.js +118 -2
- package/dist/contract/index.js.map +1 -1
- package/dist/{control-BgA6BYTm.d.ts → control-CehLtoET.d.ts} +1 -1
- package/dist/control.d.ts +2 -2
- package/dist/control.js +2 -2
- package/dist/governance/index.d.ts +1 -1
- package/dist/hosted/index.d.ts +4 -4
- package/dist/{index-DsnOpCO6.d.ts → index-B1RKber3.d.ts} +1 -1
- package/dist/index.d.ts +127 -26
- package/dist/index.js +32 -7
- package/dist/index.js.map +1 -1
- package/dist/{insight-report-Df3lxYXM.d.ts → insight-report-dlpEzQDi.d.ts} +1 -1
- package/dist/{kind-factory-DW9XWPvM.d.ts → kind-factory-DqV2t1Xk.d.ts} +1 -1
- package/dist/meta-eval/index.d.ts +6 -99
- package/dist/meta-eval/index.js +7 -76
- package/dist/meta-eval/index.js.map +1 -1
- package/dist/off-policy-DiwuKKg7.d.ts +132 -0
- package/dist/openapi.json +1 -1
- package/dist/{outcome-store-D6KWmYvj.d.ts → outcome-store-rnXLEqSn.d.ts} +1 -1
- package/dist/{provenance-B-TFszPW.d.ts → provenance-jG-Gngg8.d.ts} +3 -3
- package/dist/{registry-DuVYiTvw.d.ts → registry-BK0Zee01.d.ts} +1 -1
- package/dist/{release-report-CN8hJlhk.d.ts → release-report-CXXZlR8g.d.ts} +2 -2
- package/dist/reporting.d.ts +5 -5
- package/dist/{researcher-C_KJyIGg.d.ts → researcher-rInLj9De.d.ts} +2 -2
- package/dist/rl.d.ts +10 -140
- package/dist/rl.js +8 -122
- package/dist/rl.js.map +1 -1
- package/dist/{rubric-predictive-validity-D_4BSXGV.d.ts → rubric-predictive-validity-CLPuwiUw.d.ts} +2 -2
- package/dist/{run-improvement-loop-BqYH2vCR.d.ts → run-improvement-loop-BAl_aVOZ.d.ts} +2 -4
- package/dist/{run-record-BgTFzO2r.d.ts → run-record-sItO5ftF.d.ts} +11 -0
- package/dist/{semantic-concept-judge-CV9Wlx4t.d.ts → semantic-concept-judge-qXEUV2w7.d.ts} +3 -3
- package/dist/{summary-report-ByiOUrHj.d.ts → summary-report-BTaXq1TS.d.ts} +1 -1
- package/dist/traces.d.ts +1 -1
- package/dist/traces.js +2 -2
- package/dist/{types-Bba0vl1V.d.ts → types-4mm2msnR.d.ts} +12 -4
- package/dist/{types-CRD68aH7.d.ts → types-DRvV0zRo.d.ts} +10 -1
- package/dist/workflow/index.d.ts +4 -4
- package/dist/workflow/index.js +1 -1
- package/docs/auto-research-loop-end-to-end.md +1 -1
- package/docs/feature-guide.md +4 -4
- package/docs/multi-shot-optimization.md +61 -115
- package/docs/product-eval-adoption.md +1 -1
- package/docs/research/belief-state-agent-eval-roadmap.md +558 -0
- package/docs/research/research-roadmap.md +1 -0
- package/docs/three-package-architecture.md +1 -1
- package/docs/trace-analysis.md +19 -0
- package/package.json +7 -2
- package/dist/chunk-7W4SM7FD.js.map +0 -1
- package/dist/chunk-F3SRAAZO.js.map +0 -1
- package/dist/chunk-JYE3WOTE.js.map +0 -1
- package/dist/chunk-WYIHD6EB.js.map +0 -1
- /package/dist/{chunk-XPILG2CA.js.map → chunk-GXHLRXDI.js.map} +0 -0
- /package/dist/{chunk-6EKXFFGQ.js.map → chunk-RTWFUK6A.js.map} +0 -0
- /package/dist/{chunk-XGNCBAVZ.js.map → chunk-XQL22JDG.js.map} +0 -0
- /package/dist/{chunk-GJJNJVIR.js.map → chunk-XXNIODOM.js.map} +0 -0
package/dist/campaign/index.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { A as AnalyzeTracesOptions, a as AnalyzeTracesInput, b as AnalyzeTracesResult } from '../analyst-t7zZS3TV.js';
|
|
2
|
-
import { S as Scenario, M as MutableSurface, b as DispatchContext, a as JudgeConfig, I as ImprovementDriver, q as ProposeContext, J as JudgeScore, L as LabeledScenarioStore, r as LabeledScenarioWrite, s as LabeledScenarioSampleArgs, t as LabeledScenarioRecord, u as LabelTrust, v as LabeledScenarioSource,
|
|
3
|
-
export { C as CampaignAggregates,
|
|
4
|
-
import { a as RunCampaignOptions, b as RunImprovementLoopOptions, C as CampaignStorage } from '../run-improvement-loop-
|
|
5
|
-
export { d as GepaDriverConstraints, G as GepaDriverOptions, O as OpenAutoPrOptions, e as OpenAutoPrResult, R as RunImprovementLoopResult, h as RunOptimizationOptions, j as RunOptimizationResult, k as countSentenceEdits, l as defaultRenderDiff, m as extractH2Sections, f as fsCampaignStorage, g as gepaDriver, i as inMemoryCampaignStorage, o as openAutoPr, r as runCampaign, c as runImprovementLoop, n as runOptimization, s as surfaceHash } from '../run-improvement-loop-
|
|
6
|
-
export { A as AxisEvidence, a as AxisVerdict, B as BuildEvidenceVectorOptions, k as BuildLoopProvenanceArgs, D as DefaultProductionGateOptions, l as EmitLoopProvenanceArgs, m as EmitLoopProvenanceResult, E as EvidenceVector, b as EvolutionaryDriverOptions, H as HeldOutGateOptions, n as LoopProvenanceBackend, o as LoopProvenanceCandidate, L as LoopProvenanceRecord, O as ObjectiveSource, P as ParetoSignificanceGateOptions, c as PromotionObjective, d as PromotionPolicy, R as RunEvalOptions, e as buildEvidenceVector, q as buildLoopProvenanceRecord, f as composeGate, g as defaultProductionGate, s as emitLoopProvenance, h as evolutionaryDriver, i as heldOutGate, t as loopProvenanceSpans, p as paretoPolicy, j as paretoSignificanceGate, u as provenanceRecordPath, v as provenanceSpansPath, r as runEval, w as surfaceContentHash } from '../provenance-
|
|
2
|
+
import { S as Scenario, M as MutableSurface, b as DispatchContext, a as JudgeConfig, I as ImprovementDriver, q as ProposeContext, J as JudgeScore, L as LabeledScenarioStore, r as LabeledScenarioWrite, s as LabeledScenarioSampleArgs, t as LabeledScenarioRecord, u as LabelTrust, v as LabeledScenarioSource, g as CampaignResult, i as CodeSurface } from '../types-4mm2msnR.js';
|
|
3
|
+
export { C as CampaignAggregates, d as CampaignArtifactWriter, e as CampaignCellResult, f as CampaignCostMeter, w as CampaignTokenUsage, h as CampaignTraceWriter, D as DispatchFn, G as Gate, j as GateContext, c as GateDecision, k as GateResult, l as GenerationCandidate, m as GenerationRecord, x as JudgeAggregate, n as JudgeDimension, o as Mutator, O as OptimizerConfig, P as ParetoParent, y as ProposedCandidate, R as RedactionStatus, z as ScenarioAggregate, p as SessionScript, T as TraceSpan, A as isProposedCandidate, B as labelTrustRank } from '../types-4mm2msnR.js';
|
|
4
|
+
import { a as RunCampaignOptions, b as RunImprovementLoopOptions, C as CampaignStorage } from '../run-improvement-loop-BAl_aVOZ.js';
|
|
5
|
+
export { d as GepaDriverConstraints, G as GepaDriverOptions, O as OpenAutoPrOptions, e as OpenAutoPrResult, R as RunImprovementLoopResult, h as RunOptimizationOptions, j as RunOptimizationResult, k as countSentenceEdits, l as defaultRenderDiff, m as extractH2Sections, f as fsCampaignStorage, g as gepaDriver, i as inMemoryCampaignStorage, o as openAutoPr, r as runCampaign, c as runImprovementLoop, n as runOptimization, s as surfaceHash } from '../run-improvement-loop-BAl_aVOZ.js';
|
|
6
|
+
export { A as AxisEvidence, a as AxisVerdict, B as BuildEvidenceVectorOptions, k as BuildLoopProvenanceArgs, D as DefaultProductionGateOptions, l as EmitLoopProvenanceArgs, m as EmitLoopProvenanceResult, E as EvidenceVector, b as EvolutionaryDriverOptions, H as HeldOutGateOptions, n as LoopProvenanceBackend, o as LoopProvenanceCandidate, L as LoopProvenanceRecord, O as ObjectiveSource, P as ParetoSignificanceGateOptions, c as PromotionObjective, d as PromotionPolicy, R as RunEvalOptions, e as buildEvidenceVector, q as buildLoopProvenanceRecord, f as composeGate, g as defaultProductionGate, s as emitLoopProvenance, h as evolutionaryDriver, i as heldOutGate, t as loopProvenanceSpans, p as paretoPolicy, j as paretoSignificanceGate, u as provenanceRecordPath, v as provenanceSpansPath, r as runEval, w as surfaceContentHash } from '../provenance-jG-Gngg8.js';
|
|
7
7
|
import { L as LlmClientOptions } from '../llm-client-DbjLfz-K.js';
|
|
8
|
-
import { c as TraceAnalystKindSpec } from '../kind-factory-
|
|
9
|
-
import { c as AnalystFinding } from '../types-
|
|
8
|
+
import { c as TraceAnalystKindSpec } from '../kind-factory-DqV2t1Xk.js';
|
|
9
|
+
import { c as AnalystFinding } from '../types-DRvV0zRo.js';
|
|
10
10
|
import { a as PairedBootstrapResult } from '../statistics-B7yCbi9i.js';
|
|
11
|
-
import { A as AgentProfile, B as BackendIntegrityReport, C as CompletionRequirement, R as RuntimeEventLike, a as CompletionVerdict, P as ProducedState, b as CorrectnessChecker } from '../agent-profile-
|
|
11
|
+
import { A as AgentProfile, B as BackendIntegrityReport, C as CompletionRequirement, R as RuntimeEventLike, a as CompletionVerdict, P as ProducedState, b as CorrectnessChecker } from '../agent-profile-aSEaJ9Pl.js';
|
|
12
12
|
import { A as AgentEvalError } from '../errors-Dwqw-T_m.js';
|
|
13
|
-
import { b as RunSplitTag, R as RunRecord } from '../run-record-
|
|
13
|
+
import { b as RunSplitTag, R as RunRecord } from '../run-record-sItO5ftF.js';
|
|
14
14
|
import '@ax-llm/ax';
|
|
15
15
|
import '../store-GmBE2pZZ.js';
|
|
16
16
|
import '../red-team-DW9Ca_tj.js';
|
|
@@ -19,8 +19,8 @@ import '../store-CKUAgsJz.js';
|
|
|
19
19
|
import '../schema-m0gsnbt3.js';
|
|
20
20
|
import '../pareto-E-pembql.js';
|
|
21
21
|
import '../hosted/index.js';
|
|
22
|
-
import '../insight-report-
|
|
23
|
-
import '../summary-report-
|
|
22
|
+
import '../insight-report-dlpEzQDi.js';
|
|
23
|
+
import '../summary-report-BTaXq1TS.js';
|
|
24
24
|
import '../failure-cluster-CL7IVgkJ.js';
|
|
25
25
|
import '../judge-calibration-DilmB3Ml.js';
|
|
26
26
|
import '../raw-provider-sink-C46HDghv.js';
|
package/dist/campaign/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
paretoPolicy,
|
|
11
11
|
paretoSignificanceGate,
|
|
12
12
|
runEval
|
|
13
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-GXHLRXDI.js";
|
|
14
14
|
import {
|
|
15
15
|
agentProfileHash,
|
|
16
16
|
estimateCost,
|
|
@@ -39,7 +39,7 @@ import {
|
|
|
39
39
|
runOptimization,
|
|
40
40
|
surfaceContentHash,
|
|
41
41
|
surfaceHash
|
|
42
|
-
} from "../chunk-
|
|
42
|
+
} from "../chunk-RPLZ4OIB.js";
|
|
43
43
|
import {
|
|
44
44
|
assertRealBackend,
|
|
45
45
|
fsCampaignStorage,
|
|
@@ -51,7 +51,7 @@ import {
|
|
|
51
51
|
AnalystRegistry,
|
|
52
52
|
DEFAULT_TRACE_ANALYST_KINDS,
|
|
53
53
|
createTraceAnalystKind
|
|
54
|
-
} from "../chunk-
|
|
54
|
+
} from "../chunk-CF67I6QY.js";
|
|
55
55
|
import "../chunk-YV7J7X5N.js";
|
|
56
56
|
import {
|
|
57
57
|
callLlm
|
|
@@ -67,7 +67,7 @@ import {
|
|
|
67
67
|
import "../chunk-PC4UYEBM.js";
|
|
68
68
|
import {
|
|
69
69
|
validateRunRecord
|
|
70
|
-
} from "../chunk-
|
|
70
|
+
} from "../chunk-KWRRMR3J.js";
|
|
71
71
|
import "../chunk-VSMTAMNK.js";
|
|
72
72
|
import {
|
|
73
73
|
AgentEvalError
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ValidationError
|
|
3
|
+
} from "./chunk-3BFEG2F6.js";
|
|
4
|
+
|
|
5
|
+
// src/rl/off-policy.ts
|
|
6
|
+
function inverseProbabilityWeighting(trajectories, opts = {}) {
|
|
7
|
+
const cap = opts.weightCap ?? Infinity;
|
|
8
|
+
const clip = opts.rewardClip ?? { low: 0, high: 1 };
|
|
9
|
+
if (trajectories.length === 0) {
|
|
10
|
+
return zeroEstimate();
|
|
11
|
+
}
|
|
12
|
+
const weights = [];
|
|
13
|
+
const weightedRewards = [];
|
|
14
|
+
let maxW = 0;
|
|
15
|
+
for (const t of trajectories) {
|
|
16
|
+
if (t.behaviorProb <= 0) {
|
|
17
|
+
throw new ValidationError(
|
|
18
|
+
`inverseProbabilityWeighting: behaviorProb must be > 0 (runId=${t.runId})`
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
const w = Math.min(cap, t.targetProb / t.behaviorProb);
|
|
22
|
+
const r = clamp(t.reward, clip.low, clip.high);
|
|
23
|
+
weights.push(w);
|
|
24
|
+
weightedRewards.push(w * r);
|
|
25
|
+
if (w > maxW) maxW = w;
|
|
26
|
+
}
|
|
27
|
+
const n = weights.length;
|
|
28
|
+
const value = weightedRewards.reduce((s, x) => s + x, 0) / n;
|
|
29
|
+
const variance = weightedRewards.reduce((s, x) => s + (x - value) ** 2, 0) / Math.max(1, n - 1);
|
|
30
|
+
const sumW = weights.reduce((s, w) => s + w, 0);
|
|
31
|
+
const sumW2 = weights.reduce((s, w) => s + w * w, 0);
|
|
32
|
+
const effN = sumW === 0 ? 0 : sumW * sumW / sumW2;
|
|
33
|
+
return {
|
|
34
|
+
value,
|
|
35
|
+
standardError: Math.sqrt(variance / n),
|
|
36
|
+
effectiveSampleSize: effN,
|
|
37
|
+
n,
|
|
38
|
+
maxImportanceWeight: maxW
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function selfNormalizedImportanceWeighting(trajectories, opts = {}) {
|
|
42
|
+
const cap = opts.weightCap ?? Infinity;
|
|
43
|
+
const clip = opts.rewardClip ?? { low: 0, high: 1 };
|
|
44
|
+
if (trajectories.length === 0) return zeroEstimate();
|
|
45
|
+
const weights = [];
|
|
46
|
+
const rewards = [];
|
|
47
|
+
let maxW = 0;
|
|
48
|
+
for (const t of trajectories) {
|
|
49
|
+
if (t.behaviorProb <= 0) {
|
|
50
|
+
throw new ValidationError(
|
|
51
|
+
`selfNormalizedImportanceWeighting: behaviorProb must be > 0 (runId=${t.runId})`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
const w = Math.min(cap, t.targetProb / t.behaviorProb);
|
|
55
|
+
weights.push(w);
|
|
56
|
+
rewards.push(clamp(t.reward, clip.low, clip.high));
|
|
57
|
+
if (w > maxW) maxW = w;
|
|
58
|
+
}
|
|
59
|
+
const sumW = weights.reduce((s, w) => s + w, 0);
|
|
60
|
+
const sumWR = weights.reduce((s, w, i) => s + w * rewards[i], 0);
|
|
61
|
+
const value = sumW === 0 ? 0 : sumWR / sumW;
|
|
62
|
+
const sumW2 = weights.reduce((s, w) => s + w * w, 0);
|
|
63
|
+
const effN = sumW === 0 ? 0 : sumW * sumW / sumW2;
|
|
64
|
+
const phi = weights.map((w, i) => w * (rewards[i] - value));
|
|
65
|
+
const variance = phi.reduce((s, x) => s + x * x, 0) / Math.max(1, sumW * sumW);
|
|
66
|
+
return {
|
|
67
|
+
value,
|
|
68
|
+
standardError: Math.sqrt(variance),
|
|
69
|
+
effectiveSampleSize: effN,
|
|
70
|
+
n: trajectories.length,
|
|
71
|
+
maxImportanceWeight: maxW
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function doublyRobust(trajectories, opts = {}) {
|
|
75
|
+
const cap = opts.weightCap ?? Infinity;
|
|
76
|
+
const clip = opts.rewardClip ?? { low: 0, high: 1 };
|
|
77
|
+
if (trajectories.length === 0) return zeroEstimate();
|
|
78
|
+
const contributions = [];
|
|
79
|
+
let maxW = 0;
|
|
80
|
+
let sumW = 0;
|
|
81
|
+
let sumW2 = 0;
|
|
82
|
+
for (const t of trajectories) {
|
|
83
|
+
if (t.behaviorProb <= 0) {
|
|
84
|
+
throw new ValidationError(`doublyRobust: behaviorProb must be > 0 (runId=${t.runId})`);
|
|
85
|
+
}
|
|
86
|
+
const w = Math.min(cap, t.targetProb / t.behaviorProb);
|
|
87
|
+
const r = clamp(t.reward, clip.low, clip.high);
|
|
88
|
+
const q = typeof t.qHat === "number" && Number.isFinite(t.qHat) ? clamp(t.qHat, clip.low, clip.high) : null;
|
|
89
|
+
if (q === null) {
|
|
90
|
+
contributions.push(w * r);
|
|
91
|
+
} else {
|
|
92
|
+
contributions.push(q + w * (r - q));
|
|
93
|
+
}
|
|
94
|
+
if (w > maxW) maxW = w;
|
|
95
|
+
sumW += w;
|
|
96
|
+
sumW2 += w * w;
|
|
97
|
+
}
|
|
98
|
+
const n = contributions.length;
|
|
99
|
+
const value = contributions.reduce((s, x) => s + x, 0) / n;
|
|
100
|
+
const variance = contributions.reduce((s, x) => s + (x - value) ** 2, 0) / Math.max(1, n - 1);
|
|
101
|
+
const effN = sumW === 0 ? 0 : sumW * sumW / sumW2;
|
|
102
|
+
return {
|
|
103
|
+
value,
|
|
104
|
+
standardError: Math.sqrt(variance / n),
|
|
105
|
+
effectiveSampleSize: effN,
|
|
106
|
+
n,
|
|
107
|
+
maxImportanceWeight: maxW
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function offPolicyEstimateAll(trajectories, opts = {}) {
|
|
111
|
+
return {
|
|
112
|
+
ips: inverseProbabilityWeighting(trajectories, opts),
|
|
113
|
+
snips: selfNormalizedImportanceWeighting(trajectories, opts),
|
|
114
|
+
dr: doublyRobust(trajectories, opts)
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function zeroEstimate() {
|
|
118
|
+
return { value: 0, standardError: 0, effectiveSampleSize: 0, n: 0, maxImportanceWeight: 0 };
|
|
119
|
+
}
|
|
120
|
+
function clamp(x, lo, hi) {
|
|
121
|
+
if (!Number.isFinite(x)) return lo;
|
|
122
|
+
return Math.max(lo, Math.min(hi, x));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export {
|
|
126
|
+
inverseProbabilityWeighting,
|
|
127
|
+
selfNormalizedImportanceWeighting,
|
|
128
|
+
doublyRobust,
|
|
129
|
+
offPolicyEstimateAll
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=chunk-4DIJWVUT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/rl/off-policy.ts"],"sourcesContent":["/**\n * Off-policy evaluation primitives.\n *\n * Standard inverse-probability-weighted (IPS), self-normalized\n * importance-weighted (SNIPS), and doubly-robust (DR) estimators for the\n * value of a *target* policy given trajectories collected under a\n * *behavior* policy. This is the canonical RL eval task: \"we have last\n * week's runs, we changed the policy — how would the new one do without\n * re-running?\"\n *\n * The math here is textbook (Dudík, Langford, Li 2011 for DR; Swaminathan\n * & Joachims 2015 for SNIPS) but the *application* to LLM-agent\n * evaluation needs care:\n *\n * - The \"policy\" is the (prompt, tool config, model snapshot) triple.\n * Two policies have the same probability over an action *iff* their\n * LLM call would emit the same token with the same probability —\n * which is generally unknowable without the model log-probs.\n * - For LLM agents, propensity scores must be supplied by the caller\n * (logged in the trace, recovered from token log-probs, or estimated\n * via a learned propensity model). We do NOT estimate propensity here.\n * - Doubly-robust requires a Q-function (model-based reward predictor).\n * We accept any callable; consumers pass either a tabular average,\n * a regression fit, or a learned reward model.\n *\n * Bias / variance tradeoffs:\n * - IPS: unbiased; high variance for small overlap, infinite variance\n * when target has support outside behavior.\n * - SNIPS: lower variance, slight bias; usually preferred in practice.\n * - DR: doubly-robust — unbiased if either propensity OR Q-function is\n * correct. Lowest practical variance when Q is decent. Use this.\n *\n * Caveat the panel will land: on the LLM-agent setting, propensity scores\n * recovered from token log-probs are noisy, the action space is enormous,\n * and overlap is often poor. These estimators are useful but not magic;\n * complement with `replayCampaign` (exact replay where the request hashes\n * match) for high-confidence answers and OPE for the gap.\n */\n\nimport { ValidationError } from '../errors'\n\nexport interface OffPolicyTrajectory {\n /** Stable id, for traceability through the dataset. */\n runId: string\n /** Reward observed under the behavior policy (the realized outcome). */\n reward: number\n /**\n * Behavior-policy probability of the action that was taken. For LLM\n * agents this is typically `exp(sum(token_log_probs))` over the chosen\n * trajectory. Must be in (0, 1].\n */\n behaviorProb: number\n /**\n * Target-policy probability of the same action. For replay-style\n * counterfactual evaluation this is what the *new* policy would have\n * assigned to the *old* trajectory. Must be in [0, 1].\n */\n targetProb: number\n /**\n * Optional model-based reward prediction at the same context. Used by\n * `doublyRobust`. Set to `null` for IPS-only evaluation.\n */\n qHat?: number | null\n}\n\nexport interface OffPolicyEstimate {\n /** Estimated value of the target policy. */\n value: number\n /** Standard error of the estimate. */\n standardError: number\n /** Effective sample size (Kong 1992). Lower = more reliance on a few high-weight samples. */\n effectiveSampleSize: number\n /** Number of trajectories used. */\n n: number\n /**\n * Diagnostic: maximum importance weight observed. Large values (>>10x\n * mean) are a red flag — variance is dominated by a few outliers.\n */\n maxImportanceWeight: number\n}\n\nexport interface OffPolicyOptions {\n /**\n * Cap importance weights at this value (Ionides 2008 truncated IS) to\n * trade unbiasedness for variance reduction. Default `Infinity` (no cap).\n * Set e.g. `10` for stable estimates when the policies are close.\n */\n weightCap?: number\n /** Reward clipping range. Default `[0, 1]`. */\n rewardClip?: { low: number; high: number }\n}\n\n/**\n * Inverse Probability Weighting (Horvitz-Thompson). Unbiased estimator\n * of E[reward under target policy]. Variance scales with the spread of\n * target/behavior ratios.\n */\nexport function inverseProbabilityWeighting(\n trajectories: OffPolicyTrajectory[],\n opts: OffPolicyOptions = {},\n): OffPolicyEstimate {\n const cap = opts.weightCap ?? Infinity\n const clip = opts.rewardClip ?? { low: 0, high: 1 }\n\n if (trajectories.length === 0) {\n return zeroEstimate()\n }\n\n const weights: number[] = []\n const weightedRewards: number[] = []\n let maxW = 0\n for (const t of trajectories) {\n if (t.behaviorProb <= 0) {\n throw new ValidationError(\n `inverseProbabilityWeighting: behaviorProb must be > 0 (runId=${t.runId})`,\n )\n }\n const w = Math.min(cap, t.targetProb / t.behaviorProb)\n const r = clamp(t.reward, clip.low, clip.high)\n weights.push(w)\n weightedRewards.push(w * r)\n if (w > maxW) maxW = w\n }\n const n = weights.length\n const value = weightedRewards.reduce((s, x) => s + x, 0) / n\n const variance = weightedRewards.reduce((s, x) => s + (x - value) ** 2, 0) / Math.max(1, n - 1)\n const sumW = weights.reduce((s, w) => s + w, 0)\n const sumW2 = weights.reduce((s, w) => s + w * w, 0)\n const effN = sumW === 0 ? 0 : (sumW * sumW) / sumW2\n\n return {\n value,\n standardError: Math.sqrt(variance / n),\n effectiveSampleSize: effN,\n n,\n maxImportanceWeight: maxW,\n }\n}\n\n/**\n * Self-Normalized Importance Sampling. Lower variance than vanilla IPS at\n * the cost of small bias (vanishing as N grows). The right default for\n * LLM-agent evaluation where overlap is often poor.\n */\nexport function selfNormalizedImportanceWeighting(\n trajectories: OffPolicyTrajectory[],\n opts: OffPolicyOptions = {},\n): OffPolicyEstimate {\n const cap = opts.weightCap ?? Infinity\n const clip = opts.rewardClip ?? { low: 0, high: 1 }\n if (trajectories.length === 0) return zeroEstimate()\n\n const weights: number[] = []\n const rewards: number[] = []\n let maxW = 0\n for (const t of trajectories) {\n if (t.behaviorProb <= 0) {\n throw new ValidationError(\n `selfNormalizedImportanceWeighting: behaviorProb must be > 0 (runId=${t.runId})`,\n )\n }\n const w = Math.min(cap, t.targetProb / t.behaviorProb)\n weights.push(w)\n rewards.push(clamp(t.reward, clip.low, clip.high))\n if (w > maxW) maxW = w\n }\n const sumW = weights.reduce((s, w) => s + w, 0)\n const sumWR = weights.reduce((s, w, i) => s + w * rewards[i]!, 0)\n const value = sumW === 0 ? 0 : sumWR / sumW\n const sumW2 = weights.reduce((s, w) => s + w * w, 0)\n const effN = sumW === 0 ? 0 : (sumW * sumW) / sumW2\n // Influence-function-based SE for SNIPS (Owen 2013, Ch. 9).\n const phi = weights.map((w, i) => w * (rewards[i]! - value))\n const variance = phi.reduce((s, x) => s + x * x, 0) / Math.max(1, sumW * sumW)\n return {\n value,\n standardError: Math.sqrt(variance),\n effectiveSampleSize: effN,\n n: trajectories.length,\n maxImportanceWeight: maxW,\n }\n}\n\n/**\n * Doubly-robust off-policy estimator (Dudík, Langford, Li 2011).\n *\n * V_DR = (1/N) * sum_i [ q_hat_i + (target_prob_i / behavior_prob_i) * (r_i - q_hat_i) ]\n *\n * Unbiased if EITHER:\n * - the importance ratios are correct (IPS-style validity), OR\n * - the Q-hat function is correct (model-based validity).\n *\n * In practice both are imperfect, but the residual bias is the *product*\n * of both errors — much smaller than either alone. This is why DR is the\n * default in production OPE pipelines.\n *\n * Requires `qHat` on every trajectory. If any are `null`, the estimator\n * falls back to SNIPS for those entries (loud-fallback behavior; the\n * report's `n` reflects the full set but `effectiveSampleSize` accounts\n * for the lost variance reduction).\n */\nexport function doublyRobust(\n trajectories: OffPolicyTrajectory[],\n opts: OffPolicyOptions = {},\n): OffPolicyEstimate {\n const cap = opts.weightCap ?? Infinity\n const clip = opts.rewardClip ?? { low: 0, high: 1 }\n if (trajectories.length === 0) return zeroEstimate()\n\n const contributions: number[] = []\n let maxW = 0\n let sumW = 0\n let sumW2 = 0\n for (const t of trajectories) {\n if (t.behaviorProb <= 0) {\n throw new ValidationError(`doublyRobust: behaviorProb must be > 0 (runId=${t.runId})`)\n }\n const w = Math.min(cap, t.targetProb / t.behaviorProb)\n const r = clamp(t.reward, clip.low, clip.high)\n const q =\n typeof t.qHat === 'number' && Number.isFinite(t.qHat)\n ? clamp(t.qHat, clip.low, clip.high)\n : null\n if (q === null) {\n contributions.push(w * r) // fallback: IPS for this entry\n } else {\n contributions.push(q + w * (r - q))\n }\n if (w > maxW) maxW = w\n sumW += w\n sumW2 += w * w\n }\n const n = contributions.length\n const value = contributions.reduce((s, x) => s + x, 0) / n\n const variance = contributions.reduce((s, x) => s + (x - value) ** 2, 0) / Math.max(1, n - 1)\n const effN = sumW === 0 ? 0 : (sumW * sumW) / sumW2\n return {\n value,\n standardError: Math.sqrt(variance / n),\n effectiveSampleSize: effN,\n n,\n maxImportanceWeight: maxW,\n }\n}\n\n/**\n * Convenience: run all three estimators and return them side-by-side.\n * The recommended diagnostic — agreement across estimators is a much\n * stronger signal than any single one.\n */\nexport function offPolicyEstimateAll(\n trajectories: OffPolicyTrajectory[],\n opts: OffPolicyOptions = {},\n): { ips: OffPolicyEstimate; snips: OffPolicyEstimate; dr: OffPolicyEstimate } {\n return {\n ips: inverseProbabilityWeighting(trajectories, opts),\n snips: selfNormalizedImportanceWeighting(trajectories, opts),\n dr: doublyRobust(trajectories, opts),\n }\n}\n\n// ── Helpers ──────────────────────────────────────────────────────────────\n\nfunction zeroEstimate(): OffPolicyEstimate {\n return { value: 0, standardError: 0, effectiveSampleSize: 0, n: 0, maxImportanceWeight: 0 }\n}\n\nfunction clamp(x: number, lo: number, hi: number): number {\n if (!Number.isFinite(x)) return lo\n return Math.max(lo, Math.min(hi, x))\n}\n"],"mappings":"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","names":[]}
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
computeFindingId,
|
|
5
5
|
createTraceAnalystKind,
|
|
6
6
|
makeFinding
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-CF67I6QY.js";
|
|
8
8
|
import {
|
|
9
9
|
LlmClient,
|
|
10
10
|
callLlmJson
|
|
@@ -24,6 +24,93 @@ function createAnalystAi(config) {
|
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
// src/analyst/chat-client.ts
|
|
28
|
+
function createChatClient(opts) {
|
|
29
|
+
switch (opts.transport) {
|
|
30
|
+
case "router":
|
|
31
|
+
return wrapLlmClient(
|
|
32
|
+
opts.transport,
|
|
33
|
+
opts.defaultModel,
|
|
34
|
+
new LlmClient({
|
|
35
|
+
baseUrl: opts.baseUrl ?? "https://router.tangle.tools/v1",
|
|
36
|
+
apiKey: opts.apiKey
|
|
37
|
+
})
|
|
38
|
+
);
|
|
39
|
+
case "cli-bridge":
|
|
40
|
+
return wrapLlmClient(
|
|
41
|
+
opts.transport,
|
|
42
|
+
opts.defaultModel,
|
|
43
|
+
new LlmClient({
|
|
44
|
+
baseUrl: opts.baseUrl ?? "http://127.0.0.1:3344/v1",
|
|
45
|
+
apiKey: opts.bearer ?? ""
|
|
46
|
+
})
|
|
47
|
+
);
|
|
48
|
+
case "direct-provider":
|
|
49
|
+
return wrapLlmClient(
|
|
50
|
+
opts.transport,
|
|
51
|
+
opts.defaultModel,
|
|
52
|
+
new LlmClient({
|
|
53
|
+
baseUrl: opts.baseUrl,
|
|
54
|
+
apiKey: opts.apiKey
|
|
55
|
+
})
|
|
56
|
+
);
|
|
57
|
+
case "sandbox-sdk":
|
|
58
|
+
return {
|
|
59
|
+
transport: "sandbox-sdk",
|
|
60
|
+
defaultModel: opts.defaultModel,
|
|
61
|
+
chat: async (req, callOpts) => opts.chat(resolveModel(req, opts.defaultModel), callOpts)
|
|
62
|
+
};
|
|
63
|
+
case "mock":
|
|
64
|
+
return {
|
|
65
|
+
transport: "mock",
|
|
66
|
+
defaultModel: opts.defaultModel,
|
|
67
|
+
chat: async (req, callOpts) => opts.handler(resolveModel(req, opts.defaultModel), callOpts)
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function wrapLlmClient(transport, defaultModel, inner) {
|
|
72
|
+
return {
|
|
73
|
+
transport,
|
|
74
|
+
defaultModel,
|
|
75
|
+
chat: async (req, callOpts) => {
|
|
76
|
+
const resolved = resolveModel(req, defaultModel);
|
|
77
|
+
const call = inner.call({
|
|
78
|
+
model: resolved.model,
|
|
79
|
+
messages: req.messages,
|
|
80
|
+
jsonMode: req.jsonMode,
|
|
81
|
+
jsonSchema: req.jsonSchema,
|
|
82
|
+
temperature: req.temperature,
|
|
83
|
+
maxTokens: req.maxTokens,
|
|
84
|
+
timeoutMs: req.timeoutMs
|
|
85
|
+
});
|
|
86
|
+
if (!callOpts?.signal) return await call;
|
|
87
|
+
return await Promise.race([call, abortAsRejection(callOpts.signal)]);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function abortAsRejection(signal) {
|
|
92
|
+
if (signal.aborted) return Promise.reject(toAbortError(signal));
|
|
93
|
+
return new Promise((_, reject) => {
|
|
94
|
+
signal.addEventListener("abort", () => reject(toAbortError(signal)), { once: true });
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function toAbortError(signal) {
|
|
98
|
+
const reason = signal.reason;
|
|
99
|
+
if (reason instanceof Error) return reason;
|
|
100
|
+
const e = new Error("ChatClient.chat: aborted");
|
|
101
|
+
e.name = "AbortError";
|
|
102
|
+
return e;
|
|
103
|
+
}
|
|
104
|
+
function resolveModel(req, defaultModel) {
|
|
105
|
+
if (req.model) return req;
|
|
106
|
+
if (!defaultModel) {
|
|
107
|
+
throw new Error(
|
|
108
|
+
"ChatClient.chat: no model on request and no defaultModel on the client. Either pass req.model or bind defaultModel at createChatClient()."
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
return { ...req, model: defaultModel };
|
|
112
|
+
}
|
|
113
|
+
|
|
27
114
|
// src/trace-analyst/behavioral-metrics.ts
|
|
28
115
|
var INPUT_GROWTH_FACTOR = 3;
|
|
29
116
|
var MIN_TOOL_CALLS = 3;
|
|
@@ -959,95 +1046,9 @@ function createSemanticConceptJudge(options = {}) {
|
|
|
959
1046
|
return (input) => runSemanticConceptJudge(input, options);
|
|
960
1047
|
}
|
|
961
1048
|
|
|
962
|
-
// src/analyst/chat-client.ts
|
|
963
|
-
function createChatClient(opts) {
|
|
964
|
-
switch (opts.transport) {
|
|
965
|
-
case "router":
|
|
966
|
-
return wrapLlmClient(
|
|
967
|
-
opts.transport,
|
|
968
|
-
opts.defaultModel,
|
|
969
|
-
new LlmClient({
|
|
970
|
-
baseUrl: opts.baseUrl ?? "https://router.tangle.tools/v1",
|
|
971
|
-
apiKey: opts.apiKey
|
|
972
|
-
})
|
|
973
|
-
);
|
|
974
|
-
case "cli-bridge":
|
|
975
|
-
return wrapLlmClient(
|
|
976
|
-
opts.transport,
|
|
977
|
-
opts.defaultModel,
|
|
978
|
-
new LlmClient({
|
|
979
|
-
baseUrl: opts.baseUrl ?? "http://127.0.0.1:3344/v1",
|
|
980
|
-
apiKey: opts.bearer ?? ""
|
|
981
|
-
})
|
|
982
|
-
);
|
|
983
|
-
case "direct-provider":
|
|
984
|
-
return wrapLlmClient(
|
|
985
|
-
opts.transport,
|
|
986
|
-
opts.defaultModel,
|
|
987
|
-
new LlmClient({
|
|
988
|
-
baseUrl: opts.baseUrl,
|
|
989
|
-
apiKey: opts.apiKey
|
|
990
|
-
})
|
|
991
|
-
);
|
|
992
|
-
case "sandbox-sdk":
|
|
993
|
-
return {
|
|
994
|
-
transport: "sandbox-sdk",
|
|
995
|
-
defaultModel: opts.defaultModel,
|
|
996
|
-
chat: async (req, callOpts) => opts.chat(resolveModel(req, opts.defaultModel), callOpts)
|
|
997
|
-
};
|
|
998
|
-
case "mock":
|
|
999
|
-
return {
|
|
1000
|
-
transport: "mock",
|
|
1001
|
-
defaultModel: opts.defaultModel,
|
|
1002
|
-
chat: async (req, callOpts) => opts.handler(resolveModel(req, opts.defaultModel), callOpts)
|
|
1003
|
-
};
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
function wrapLlmClient(transport, defaultModel, inner) {
|
|
1007
|
-
return {
|
|
1008
|
-
transport,
|
|
1009
|
-
defaultModel,
|
|
1010
|
-
chat: async (req, callOpts) => {
|
|
1011
|
-
const resolved = resolveModel(req, defaultModel);
|
|
1012
|
-
const call = inner.call({
|
|
1013
|
-
model: resolved.model,
|
|
1014
|
-
messages: req.messages,
|
|
1015
|
-
jsonMode: req.jsonMode,
|
|
1016
|
-
jsonSchema: req.jsonSchema,
|
|
1017
|
-
temperature: req.temperature,
|
|
1018
|
-
maxTokens: req.maxTokens,
|
|
1019
|
-
timeoutMs: req.timeoutMs
|
|
1020
|
-
});
|
|
1021
|
-
if (!callOpts?.signal) return await call;
|
|
1022
|
-
return await Promise.race([call, abortAsRejection(callOpts.signal)]);
|
|
1023
|
-
}
|
|
1024
|
-
};
|
|
1025
|
-
}
|
|
1026
|
-
function abortAsRejection(signal) {
|
|
1027
|
-
if (signal.aborted) return Promise.reject(toAbortError(signal));
|
|
1028
|
-
return new Promise((_, reject) => {
|
|
1029
|
-
signal.addEventListener("abort", () => reject(toAbortError(signal)), { once: true });
|
|
1030
|
-
});
|
|
1031
|
-
}
|
|
1032
|
-
function toAbortError(signal) {
|
|
1033
|
-
const reason = signal.reason;
|
|
1034
|
-
if (reason instanceof Error) return reason;
|
|
1035
|
-
const e = new Error("ChatClient.chat: aborted");
|
|
1036
|
-
e.name = "AbortError";
|
|
1037
|
-
return e;
|
|
1038
|
-
}
|
|
1039
|
-
function resolveModel(req, defaultModel) {
|
|
1040
|
-
if (req.model) return req;
|
|
1041
|
-
if (!defaultModel) {
|
|
1042
|
-
throw new Error(
|
|
1043
|
-
"ChatClient.chat: no model on request and no defaultModel on the client. Either pass req.model or bind defaultModel at createChatClient()."
|
|
1044
|
-
);
|
|
1045
|
-
}
|
|
1046
|
-
return { ...req, model: defaultModel };
|
|
1047
|
-
}
|
|
1048
|
-
|
|
1049
1049
|
export {
|
|
1050
1050
|
createAnalystAi,
|
|
1051
|
+
createChatClient,
|
|
1051
1052
|
computeTraceMetrics,
|
|
1052
1053
|
deriveEfficiencyFindings,
|
|
1053
1054
|
behavioralAnalyst,
|
|
@@ -1069,7 +1070,6 @@ export {
|
|
|
1069
1070
|
DEFAULT_COMPLEXITY_WEIGHTS,
|
|
1070
1071
|
SEMANTIC_CONCEPT_JUDGE_VERSION,
|
|
1071
1072
|
runSemanticConceptJudge,
|
|
1072
|
-
createSemanticConceptJudge
|
|
1073
|
-
createChatClient
|
|
1073
|
+
createSemanticConceptJudge
|
|
1074
1074
|
};
|
|
1075
|
-
//# sourceMappingURL=chunk-
|
|
1075
|
+
//# sourceMappingURL=chunk-5LVWPNS5.js.map
|