bare-agent 0.45.0 → 0.46.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 +1 -1
- package/bareagent.context.md +11 -4
- package/package.json +1 -1
- package/primitives.json +1 -1
- package/src/evaluator.d.ts +65 -9
- package/src/evaluator.js +92 -11
package/README.md
CHANGED
|
@@ -88,7 +88,7 @@ Every piece works alone — take what you need, ignore the rest. Two axes: **Act
|
|
|
88
88
|
|
|
89
89
|
| Component | What it does |
|
|
90
90
|
|---|---|
|
|
91
|
-
| **Evaluator + refine** | Judge output by `predicate` (no tokens), `rubric` (an isolated adversarial grader),
|
|
91
|
+
| **Evaluator + refine** | Judge output by `predicate` (no tokens), `rubric` (an isolated adversarial grader), `agentic` (a critic that exercises the live artifact), or `jev` (a cheap calibrated classifier tier). `refine` is the bounded generate→evaluate→regenerate loop |
|
|
92
92
|
| **SkillRegistry** | Surface skills on demand: one meta-tool catalog; activating a skill injects its instructions and unlocks its tools |
|
|
93
93
|
| **stash** | Compact finished work out of the live window (restorable), or auto-fold the middle under token pressure |
|
|
94
94
|
|
package/bareagent.context.md
CHANGED
|
@@ -51,7 +51,7 @@ Eight entry points:
|
|
|
51
51
|
| Retry individual plan steps | runPlan({ stepRetry }) |
|
|
52
52
|
| Use a CLI tool as an LLM provider | CLIPipe |
|
|
53
53
|
| Health-check provider, store, and tools | Loop.validate() |
|
|
54
|
-
| Verify an agent's output (judge / grade / critic) | Evaluator + refine — `predicate` / `rubric` / `agentic` criteria |
|
|
54
|
+
| Verify an agent's output (judge / grade / critic) | Evaluator + refine — `predicate` / `rubric` / `agentic` / `jev` criteria |
|
|
55
55
|
| Decisively judge "did this answer honor the request?" (return-time) | judge — verbatim request + one artifact → `honored`/`broke` + mechanical `where`; `calibrate` admits a tier vs a frozen floor |
|
|
56
56
|
| Cheap yes/no, pick-one, or score classification (cheaper than judge/Evaluator.rubric) | JevProvider.classify — `noul`/`choice`/`score`; `calibrateJev` admits a Jev tier vs a frozen floor + injection battery |
|
|
57
57
|
| Offer skills on demand without bloating context | SkillRegistry — `skill_use` meta-tool + `skills.activeTools` thunk |
|
|
@@ -824,12 +824,18 @@ const out = await recurse('Fix the failing function in calc.js', ctx, {
|
|
|
824
824
|
```javascript
|
|
825
825
|
const { Evaluator, refine } = require('bare-agent');
|
|
826
826
|
|
|
827
|
-
const evaluator = new Evaluator({ provider }); // provider REQUIRED for rubric/agentic; predicate needs
|
|
827
|
+
const evaluator = new Evaluator({ provider, jevProvider }); // provider REQUIRED for rubric/agentic; jevProvider REQUIRED for jev; predicate needs neither
|
|
828
828
|
|
|
829
|
-
//
|
|
829
|
+
// Four criteria types — pass EXACTLY ONE:
|
|
830
830
|
const v1 = await evaluator.evaluate(goal, result, { predicate: (r) => r.includes('DONE') }); // deterministic, 0 tokens
|
|
831
831
|
const v2 = await evaluator.evaluate(goal, result, { rubric: 'Cites a source for every claim.' }); // isolated adversarial LLM grader
|
|
832
832
|
const v3 = await evaluator.evaluate(goal, url, { agentic: 'Open the page, click Submit, check the console for errors.' }); // tool-running critic that EXERCISES the artifact
|
|
833
|
+
const v4 = await evaluator.evaluate(goal, result, {
|
|
834
|
+
jev: {
|
|
835
|
+
question: { type: 'noul', instructions: 'Does the result satisfy the goal?' },
|
|
836
|
+
toVerdict: (a) => (a.noul >= 0.5 ? 'satisfied' : 'failed'), // caller owns the threshold/band mapping
|
|
837
|
+
},
|
|
838
|
+
}); // cheap calibrated classifier tier (~100-1000x cheaper than rubric)
|
|
833
839
|
|
|
834
840
|
// Verdict: { status: 'satisfied' | 'needs_revision' | 'failed', pass, score, critique, suggestions }
|
|
835
841
|
// pass = (status === 'satisfied'); needs_revision is retryable; failed is terminal (stop spending).
|
|
@@ -839,7 +845,8 @@ if (!v2.pass) console.log(v2.critique, v2.suggestions);
|
|
|
839
845
|
Key invariants:
|
|
840
846
|
- The **rubric path runs an isolated adversarial grader** — a separate context window with a harsh, independent prompt, never the generator's transcript. That isolation (not a feedback knob) is what defeats the self-evaluation trap; the grader treats the RESULT as untrusted DATA (judge prompt-injection defence).
|
|
841
847
|
- **`agentic`** (the third type) spins up a fresh Loop with scoped tools (set on the Evaluator, or per-call `opts.tools`) that **exercises** the live artifact — clicks, reads console/network — rather than reading text. Each critic round forwards to `onLlmResult`; a governance `HaltError` re-throws clean.
|
|
842
|
-
- **`
|
|
848
|
+
- **`jev`** (the fourth type) composes `JevProvider` for a cost tier BELOW rubric — `question` is the SOLE criterion sent to the classifier (no layered prompt), and the caller-supplied `toVerdict(answer)` maps jev's `noul`/`choice`/`score` answer shape to the tri-state status (the Evaluator stays agnostic to jev's answer shapes). A `toVerdict` return outside the tri-state set is a broken arbiter (BA-15 family): thrown as `ValidationError` naming the type only, never the value. Requires a `jevProvider` (on the Evaluator or per-call `opts.jevProvider`). `score` is always `null`.
|
|
849
|
+
- **`contract`** (a definition of done) is graded against instead of the loose goal: `evaluate(goal, result, { rubric, contract })`. Judge tokens forward to the gate via `onLlmResult` (`kind:'evaluate'`) so verification spend is visible to the budget. For `jev`, `contract` is used only as the failed/needs-revision critique string — never folded into `question`.
|
|
843
850
|
|
|
844
851
|
**`refine`** drives a caller-supplied `attempt`/`evaluate` until a satisfied verdict, a terminal `failed`, or `maxIterations` (the real bound is bareguard maxTurns/budget). It threads the latest `critique` into the next attempt (fresh-feedback, not anchoring on a failed answer) and a shared `contract` to both sides.
|
|
845
852
|
|
package/package.json
CHANGED
package/primitives.json
CHANGED
|
@@ -175,7 +175,7 @@
|
|
|
175
175
|
{
|
|
176
176
|
"name": "Evaluator",
|
|
177
177
|
"category": "evaluation",
|
|
178
|
-
"when": "you need to judge an output against a goal or contract — deterministically (predicate), by LLM rubric,
|
|
178
|
+
"when": "you need to judge an output against a goal or contract — deterministically (predicate), by LLM rubric, with a tool-running critic that exercises the live artifact, or by a cheap calibrated classifier (jev)",
|
|
179
179
|
"import": "import { Evaluator } from 'bare-agent'",
|
|
180
180
|
"signature": "new Evaluator(options?: EvaluatorOptions)",
|
|
181
181
|
"fails": "never throws for a bad grade — returns a Verdict {status: satisfied|needs_revision|failed}; a provider HaltError propagates clean. Judge tokens forward via onLlmResult.",
|
package/src/evaluator.d.ts
CHANGED
|
@@ -56,6 +56,12 @@ export type EvaluatorOptions = {
|
|
|
56
56
|
* `EvaluateOptions.tools`. Ignored by predicate/rubric.
|
|
57
57
|
*/
|
|
58
58
|
tools?: import("../types").ToolDef[] | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* - REQUIRED for the `jev` path — a cheap
|
|
61
|
+
* calibrated classifier tier (~100-1000x cheaper than a rubric LLM round for classification-shaped verdicts).
|
|
62
|
+
* Overridable per call via `EvaluateOptions.jevProvider`. Ignored by predicate/rubric/agentic.
|
|
63
|
+
*/
|
|
64
|
+
jevProvider?: import("./provider-jev").JevProvider | undefined;
|
|
59
65
|
};
|
|
60
66
|
export type Criteria = {
|
|
61
67
|
/**
|
|
@@ -75,9 +81,28 @@ export type Criteria = {
|
|
|
75
81
|
* `tools`. The strongest verification — catches what only running the thing reveals. Exactly one of the three.
|
|
76
82
|
*/
|
|
77
83
|
agentic?: string | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* -
|
|
86
|
+
* Cheap calibrated classifier door (composes `JevProvider`, the cost tier below `rubric`). `question` is
|
|
87
|
+
* ONE Jev question object — the SOLE criterion (a classifier takes one instruction, not a layered prompt;
|
|
88
|
+
* unlike rubric/agentic, `contract` is NOT folded into it here — it is used only as the failed-critique
|
|
89
|
+
* string). `toVerdict` maps the classifier's per-question answer (`{type:'noul',noul}` /
|
|
90
|
+
* `{type:'choice',choice,...}` / `{type:'score',score,...}`) to a tri-state status — the caller owns
|
|
91
|
+
* thresholds/bands (Option A: caller-supplied mapping fn, open + simple, no premature abstraction over
|
|
92
|
+
* jev's three answer shapes). Requires a `jevProvider` (on the Evaluator or per-call). Exactly one of the four.
|
|
93
|
+
*/
|
|
94
|
+
jev?: {
|
|
95
|
+
question: {
|
|
96
|
+
type: "noul" | "choice" | "score";
|
|
97
|
+
instructions: string;
|
|
98
|
+
criteria?: any;
|
|
99
|
+
};
|
|
100
|
+
toVerdict: (answer: any) => "satisfied" | "needs_revision" | "failed";
|
|
101
|
+
} | undefined;
|
|
78
102
|
/**
|
|
79
103
|
* - The shared, authoritative "definition of done" the grader judges against
|
|
80
|
-
* (A3 / D10). When present it is what success means — not the loose goal. Folded into the rubric/agentic
|
|
104
|
+
* (A3 / D10). When present it is what success means — not the loose goal. Folded into the rubric/agentic
|
|
105
|
+
* prompt; for the `jev` door it is used ONLY as the failed-critique string (never folded into `question`).
|
|
81
106
|
*/
|
|
82
107
|
contract?: string | undefined;
|
|
83
108
|
};
|
|
@@ -102,21 +127,28 @@ export type EvaluateOptions = {
|
|
|
102
127
|
* critic MUST be bounded (turn/budget caps come from the gate; the Loop's HARD_ROUND_LIMIT is only a net).
|
|
103
128
|
*/
|
|
104
129
|
policy?: Function | undefined;
|
|
130
|
+
/**
|
|
131
|
+
* - Per-call override of the `jev` door's classifier
|
|
132
|
+
* provider (else `EvaluatorOptions.jevProvider`).
|
|
133
|
+
*/
|
|
134
|
+
jevProvider?: import("./provider-jev").JevProvider | undefined;
|
|
105
135
|
};
|
|
106
136
|
/**
|
|
107
137
|
* Output-side judge — the mirror of `Planner` (input-side). Judges whether a result meets a goal, by a
|
|
108
|
-
* deterministic `predicate`, an LLM `rubric`,
|
|
109
|
-
* `Verdict`. The rubric and agentic paths run an ISOLATED adversarial
|
|
110
|
-
* system prompt) — that isolation, not a feedback knob, is what
|
|
111
|
-
* path additionally EXERCISES the artifact with scoped tools
|
|
112
|
-
*
|
|
138
|
+
* deterministic `predicate`, an LLM `rubric`, a tool-running `agentic` critic, or a cheap calibrated `jev`
|
|
139
|
+
* classifier tier, returning one uniform `Verdict`. The rubric and agentic paths run an ISOLATED adversarial
|
|
140
|
+
* critic (separate context + independent system prompt) — that isolation, not a feedback knob, is what
|
|
141
|
+
* defeats the self-evaluation trap. The agentic path additionally EXERCISES the artifact with scoped tools
|
|
142
|
+
* (it does not read the diff). The `jev` path composes `JevProvider` (a single classification call, ~100-1000x
|
|
143
|
+
* cheaper than a rubric round) for classification-shaped verdicts — the caller supplies a `toVerdict` mapping
|
|
144
|
+
* fn from the classifier's answer to the tri-state status. Composes AROUND a Loop (never inside `loop.js`).
|
|
113
145
|
*
|
|
114
146
|
* Built flagged-and-deletable per D11 — opt-in by import; calibrate the rubric/prompt from execution traces.
|
|
115
147
|
*/
|
|
116
148
|
export class Evaluator {
|
|
117
149
|
/**
|
|
118
150
|
* @param {EvaluatorOptions} [options]
|
|
119
|
-
* @when you need to judge an output against a goal or contract — deterministically (predicate), by LLM rubric,
|
|
151
|
+
* @when you need to judge an output against a goal or contract — deterministically (predicate), by LLM rubric, with a tool-running critic that exercises the live artifact, or by a cheap calibrated classifier (jev)
|
|
120
152
|
* @fails never throws for a bad grade — returns a Verdict {status: satisfied|needs_revision|failed}; a provider HaltError propagates clean. Judge tokens forward via onLlmResult.
|
|
121
153
|
* @example
|
|
122
154
|
* const evaluator = new Evaluator({ provider });
|
|
@@ -128,14 +160,15 @@ export class Evaluator {
|
|
|
128
160
|
prompt: string;
|
|
129
161
|
agenticPrompt: string;
|
|
130
162
|
tools: import("../types").ToolDef[];
|
|
163
|
+
jevProvider: import("./provider-jev").JevProvider | null;
|
|
131
164
|
/**
|
|
132
165
|
* Judge `result` against `goal` by exactly one criteria type.
|
|
133
166
|
* @param {string} goal - The objective the result is judged against.
|
|
134
167
|
* @param {any} result - The output under judgment.
|
|
135
|
-
* @param {Criteria} criteria - Exactly one of `predicate` | `rubric` | `agentic` (none/more-than-one throws).
|
|
168
|
+
* @param {Criteria} criteria - Exactly one of `predicate` | `rubric` | `agentic` | `jev` (none/more-than-one throws).
|
|
136
169
|
* @param {EvaluateOptions} [opts]
|
|
137
170
|
* @returns {Promise<Verdict>}
|
|
138
|
-
* @throws {ValidationError} not-exactly-one criteria supplied, or rubric/agentic requested with no provider.
|
|
171
|
+
* @throws {ValidationError} not-exactly-one criteria supplied, or rubric/agentic/jev requested with no provider.
|
|
139
172
|
*/
|
|
140
173
|
evaluate(goal: string, result: any, criteria: Criteria, opts?: EvaluateOptions): Promise<Verdict>;
|
|
141
174
|
/**
|
|
@@ -155,6 +188,29 @@ export class Evaluator {
|
|
|
155
188
|
* @throws {HaltError} a governance cap halted the critic mid-run.
|
|
156
189
|
*/
|
|
157
190
|
_evaluateAgentic(goal: string, result: any, instructions: string, contract: string | null, opts: EvaluateOptions): Promise<Verdict>;
|
|
191
|
+
/**
|
|
192
|
+
* Jev path — a cheap calibrated classifier verdict tier (the cost tier below `rubric`; ~100-1000x cheaper
|
|
193
|
+
* for classification-shaped verdicts). Unlike rubric/agentic there is NO layered prompt: `question.instructions`
|
|
194
|
+
* is the SOLE criterion sent to the classifier (a classifier takes one instruction, not goal+contract+rubric).
|
|
195
|
+
* `toVerdict` — caller-supplied (Option A: open + simple, no premature abstraction over jev's three answer
|
|
196
|
+
* shapes) — maps the classifier's answer to a tri-state status; the caller owns thresholds/bands.
|
|
197
|
+
* @param {any} result
|
|
198
|
+
* @param {{question: {type: 'noul'|'choice'|'score', instructions: string, criteria?: any}, toVerdict: (answer: any) => any}} jevCriteria
|
|
199
|
+
* @param {string|null} contract - Used ONLY as the failed-critique string (never folded into the question).
|
|
200
|
+
* @param {EvaluateOptions} opts
|
|
201
|
+
* @returns {Promise<Verdict>}
|
|
202
|
+
* @throws {ValidationError} no jevProvider, `toVerdict` isn't a function, or it returns something other
|
|
203
|
+
* than a valid tri-state status (BA-15 family — a broken arbiter is named loudly, never coerced; the
|
|
204
|
+
* error names the TYPE only, never the returned VALUE, F16/BA-1 audit-safety).
|
|
205
|
+
*/
|
|
206
|
+
_evaluateJev(result: any, jevCriteria: {
|
|
207
|
+
question: {
|
|
208
|
+
type: "noul" | "choice" | "score";
|
|
209
|
+
instructions: string;
|
|
210
|
+
criteria?: any;
|
|
211
|
+
};
|
|
212
|
+
toVerdict: (answer: any) => any;
|
|
213
|
+
}, contract: string | null, opts: EvaluateOptions): Promise<Verdict>;
|
|
158
214
|
/**
|
|
159
215
|
* Defensive JSON parse of a grader response into a `Verdict` (mirrors `Planner._parse`).
|
|
160
216
|
* @param {string} text
|
package/src/evaluator.js
CHANGED
|
@@ -34,6 +34,9 @@ const { Loop } = require('./loop');
|
|
|
34
34
|
* @property {ToolDef[]} [tools] - The critic's SCOPED functional tools (`barebrowse`/`baremobile`) for the
|
|
35
35
|
* agentic path — what lets it exercise the live artifact rather than read text. Overridable per call via
|
|
36
36
|
* `EvaluateOptions.tools`. Ignored by predicate/rubric.
|
|
37
|
+
* @property {import('./provider-jev').JevProvider} [jevProvider] - REQUIRED for the `jev` path — a cheap
|
|
38
|
+
* calibrated classifier tier (~100-1000x cheaper than a rubric LLM round for classification-shaped verdicts).
|
|
39
|
+
* Overridable per call via `EvaluateOptions.jevProvider`. Ignored by predicate/rubric/agentic.
|
|
37
40
|
*/
|
|
38
41
|
|
|
39
42
|
/**
|
|
@@ -46,8 +49,17 @@ const { Loop } = require('./loop');
|
|
|
46
49
|
* @property {string} [agentic] - Instructions for a tool-running critic (D9): how to EXERCISE the live artifact
|
|
47
50
|
* (open it, click, read console/network) and what would make it fail. Runs an ISOLATED Loop with the scoped
|
|
48
51
|
* `tools`. The strongest verification — catches what only running the thing reveals. Exactly one of the three.
|
|
52
|
+
* @property {{question: {type: 'noul'|'choice'|'score', instructions: string, criteria?: any}, toVerdict: (answer: any) => 'satisfied'|'needs_revision'|'failed'}} [jev] -
|
|
53
|
+
* Cheap calibrated classifier door (composes `JevProvider`, the cost tier below `rubric`). `question` is
|
|
54
|
+
* ONE Jev question object — the SOLE criterion (a classifier takes one instruction, not a layered prompt;
|
|
55
|
+
* unlike rubric/agentic, `contract` is NOT folded into it here — it is used only as the failed-critique
|
|
56
|
+
* string). `toVerdict` maps the classifier's per-question answer (`{type:'noul',noul}` /
|
|
57
|
+
* `{type:'choice',choice,...}` / `{type:'score',score,...}`) to a tri-state status — the caller owns
|
|
58
|
+
* thresholds/bands (Option A: caller-supplied mapping fn, open + simple, no premature abstraction over
|
|
59
|
+
* jev's three answer shapes). Requires a `jevProvider` (on the Evaluator or per-call). Exactly one of the four.
|
|
49
60
|
* @property {string} [contract] - The shared, authoritative "definition of done" the grader judges against
|
|
50
|
-
* (A3 / D10). When present it is what success means — not the loose goal. Folded into the rubric/agentic
|
|
61
|
+
* (A3 / D10). When present it is what success means — not the loose goal. Folded into the rubric/agentic
|
|
62
|
+
* prompt; for the `jev` door it is used ONLY as the failed-critique string (never folded into `question`).
|
|
51
63
|
*/
|
|
52
64
|
|
|
53
65
|
/**
|
|
@@ -59,6 +71,8 @@ const { Loop } = require('./loop');
|
|
|
59
71
|
* @property {ToolDef[]} [tools] - Per-call override of the agentic critic's scoped tools (else `EvaluatorOptions.tools`).
|
|
60
72
|
* @property {Function} [policy] - bareguard `policy` forwarded to the agentic critic's Loop — a tool-running
|
|
61
73
|
* critic MUST be bounded (turn/budget caps come from the gate; the Loop's HARD_ROUND_LIMIT is only a net).
|
|
74
|
+
* @property {import('./provider-jev').JevProvider} [jevProvider] - Per-call override of the `jev` door's classifier
|
|
75
|
+
* provider (else `EvaluatorOptions.jevProvider`).
|
|
62
76
|
*/
|
|
63
77
|
|
|
64
78
|
// The adversarial grader system prompt — the anti-sycophancy core (A1, "Self-Evaluation is a Trap"). The
|
|
@@ -99,18 +113,20 @@ Output your FINAL answer as ONLY this JSON, no markdown, no prose:
|
|
|
99
113
|
|
|
100
114
|
/**
|
|
101
115
|
* Output-side judge — the mirror of `Planner` (input-side). Judges whether a result meets a goal, by a
|
|
102
|
-
* deterministic `predicate`, an LLM `rubric`,
|
|
103
|
-
* `Verdict`. The rubric and agentic paths run an ISOLATED adversarial
|
|
104
|
-
* system prompt) — that isolation, not a feedback knob, is what
|
|
105
|
-
* path additionally EXERCISES the artifact with scoped tools
|
|
106
|
-
*
|
|
116
|
+
* deterministic `predicate`, an LLM `rubric`, a tool-running `agentic` critic, or a cheap calibrated `jev`
|
|
117
|
+
* classifier tier, returning one uniform `Verdict`. The rubric and agentic paths run an ISOLATED adversarial
|
|
118
|
+
* critic (separate context + independent system prompt) — that isolation, not a feedback knob, is what
|
|
119
|
+
* defeats the self-evaluation trap. The agentic path additionally EXERCISES the artifact with scoped tools
|
|
120
|
+
* (it does not read the diff). The `jev` path composes `JevProvider` (a single classification call, ~100-1000x
|
|
121
|
+
* cheaper than a rubric round) for classification-shaped verdicts — the caller supplies a `toVerdict` mapping
|
|
122
|
+
* fn from the classifier's answer to the tri-state status. Composes AROUND a Loop (never inside `loop.js`).
|
|
107
123
|
*
|
|
108
124
|
* Built flagged-and-deletable per D11 — opt-in by import; calibrate the rubric/prompt from execution traces.
|
|
109
125
|
*/
|
|
110
126
|
class Evaluator {
|
|
111
127
|
/**
|
|
112
128
|
* @param {EvaluatorOptions} [options]
|
|
113
|
-
* @when you need to judge an output against a goal or contract — deterministically (predicate), by LLM rubric,
|
|
129
|
+
* @when you need to judge an output against a goal or contract — deterministically (predicate), by LLM rubric, with a tool-running critic that exercises the live artifact, or by a cheap calibrated classifier (jev)
|
|
114
130
|
* @fails never throws for a bad grade — returns a Verdict {status: satisfied|needs_revision|failed}; a provider HaltError propagates clean. Judge tokens forward via onLlmResult.
|
|
115
131
|
* @example
|
|
116
132
|
* const evaluator = new Evaluator({ provider });
|
|
@@ -122,23 +138,25 @@ class Evaluator {
|
|
|
122
138
|
this.prompt = options.prompt || GRADER_PROMPT;
|
|
123
139
|
this.agenticPrompt = options.agenticPrompt || AGENTIC_PROMPT;
|
|
124
140
|
this.tools = Array.isArray(options.tools) ? options.tools : [];
|
|
141
|
+
this.jevProvider = options.jevProvider || null;
|
|
125
142
|
}
|
|
126
143
|
|
|
127
144
|
/**
|
|
128
145
|
* Judge `result` against `goal` by exactly one criteria type.
|
|
129
146
|
* @param {string} goal - The objective the result is judged against.
|
|
130
147
|
* @param {any} result - The output under judgment.
|
|
131
|
-
* @param {Criteria} criteria - Exactly one of `predicate` | `rubric` | `agentic` (none/more-than-one throws).
|
|
148
|
+
* @param {Criteria} criteria - Exactly one of `predicate` | `rubric` | `agentic` | `jev` (none/more-than-one throws).
|
|
132
149
|
* @param {EvaluateOptions} [opts]
|
|
133
150
|
* @returns {Promise<Verdict>}
|
|
134
|
-
* @throws {ValidationError} not-exactly-one criteria supplied, or rubric/agentic requested with no provider.
|
|
151
|
+
* @throws {ValidationError} not-exactly-one criteria supplied, or rubric/agentic/jev requested with no provider.
|
|
135
152
|
*/
|
|
136
153
|
async evaluate(goal, result, criteria, opts = {}) {
|
|
137
154
|
const predicate = typeof criteria?.predicate === 'function' ? criteria.predicate : null;
|
|
138
155
|
const rubric = typeof criteria?.rubric === 'string' && criteria.rubric.length > 0 ? criteria.rubric : null;
|
|
139
156
|
const agentic = typeof criteria?.agentic === 'string' && criteria.agentic.length > 0 ? criteria.agentic : null;
|
|
140
|
-
|
|
141
|
-
|
|
157
|
+
const jev = criteria && typeof criteria.jev === 'object' && criteria.jev !== null ? criteria.jev : null;
|
|
158
|
+
if ([predicate, rubric, agentic, jev].filter(Boolean).length !== 1) {
|
|
159
|
+
throw new ValidationError('[Evaluator] criteria must supply exactly one of { predicate } | { rubric } | { agentic } | { jev }');
|
|
142
160
|
}
|
|
143
161
|
|
|
144
162
|
if (predicate) {
|
|
@@ -184,6 +202,12 @@ class Evaluator {
|
|
|
184
202
|
return this._evaluateAgentic(goal, result, agentic, contract, opts);
|
|
185
203
|
}
|
|
186
204
|
|
|
205
|
+
// Jev path — a cheap calibrated classifier tier (the cost tier below rubric). No layered prompt: the
|
|
206
|
+
// question's `instructions` is the sole criterion; `contract` (if any) is used only as the failed-critique.
|
|
207
|
+
if (jev) {
|
|
208
|
+
return this._evaluateJev(result, jev, contract, opts);
|
|
209
|
+
}
|
|
210
|
+
|
|
187
211
|
// Rubric path — isolated adversarial grader.
|
|
188
212
|
if (!this.provider) {
|
|
189
213
|
throw new ValidationError('[Evaluator] rubric criteria requires a provider on the Evaluator');
|
|
@@ -275,6 +299,63 @@ class Evaluator {
|
|
|
275
299
|
return this._parse(out.text);
|
|
276
300
|
}
|
|
277
301
|
|
|
302
|
+
/**
|
|
303
|
+
* Jev path — a cheap calibrated classifier verdict tier (the cost tier below `rubric`; ~100-1000x cheaper
|
|
304
|
+
* for classification-shaped verdicts). Unlike rubric/agentic there is NO layered prompt: `question.instructions`
|
|
305
|
+
* is the SOLE criterion sent to the classifier (a classifier takes one instruction, not goal+contract+rubric).
|
|
306
|
+
* `toVerdict` — caller-supplied (Option A: open + simple, no premature abstraction over jev's three answer
|
|
307
|
+
* shapes) — maps the classifier's answer to a tri-state status; the caller owns thresholds/bands.
|
|
308
|
+
* @param {any} result
|
|
309
|
+
* @param {{question: {type: 'noul'|'choice'|'score', instructions: string, criteria?: any}, toVerdict: (answer: any) => any}} jevCriteria
|
|
310
|
+
* @param {string|null} contract - Used ONLY as the failed-critique string (never folded into the question).
|
|
311
|
+
* @param {EvaluateOptions} opts
|
|
312
|
+
* @returns {Promise<Verdict>}
|
|
313
|
+
* @throws {ValidationError} no jevProvider, `toVerdict` isn't a function, or it returns something other
|
|
314
|
+
* than a valid tri-state status (BA-15 family — a broken arbiter is named loudly, never coerced; the
|
|
315
|
+
* error names the TYPE only, never the returned VALUE, F16/BA-1 audit-safety).
|
|
316
|
+
*/
|
|
317
|
+
async _evaluateJev(result, jevCriteria, contract, opts) {
|
|
318
|
+
const jevProvider = opts.jevProvider || this.jevProvider;
|
|
319
|
+
if (!jevProvider) {
|
|
320
|
+
throw new ValidationError('[Evaluator] jev criteria requires a jevProvider (on the Evaluator or per-call opts.jevProvider)');
|
|
321
|
+
}
|
|
322
|
+
const toVerdict = typeof jevCriteria?.toVerdict === 'function' ? jevCriteria.toVerdict : null;
|
|
323
|
+
if (!toVerdict) {
|
|
324
|
+
throw new ValidationError('[Evaluator] jev criteria requires a toVerdict(answer) => status function');
|
|
325
|
+
}
|
|
326
|
+
const question = jevCriteria.question;
|
|
327
|
+
const forward = opts.onLlmResult;
|
|
328
|
+
|
|
329
|
+
const out = await jevProvider.classify(stringifyResult(result), { q: question }, {
|
|
330
|
+
// Re-tag jev's own kind:'classify' as kind:'evaluate' at the Evaluator boundary (mirrors rubric/agentic).
|
|
331
|
+
// A HaltError thrown by the consumer's hook propagates clean (JevProvider awaits it, no swallow).
|
|
332
|
+
onLlmResult: forward
|
|
333
|
+
? async (/** @type {any} */ e) => { await forward({ usage: e.usage, model: e.model, kind: 'evaluate' }); }
|
|
334
|
+
: undefined,
|
|
335
|
+
});
|
|
336
|
+
const answer = out.answers.q;
|
|
337
|
+
|
|
338
|
+
const status = await toVerdict(answer);
|
|
339
|
+
if (status !== 'satisfied' && status !== 'needs_revision' && status !== 'failed') {
|
|
340
|
+
// Name the TYPE only, never the value — mirrors the predicate door's broken-arbiter guard (BA-15/F16).
|
|
341
|
+
const got = status === null ? 'null'
|
|
342
|
+
: status === undefined ? 'undefined'
|
|
343
|
+
: Array.isArray(status) ? 'an array'
|
|
344
|
+
: typeof status === 'object' ? 'an object'
|
|
345
|
+
: `a ${typeof status}`;
|
|
346
|
+
throw new ValidationError(
|
|
347
|
+
`[Evaluator] jev criteria toVerdict must return 'satisfied'|'needs_revision'|'failed', got ${got}.`,
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
return {
|
|
351
|
+
status,
|
|
352
|
+
pass: status === 'satisfied',
|
|
353
|
+
score: null,
|
|
354
|
+
critique: status === 'satisfied' ? '' : (typeof contract === 'string' ? contract : ''),
|
|
355
|
+
suggestions: [],
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
|
|
278
359
|
/**
|
|
279
360
|
* Defensive JSON parse of a grader response into a `Verdict` (mirrors `Planner._parse`).
|
|
280
361
|
* @param {string} text
|