@ouispec/agent-evals 0.20.0 → 0.21.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 +7 -4
- package/dist/cassettes.d.ts +6 -0
- package/dist/cassettes.d.ts.map +1 -1
- package/dist/cassettes.js +8 -2
- package/dist/cassettes.js.map +1 -1
- package/dist/cli.js +9 -8
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +30 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +14 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -4
- package/dist/index.js.map +1 -1
- package/dist/judge.d.ts +30 -4
- package/dist/judge.d.ts.map +1 -1
- package/dist/judge.js +65 -14
- package/dist/judge.js.map +1 -1
- package/dist/memory.d.ts +40 -2
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +32 -2
- package/dist/memory.js.map +1 -1
- package/dist/page.d.ts +54 -0
- package/dist/page.d.ts.map +1 -0
- package/dist/page.js +338 -0
- package/dist/page.js.map +1 -0
- package/dist/report.d.ts +10 -2
- package/dist/report.d.ts.map +1 -1
- package/dist/report.js +23 -15
- package/dist/report.js.map +1 -1
- package/dist/run.d.ts +45 -5
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +236 -47
- package/dist/run.js.map +1 -1
- package/dist/suite.d.ts.map +1 -1
- package/dist/suite.js +37 -1
- package/dist/suite.js.map +1 -1
- package/dist/usage.d.ts +29 -0
- package/dist/usage.d.ts.map +1 -0
- package/dist/usage.js +65 -0
- package/dist/usage.js.map +1 -0
- package/package.json +6 -4
package/dist/run.d.ts
CHANGED
|
@@ -2,14 +2,34 @@ import { type ApprovalPreview } from '@ouispec/agent-core';
|
|
|
2
2
|
import { type TurnOutcome } from '@ouispec/agent-worker';
|
|
3
3
|
import type { AgentEvalExpectation, AgentEvalScenario, AgentEvalSuite } from '@ouispec/contract';
|
|
4
4
|
import type { AgentEvalConfig, EvalMode } from './config.js';
|
|
5
|
-
import { judge } from './judge.js';
|
|
5
|
+
import { judge, type JudgeOptions } from './judge.js';
|
|
6
|
+
import { type EvalPageRun } from './page.js';
|
|
7
|
+
import { type EvalTurnUsage } from './usage.js';
|
|
6
8
|
/** One assertion that did not hold, or why a case could not be run. */
|
|
7
9
|
export interface EvalFailure {
|
|
8
10
|
/** The turn it is about (0-based, in the scenario's turns); -1 for the case as a whole. */
|
|
9
11
|
turn: number;
|
|
10
|
-
/** `says`, `toolCalled`, …; `recording`, `stub`, `scenario` or `turn` for what stopped the case. */
|
|
12
|
+
/** `says`, `toolCalled`, …; `recording`, `stub`, `scenario`, `page` or `turn` for what stopped the case. */
|
|
11
13
|
assertion: string;
|
|
12
14
|
message: string;
|
|
15
|
+
/**
|
|
16
|
+
* `assertion`: the agent did not do what the scenario says. `judge`: a
|
|
17
|
+
* rubric could not be decided, because the judge gave no verdict; the reply
|
|
18
|
+
* was not judged, so this says nothing about the agent. `case`: the case
|
|
19
|
+
* could not run as written (no recording, a call no stub answers, a turn
|
|
20
|
+
* that failed).
|
|
21
|
+
*/
|
|
22
|
+
kind: 'assertion' | 'judge' | 'case';
|
|
23
|
+
}
|
|
24
|
+
/** Choice buttons a turn offered (`present_options`). */
|
|
25
|
+
export interface EvalChoices {
|
|
26
|
+
/** What is asked with them: what it says first, then the question. */
|
|
27
|
+
question: string;
|
|
28
|
+
options: Array<{
|
|
29
|
+
label: string;
|
|
30
|
+
value?: string;
|
|
31
|
+
description?: string;
|
|
32
|
+
}>;
|
|
13
33
|
}
|
|
14
34
|
/** What one of the agent's turns did, as the assertions read it. */
|
|
15
35
|
export interface EvalTurnRecord {
|
|
@@ -31,7 +51,17 @@ export interface EvalTurnRecord {
|
|
|
31
51
|
} | null;
|
|
32
52
|
/** True when the turn ran no model call because a person held the conversation. */
|
|
33
53
|
held: boolean;
|
|
54
|
+
/** Requests that reached the model's network in the turn, retries included. */
|
|
34
55
|
modelRequests: number;
|
|
56
|
+
/** What the turn's model calls used, as the provider reported it. */
|
|
57
|
+
usage: EvalTurnUsage;
|
|
58
|
+
/** The choice buttons it offered. */
|
|
59
|
+
choices: EvalChoices[];
|
|
60
|
+
/** Where the page was after the turn, and what ran on it during the turn; null with no page. */
|
|
61
|
+
page: {
|
|
62
|
+
at: string;
|
|
63
|
+
ran: EvalPageRun[];
|
|
64
|
+
} | null;
|
|
35
65
|
outcome: TurnOutcome['status'];
|
|
36
66
|
stopReason?: string;
|
|
37
67
|
}
|
|
@@ -41,7 +71,10 @@ export interface EvalCaseResult {
|
|
|
41
71
|
title: string;
|
|
42
72
|
channel: string;
|
|
43
73
|
mode: EvalMode;
|
|
74
|
+
/** True only when every assertion held and every rubric was judged. */
|
|
44
75
|
passed: boolean;
|
|
76
|
+
/** `failed`: an assertion did not hold, or the case could not run; `unjudged`: none failed, but a rubric could not be judged. */
|
|
77
|
+
status: 'passed' | 'failed' | 'unjudged';
|
|
45
78
|
failures: EvalFailure[];
|
|
46
79
|
turns: EvalTurnRecord[];
|
|
47
80
|
/** The recording's file. */
|
|
@@ -54,6 +87,8 @@ export interface EvalReport {
|
|
|
54
87
|
cases: EvalCaseResult[];
|
|
55
88
|
passed: number;
|
|
56
89
|
failed: number;
|
|
90
|
+
/** Cases where nothing failed but a rubric could not be judged. */
|
|
91
|
+
unjudged: number;
|
|
57
92
|
}
|
|
58
93
|
/** One scenario on one channel, ready to run. */
|
|
59
94
|
export interface EvalCase {
|
|
@@ -99,10 +134,15 @@ export declare function runEvalCase(config: AgentEvalConfig, target: {
|
|
|
99
134
|
/** A turn's general expectation and its channel's, as one: lists joined, the channel's single values winning. */
|
|
100
135
|
export declare function mergeExpectations(general?: AgentEvalExpectation, channel?: AgentEvalExpectation): AgentEvalExpectation;
|
|
101
136
|
type Judge = Parameters<typeof judge>[0];
|
|
102
|
-
/**
|
|
103
|
-
export
|
|
137
|
+
/** One way a turn broke its expectation; `kind: 'judge'` when a rubric could not be judged at all. */
|
|
138
|
+
export interface CheckFailure {
|
|
104
139
|
assertion: string;
|
|
105
140
|
message: string;
|
|
106
|
-
|
|
141
|
+
kind?: 'assertion' | 'judge';
|
|
142
|
+
}
|
|
143
|
+
/** Every way a turn breaks its expectation. */
|
|
144
|
+
export declare function check(expect: AgentEvalExpectation, record: EvalTurnRecord, stored: string, judgeModel: Judge, options?: {
|
|
145
|
+
judge?: JudgeOptions;
|
|
146
|
+
}): Promise<CheckFailure[]>;
|
|
107
147
|
export {};
|
|
108
148
|
//# sourceMappingURL=run.d.ts.map
|
package/dist/run.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAaA,OAAO,EAGL,KAAK,eAAe,EAGrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAWL,KAAK,WAAW,EACjB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EAAkB,oBAAoB,EAAiB,iBAAiB,EAAE,cAAc,EAAwB,MAAM,mBAAmB,CAAC;AACtJ,OAAO,KAAK,EAAE,eAAe,EAAgC,QAAQ,EAAE,MAAM,aAAa,CAAC;AAI3F,OAAO,EAAE,KAAK,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAEtD,OAAO,EAAoC,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAC/E,OAAO,EAAiD,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAI/F,uEAAuE;AACvE,MAAM,WAAW,WAAW;IAC1B,2FAA2F;IAC3F,IAAI,EAAE,MAAM,CAAC;IACb,4GAA4G;IAC5G,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;;OAMG;IACH,IAAI,EAAE,WAAW,GAAG,OAAO,GAAG,MAAM,CAAC;CACtC;AAED,yDAAyD;AACzD,MA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AO,GACrC,OAAO,CAAC,YAAY,EAAE,CAAC,CA8KzB"}
|
package/dist/run.js
CHANGED
|
@@ -4,19 +4,24 @@
|
|
|
4
4
|
* configuration, and every expectation checked after its turn.
|
|
5
5
|
*
|
|
6
6
|
* What the harness replaces is only what reaches the outside: the model's
|
|
7
|
-
* network (replayed, recorded or live), storage (one conversation in memory
|
|
8
|
-
* the realtime server (memory.ts)
|
|
7
|
+
* network (replayed, recorded or live), storage (one conversation in memory,
|
|
8
|
+
* or the product's own store), the realtime server (memory.ts), the person's
|
|
9
|
+
* page (page.ts, from the suite's fixture) and each tool's execution (its
|
|
10
|
+
* stub).
|
|
9
11
|
*/
|
|
10
12
|
import { resolve } from 'node:path';
|
|
11
13
|
import { fileURLToPath } from 'node:url';
|
|
12
14
|
import { AGENT_SOCKET_EVENTS, } from '@ouispec/agent-core';
|
|
13
|
-
import { createAgentTurnRunner, describeModel,
|
|
15
|
+
import { createAgentTurnRunner, describeModel, hostSystemPrompt, loadBuiltinTools, UI_ACT_TOOL, withoutClientUI, } from '@ouispec/agent-worker';
|
|
14
16
|
import { recordingFetch, replayingFetch } from '@ouispec/agent-worker/testing';
|
|
17
|
+
import { toolName } from '@ouispec/bindings';
|
|
15
18
|
import { CASSETTE_VERSION, cassettePath, fingerprint, readCassette, writeCassette } from './cassettes.js';
|
|
16
19
|
import { checkSuite, readSuiteFile } from './suite.js';
|
|
17
20
|
import { DEFAULT_REFUSAL, describeMatcher, holdsSubset, matchesText } from './matchers.js';
|
|
18
21
|
import { judge } from './judge.js';
|
|
19
|
-
import { NO_PAGE, createMemoryApprovalStore, createMemoryEmit, createMemoryStops } from './memory.js';
|
|
22
|
+
import { NO_PAGE, createMemoryApprovalStore, createMemoryEmit, createMemoryHistory, createMemoryStops } from './memory.js';
|
|
23
|
+
import { createFixturePage } from './page.js';
|
|
24
|
+
import { recordingCalls, turnUsage } from './usage.js';
|
|
20
25
|
/** A case whose assertions did not all hold, with every failure in its message. */
|
|
21
26
|
export class EvalCaseFailed extends Error {
|
|
22
27
|
result;
|
|
@@ -26,7 +31,7 @@ export class EvalCaseFailed extends Error {
|
|
|
26
31
|
this.name = 'EvalCaseFailed';
|
|
27
32
|
}
|
|
28
33
|
}
|
|
29
|
-
export const failureLine = (f) => `${f.turn >= 0 ? `turn ${f.turn + 1}, ` : ''}${f.assertion}: ${f.message}`;
|
|
34
|
+
export const failureLine = (f) => `${f.turn >= 0 ? `turn ${f.turn + 1}, ` : ''}${f.kind === 'judge' ? 'not judged, ' : ''}${f.assertion}: ${f.message}`;
|
|
30
35
|
// ─── Finding the cases ──────────────────────────────────────────────────────
|
|
31
36
|
function rootOf(config, fallback) {
|
|
32
37
|
if (config.root instanceof URL)
|
|
@@ -94,8 +99,8 @@ export async function runEvals(config, options = {}) {
|
|
|
94
99
|
results.push(result);
|
|
95
100
|
options.onCase?.(result);
|
|
96
101
|
}
|
|
97
|
-
const
|
|
98
|
-
return { mode: options.mode ?? 'replay', cases: results, passed, failed:
|
|
102
|
+
const count = (status) => results.filter((r) => r.status === status).length;
|
|
103
|
+
return { mode: options.mode ?? 'replay', cases: results, passed: count('passed'), failed: count('failed'), unjudged: count('unjudged') };
|
|
99
104
|
}
|
|
100
105
|
// ─── One case ───────────────────────────────────────────────────────────────
|
|
101
106
|
const QUIET = { info() { }, warn() { }, error() { }, debug() { } };
|
|
@@ -114,6 +119,8 @@ const AGENT_PARTS = [
|
|
|
114
119
|
'retries',
|
|
115
120
|
'beforeTurn',
|
|
116
121
|
'filterEvent',
|
|
122
|
+
'modelProviderOptions',
|
|
123
|
+
'forcedToolChoice',
|
|
117
124
|
];
|
|
118
125
|
/** Only the parts a turn runs with: anything else a product's configuration carries (its storage, its realtime server) stays out. */
|
|
119
126
|
function agentParts(config) {
|
|
@@ -123,6 +130,22 @@ function agentParts(config) {
|
|
|
123
130
|
parts[key] = config[key];
|
|
124
131
|
return parts;
|
|
125
132
|
}
|
|
133
|
+
/** The SDK's own interaction tools (`present_options`, `confirm_action`, …): they reach no backend, so with no stub they run as they are. */
|
|
134
|
+
const INTERACTION_TOOLS = new Set(loadBuiltinTools().map((t) => t.name));
|
|
135
|
+
/** The choice buttons among a turn's calls. */
|
|
136
|
+
const choicesOf = (calls) => calls
|
|
137
|
+
.filter((c) => c.name === 'present_options')
|
|
138
|
+
.map((c) => {
|
|
139
|
+
const { context, prompt, options } = c.args;
|
|
140
|
+
return {
|
|
141
|
+
question: [context, prompt].filter((part) => typeof part === 'string' && part.trim() !== '').join('\n\n'),
|
|
142
|
+
options: (Array.isArray(options) ? options : []).map((o) => ({
|
|
143
|
+
label: String(o?.label ?? ''),
|
|
144
|
+
...(typeof o?.value === 'string' ? { value: o.value } : {}),
|
|
145
|
+
...(typeof o?.description === 'string' ? { description: o.description } : {}),
|
|
146
|
+
})),
|
|
147
|
+
};
|
|
148
|
+
});
|
|
126
149
|
/** The text a stored turn's messages said to the customer, in order. */
|
|
127
150
|
const replyOf = (messages) => messages
|
|
128
151
|
.filter((m) => m.role === 'assistant' && m.content?.trim())
|
|
@@ -138,22 +161,26 @@ export async function runEvalCase(config, target) {
|
|
|
138
161
|
const settings = config.channels[channel] ?? {};
|
|
139
162
|
const failures = [];
|
|
140
163
|
const turns = [];
|
|
141
|
-
const fail = (turn, assertion, message) => failures.push({ turn, assertion, message });
|
|
164
|
+
const fail = (turn, assertion, message, kind = 'case') => failures.push({ turn, assertion, message, kind });
|
|
142
165
|
const path = cassettePath(target.cassettes, suite, scenario, channel);
|
|
143
166
|
let modelRequests = 0;
|
|
144
|
-
const result = () =>
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
167
|
+
const result = () => {
|
|
168
|
+
const status = failures.length === 0 ? 'passed' : failures.every((f) => f.kind === 'judge') ? 'unjudged' : 'failed';
|
|
169
|
+
return {
|
|
170
|
+
suite: suite.name,
|
|
171
|
+
scenario: scenario.id,
|
|
172
|
+
title: scenario.title,
|
|
173
|
+
channel,
|
|
174
|
+
mode,
|
|
175
|
+
passed: status === 'passed',
|
|
176
|
+
status,
|
|
177
|
+
failures,
|
|
178
|
+
turns,
|
|
179
|
+
cassette: path,
|
|
180
|
+
modelRequests,
|
|
181
|
+
durationMs: Date.now() - started,
|
|
182
|
+
};
|
|
183
|
+
};
|
|
157
184
|
const customer = { userId: config.customer?.userId ?? 'eval-customer', accountId: config.customer?.accountId ?? 'eval-account' };
|
|
158
185
|
const conversationId = `eval-${scenario.id}-${channel}`;
|
|
159
186
|
const approvalChannel = settings.approvals ?? 'ui';
|
|
@@ -163,12 +190,19 @@ export async function runEvalCase(config, target) {
|
|
|
163
190
|
// The product's real configuration for this channel and scenario.
|
|
164
191
|
const agent = await config.agent({ channel, scenario, suite });
|
|
165
192
|
const resolveTools = async (turnId) => typeof agent.tools === 'function' ? await agent.tools({ ...customer, turnId }) : agent.tools;
|
|
193
|
+
// The person's page: the scenario's, else the suite's.
|
|
194
|
+
const pageFixture = scenario.page === false ? null : (scenario.page ?? suite.page ?? null);
|
|
166
195
|
const configured = fingerprint({
|
|
167
196
|
systemPrompt: hostSystemPrompt(agent, { ...customer, context: withoutClientUI(context) }),
|
|
168
197
|
tools: await resolveTools(`${conversationId}-0`),
|
|
169
198
|
channel: { name: channel, settings },
|
|
170
199
|
suite,
|
|
171
200
|
scenario,
|
|
201
|
+
// What else shapes what the model is asked, when the scenario has it.
|
|
202
|
+
...(pageFixture ? { page: { fixture: pageFixture, manifest: config.page?.manifest ?? null, knowledge: config.page?.knowledge ?? null } } : {}),
|
|
203
|
+
...(agent.modelProviderOptions !== undefined ? { modelProviderOptions: agent.modelProviderOptions } : {}),
|
|
204
|
+
...(agent.forcedToolChoice !== undefined ? { forcedToolChoice: agent.forcedToolChoice } : {}),
|
|
205
|
+
...(agent.uiActions !== undefined ? { uiActions: agent.uiActions } : {}),
|
|
172
206
|
});
|
|
173
207
|
// The model's network: replayed, recorded or live, every request counted.
|
|
174
208
|
const exchanges = [];
|
|
@@ -194,7 +228,10 @@ export async function runEvalCase(config, target) {
|
|
|
194
228
|
modelRequests += 1;
|
|
195
229
|
return network(input, init);
|
|
196
230
|
};
|
|
197
|
-
const
|
|
231
|
+
const providerModel = config.model({ fetch: counted, mode, purpose: 'agent' });
|
|
232
|
+
// Every call of the agent's model, as the provider reported what it used: never the judge's.
|
|
233
|
+
const modelCalls = [];
|
|
234
|
+
const model = recordingCalls(providerModel, (call) => modelCalls.push(call));
|
|
198
235
|
const judgeModel = (config.judge ?? config.model)({ fetch: counted, mode, purpose: 'judge' });
|
|
199
236
|
// Each tool runs only as its stub says: an eval never reaches a real backend.
|
|
200
237
|
let currentTurn = -1;
|
|
@@ -212,16 +249,28 @@ export async function runEvalCase(config, target) {
|
|
|
212
249
|
const answer = await stubbed(tool, args, call);
|
|
213
250
|
if (answer)
|
|
214
251
|
return answer;
|
|
252
|
+
if (INTERACTION_TOOLS.has(tool.name))
|
|
253
|
+
return tool.execute(args, call);
|
|
215
254
|
fail(currentTurn, 'stub', `the agent called ${tool.name} with ${JSON.stringify(args)}, and no stub answers that call`);
|
|
216
255
|
return { success: false, error: `[agent-evals] ${tool.name} has no stub for this call; nothing was run` };
|
|
217
256
|
},
|
|
218
257
|
});
|
|
219
|
-
// The
|
|
258
|
+
// The person's page, as the fixture declares it.
|
|
259
|
+
let page = null;
|
|
260
|
+
if (pageFixture) {
|
|
261
|
+
try {
|
|
262
|
+
page = createFixturePage(pageFixture, config.page);
|
|
263
|
+
}
|
|
264
|
+
catch (err) {
|
|
265
|
+
fail(-1, 'page', err instanceof Error ? err.message : String(err));
|
|
266
|
+
return result();
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
// The realtime server in memory, and the product's store (its own, or the whole conversation in memory).
|
|
220
270
|
const emit = createMemoryEmit();
|
|
221
271
|
const approvals = createMemoryApprovalStore();
|
|
222
272
|
const stops = createMemoryStops();
|
|
223
|
-
const history =
|
|
224
|
-
let snapshot = [];
|
|
273
|
+
const history = await (config.history?.({ channel, scenario, suite }) ?? createMemoryHistory());
|
|
225
274
|
let stored = [];
|
|
226
275
|
const runner = createAgentTurnRunner({
|
|
227
276
|
...agentParts(agent),
|
|
@@ -229,7 +278,8 @@ export async function runEvalCase(config, target) {
|
|
|
229
278
|
model,
|
|
230
279
|
...(config.promptCacheBreakpoint ? { promptCacheBreakpoint: config.promptCacheBreakpoint } : {}),
|
|
231
280
|
realtime: { url: NOWHERE, apiKey: 'agent-evals', emit },
|
|
232
|
-
|
|
281
|
+
// The page answers; with none, nothing does, at once (a turn whose context carries a snapshot is told the page is not responding).
|
|
282
|
+
uiActions: { ...agent.uiActions, ...(page ? { channel: page.channel } : { channel: NO_PAGE, resultTimeoutMs: 0 }) },
|
|
233
283
|
approvals: {
|
|
234
284
|
store: approvals,
|
|
235
285
|
...(agent.approvals?.preview ? { preview: agent.approvals.preview } : {}),
|
|
@@ -237,32 +287,37 @@ export async function runEvalCase(config, target) {
|
|
|
237
287
|
},
|
|
238
288
|
stops: { client: stops },
|
|
239
289
|
getDb: async () => null,
|
|
240
|
-
getHistory:
|
|
241
|
-
persistMessages: async ({
|
|
242
|
-
stored.push({ messages, ...(stopped ? { stopped } : {}) });
|
|
243
|
-
history.
|
|
290
|
+
getHistory: (id, _db, turn) => history.getHistory(id, turn),
|
|
291
|
+
persistMessages: async ({ db: _db, ...turn }) => {
|
|
292
|
+
stored.push({ messages: turn.messages, ...(turn.stopped ? { stopped: turn.stopped } : {}) });
|
|
293
|
+
return history.persistMessages(turn);
|
|
244
294
|
},
|
|
245
295
|
logger: QUIET,
|
|
246
296
|
});
|
|
247
297
|
const runTurn = async (index, kind, payload) => {
|
|
248
298
|
currentTurn = index;
|
|
249
299
|
const turnId = `${conversationId}-${index}`;
|
|
250
|
-
|
|
300
|
+
// The product's API stores the customer's message before it runs the turn.
|
|
251
301
|
if (kind === 'user')
|
|
252
|
-
history.
|
|
302
|
+
await history.append(conversationId, { role: 'user', content: payload.content });
|
|
253
303
|
stored = [];
|
|
254
304
|
const before = modelRequests;
|
|
305
|
+
const callsBefore = modelCalls.length;
|
|
306
|
+
const ranBefore = page?.ran.length ?? 0;
|
|
307
|
+
// The turn is sent from where the page is, with what it offers now, as the person's tab sends it.
|
|
308
|
+
const pageContext = page ? await page.context() : {};
|
|
255
309
|
const outcome = await runner.run({
|
|
256
310
|
turnId,
|
|
257
311
|
conversationId,
|
|
258
312
|
...customer,
|
|
259
313
|
socketRoom: `eval:turn:${turnId}`,
|
|
260
314
|
content: payload.content,
|
|
261
|
-
context: kind === 'user' ? context : sharedContext,
|
|
315
|
+
context: { ...(kind === 'user' ? context : sharedContext), ...pageContext },
|
|
262
316
|
channel: approvalChannel,
|
|
263
317
|
...(payload.approval ? { approval: payload.approval } : {}),
|
|
264
318
|
});
|
|
265
319
|
const messages = stored.flatMap((s) => s.messages);
|
|
320
|
+
const toolCalls = messages.flatMap((m) => (m.toolCalls ?? []).map((c) => ({ name: c.name, args: c.arguments })));
|
|
266
321
|
const asked = emit.events.find((e) => e.event === AGENT_SOCKET_EVENTS.APPROVAL_REQUIRED && e.data.turnId === turnId);
|
|
267
322
|
const pending = asked ? approvals.asked.find((a) => a.approvalId === asked.data.approvalId) : undefined;
|
|
268
323
|
const stopReason = outcome.status === 'stopped' ? outcome.stopReason : undefined;
|
|
@@ -271,10 +326,13 @@ export async function runEvalCase(config, target) {
|
|
|
271
326
|
kind,
|
|
272
327
|
customer: payload.content,
|
|
273
328
|
reply: replyOf(messages),
|
|
274
|
-
toolCalls
|
|
329
|
+
toolCalls,
|
|
275
330
|
approval: pending ? { tool: pending.tool, args: pending.args, preview: pending.preview } : null,
|
|
276
331
|
held: stopReason === 'taken_over' && modelRequests === before,
|
|
277
332
|
modelRequests: modelRequests - before,
|
|
333
|
+
usage: turnUsage(modelCalls.slice(callsBefore)),
|
|
334
|
+
choices: choicesOf(toolCalls),
|
|
335
|
+
page: page ? { at: page.location(), ran: page.ran.slice(ranBefore) } : null,
|
|
278
336
|
outcome: outcome.status,
|
|
279
337
|
...(stopReason ? { stopReason } : {}),
|
|
280
338
|
};
|
|
@@ -292,14 +350,14 @@ export async function runEvalCase(config, target) {
|
|
|
292
350
|
const { displayName, role, userId } = action.takeOver;
|
|
293
351
|
held = { userId: userId ?? `staff-${displayName.toLowerCase().replace(/[^a-z0-9]+/g, '-')}`, displayName, ...(role ? { role } : {}) };
|
|
294
352
|
stops.hold(conversationId, held);
|
|
295
|
-
history.
|
|
353
|
+
await history.append(conversationId, { role: 'staff', speaker: held, content: null, takeover: 'taken_over' });
|
|
296
354
|
}
|
|
297
355
|
else if ('say' in action) {
|
|
298
|
-
history.
|
|
356
|
+
await history.append(conversationId, { role: 'staff', speaker: held, content: action.say });
|
|
299
357
|
}
|
|
300
358
|
else {
|
|
301
359
|
stops.release(conversationId);
|
|
302
|
-
history.
|
|
360
|
+
await history.append(conversationId, { role: 'staff', speaker: held, content: null, takeover: 'handed_back' });
|
|
303
361
|
held = null;
|
|
304
362
|
}
|
|
305
363
|
continue;
|
|
@@ -319,6 +377,9 @@ export async function runEvalCase(config, target) {
|
|
|
319
377
|
fail(index, 'scenario', `the approval of ${waiting.tool} could not be decided: ${decided.reason}`);
|
|
320
378
|
break;
|
|
321
379
|
}
|
|
380
|
+
// The approval store hands the person's tab its grant, so the page runs the approved request.
|
|
381
|
+
if (page && decided.decision === 'approve')
|
|
382
|
+
page.grant({ approvalId: decided.approvalId, argsHash: decided.argsHash, expiresAt: decided.expiresAt });
|
|
322
383
|
ran = await runTurn(index, 'approval', {
|
|
323
384
|
content: '',
|
|
324
385
|
approval: turn.approval === 'approve'
|
|
@@ -327,13 +388,17 @@ export async function runEvalCase(config, target) {
|
|
|
327
388
|
});
|
|
328
389
|
}
|
|
329
390
|
const expectation = mergeExpectations(turn.expect, turn.expectOn?.[channel]);
|
|
330
|
-
for (const failure of await check(expectation, ran.record, ran.stored, judgeModel))
|
|
331
|
-
fail(index, failure.assertion, failure.message);
|
|
391
|
+
for (const failure of await check(expectation, ran.record, ran.stored, judgeModel, { judge: config.judgeOptions })) {
|
|
392
|
+
fail(index, failure.assertion, failure.message, failure.kind ?? 'assertion');
|
|
393
|
+
}
|
|
332
394
|
}
|
|
333
395
|
}
|
|
334
396
|
catch (err) {
|
|
335
397
|
fail(currentTurn, 'turn', `the run stopped: ${err instanceof Error ? err.message : String(err)}`);
|
|
336
398
|
}
|
|
399
|
+
finally {
|
|
400
|
+
page?.close();
|
|
401
|
+
}
|
|
337
402
|
// Replayed, the run asks exactly what was recorded: fewer requests is a run that went another way.
|
|
338
403
|
if (mode === 'replay' && failures.length === 0 && modelRequests !== recorded) {
|
|
339
404
|
fail(-1, 'recording', `the recording holds ${recorded} model responses and the run asked for ${modelRequests}: record it again with \`agent-evals --record\``);
|
|
@@ -344,7 +409,7 @@ export async function runEvalCase(config, target) {
|
|
|
344
409
|
suite: suite.name,
|
|
345
410
|
scenario: scenario.id,
|
|
346
411
|
channel,
|
|
347
|
-
model: describeModel(
|
|
412
|
+
model: describeModel(providerModel),
|
|
348
413
|
recordedAt: new Date().toISOString(),
|
|
349
414
|
fingerprint: configured,
|
|
350
415
|
exchanges,
|
|
@@ -359,7 +424,7 @@ export function mergeExpectations(general, channel) {
|
|
|
359
424
|
return channel ?? {};
|
|
360
425
|
if (!channel)
|
|
361
426
|
return general;
|
|
362
|
-
const lists = ['says', 'mustNotSay', 'toolCalled', 'toolNotCalled', 'doesNotStore'];
|
|
427
|
+
const lists = ['says', 'mustNotSay', 'toolCalled', 'toolNotCalled', 'doesNotStore', 'calls'];
|
|
363
428
|
const merged = { ...general, ...channel };
|
|
364
429
|
for (const key of lists) {
|
|
365
430
|
const joined = [...(general[key] ?? []), ...(channel[key] ?? [])];
|
|
@@ -369,22 +434,37 @@ export function mergeExpectations(general, channel) {
|
|
|
369
434
|
return merged;
|
|
370
435
|
}
|
|
371
436
|
/** Whether a matcher matches `text`; a rubric is put to the judge. */
|
|
372
|
-
async function matches(matcher, text, record, judgeModel) {
|
|
437
|
+
async function matches(matcher, text, record, judgeModel, options) {
|
|
373
438
|
if (typeof matcher === 'object' && 'rubric' in matcher) {
|
|
374
|
-
const verdict = await judge(judgeModel, matcher.rubric, record.customer, text);
|
|
439
|
+
const verdict = await judge(judgeModel, matcher.rubric, record.customer, text, options);
|
|
375
440
|
return 'error' in verdict ? verdict : { matched: verdict.pass, why: verdict.reason };
|
|
376
441
|
}
|
|
377
442
|
return { matched: matchesText(matcher, text) };
|
|
378
443
|
}
|
|
379
444
|
const quoted = (text) => JSON.stringify(text.length > 400 ? `${text.slice(0, 400)}…` : text);
|
|
445
|
+
const pct = (share) => `${Math.round(share * 1000) / 10}%`;
|
|
446
|
+
/** A page action named either way: by its id (`service-lane.view`) or by its name in the index (`service_lane_view`). */
|
|
447
|
+
const sameAction = (a, b) => a === b || toolName(a) === toolName(b);
|
|
448
|
+
/** How a bound reads in a report: "1", "at least 2", "at most 40,000", "2 to 4". */
|
|
449
|
+
function describeBound(bound, format = (n) => n.toLocaleString('en-US')) {
|
|
450
|
+
if (bound.min !== undefined && bound.max !== undefined)
|
|
451
|
+
return bound.min === bound.max ? format(bound.min) : `${format(bound.min)} to ${format(bound.max)}`;
|
|
452
|
+
return bound.min !== undefined ? `at least ${format(bound.min)}` : `at most ${format(bound.max)}`;
|
|
453
|
+
}
|
|
454
|
+
const within = (value, bound) => (bound.min === undefined || value >= bound.min) && (bound.max === undefined || value <= bound.max);
|
|
455
|
+
/** Where an address points: its path, and its query's parameters. */
|
|
456
|
+
function addressOf(address) {
|
|
457
|
+
const url = new URL(address, 'http://page.invalid');
|
|
458
|
+
return { path: url.pathname.replace(/\/+$/, '') || '/', query: Object.fromEntries(url.searchParams) };
|
|
459
|
+
}
|
|
380
460
|
/** Every way a turn breaks its expectation. */
|
|
381
|
-
export async function check(expect, record, stored, judgeModel) {
|
|
461
|
+
export async function check(expect, record, stored, judgeModel, options = {}) {
|
|
382
462
|
const out = [];
|
|
383
463
|
const reply = record.reply;
|
|
384
464
|
const textAssertion = async (assertion, matcher, text, want, what) => {
|
|
385
|
-
const got = await matches(matcher, text, record, judgeModel);
|
|
465
|
+
const got = await matches(matcher, text, record, judgeModel, options.judge);
|
|
386
466
|
if ('error' in got) {
|
|
387
|
-
out.push({ assertion, message: `${describeMatcher(matcher)} could not be judged: ${got.error}
|
|
467
|
+
out.push({ assertion, message: `${describeMatcher(matcher)} could not be judged: ${got.error}`, kind: 'judge' });
|
|
388
468
|
}
|
|
389
469
|
else if (got.matched !== want) {
|
|
390
470
|
out.push({
|
|
@@ -403,7 +483,8 @@ export async function check(expect, record, stored, judgeModel) {
|
|
|
403
483
|
for (const matcher of expect.doesNotStore ?? [])
|
|
404
484
|
await textAssertion('doesNotStore', matcher, stored, false, 'what the turn stored');
|
|
405
485
|
const calls = record.toolCalls;
|
|
406
|
-
const
|
|
486
|
+
const describeCall = (c) => c.name === UI_ACT_TOOL && typeof c.args.action === 'string' ? `${UI_ACT_TOOL} ${c.args.action} ${JSON.stringify(c.args.input ?? {})}` : `${c.name} ${JSON.stringify(c.args)}`;
|
|
487
|
+
const callsText = calls.length ? calls.map(describeCall).join('; ') : 'no tool';
|
|
407
488
|
for (const wanted of expect.toolCalled ?? []) {
|
|
408
489
|
const hit = calls.some((c) => c.name === wanted.name && (wanted.args === undefined || holdsSubset(c.args, wanted.args)));
|
|
409
490
|
if (!hit) {
|
|
@@ -418,6 +499,26 @@ export async function check(expect, record, stored, judgeModel) {
|
|
|
418
499
|
if (hit)
|
|
419
500
|
out.push({ assertion: 'toolNotCalled', message: `${name === '*' ? 'a tool' : name} was called: ${callsText}` });
|
|
420
501
|
}
|
|
502
|
+
for (const counted of expect.calls ?? []) {
|
|
503
|
+
const n = calls.filter((c) => 'tool' in counted
|
|
504
|
+
? c.name === counted.tool && (counted.args === undefined || holdsSubset(c.args, counted.args))
|
|
505
|
+
: c.name === UI_ACT_TOOL &&
|
|
506
|
+
typeof c.args.action === 'string' &&
|
|
507
|
+
sameAction(c.args.action, counted.action) &&
|
|
508
|
+
(counted.args === undefined || holdsSubset(c.args.input ?? {}, counted.args))).length;
|
|
509
|
+
const bound = counted.times !== undefined
|
|
510
|
+
? { min: counted.times, max: counted.times }
|
|
511
|
+
: counted.min === undefined && counted.max === undefined
|
|
512
|
+
? { min: 1 }
|
|
513
|
+
: { ...(counted.min !== undefined ? { min: counted.min } : {}), ...(counted.max !== undefined ? { max: counted.max } : {}) };
|
|
514
|
+
if (!within(n, bound)) {
|
|
515
|
+
const what = 'tool' in counted ? counted.tool : `the page's action ${counted.action}`;
|
|
516
|
+
out.push({
|
|
517
|
+
assertion: 'calls',
|
|
518
|
+
message: `${what}${counted.args ? ` with ${JSON.stringify(counted.args)}` : ''} was called ${n} time${n === 1 ? '' : 's'}, not ${describeBound(bound)}; the agent called ${callsText}`,
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
}
|
|
421
522
|
if (expect.approvalRequested === false) {
|
|
422
523
|
if (record.approval)
|
|
423
524
|
out.push({ assertion: 'approvalRequested', message: `the turn stopped for approval of ${record.approval.tool}` });
|
|
@@ -448,6 +549,94 @@ export async function check(expect, record, stored, judgeModel) {
|
|
|
448
549
|
: 'the turn did not run: a person held the conversation',
|
|
449
550
|
});
|
|
450
551
|
}
|
|
552
|
+
if (expect.usage) {
|
|
553
|
+
const u = record.usage;
|
|
554
|
+
const bounds = [
|
|
555
|
+
['modelCalls', u.calls.length, expect.usage.modelCalls, 'model calls'],
|
|
556
|
+
['firstCallInputTokens', u.firstCallInputTokens, expect.usage.firstCallInputTokens, 'input tokens in its first model call'],
|
|
557
|
+
['inputTokens', u.inputTokens, expect.usage.inputTokens, 'input tokens in all its model calls'],
|
|
558
|
+
['outputTokens', u.outputTokens, expect.usage.outputTokens, 'output tokens'],
|
|
559
|
+
];
|
|
560
|
+
for (const [name, value, bound, what] of bounds) {
|
|
561
|
+
if (bound && !within(value, bound))
|
|
562
|
+
out.push({ assertion: `usage.${name}`, message: `the turn used ${value.toLocaleString('en-US')} ${what}, not ${describeBound(bound)}` });
|
|
563
|
+
}
|
|
564
|
+
const perCall = expect.usage.callInputTokens;
|
|
565
|
+
if (perCall) {
|
|
566
|
+
const outside = u.calls.map((c, i) => [i + 1, c.inputTokens]).filter(([, n]) => !within(n, perCall));
|
|
567
|
+
if (outside.length > 0) {
|
|
568
|
+
out.push({
|
|
569
|
+
assertion: 'usage.callInputTokens',
|
|
570
|
+
message: `${outside.map(([i, n]) => `call ${i} used ${n.toLocaleString('en-US')}`).join(', ')} input tokens, not ${describeBound(perCall)} each`,
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
const share = expect.usage.cachedShare;
|
|
575
|
+
if (share && !within(u.cachedShare, share)) {
|
|
576
|
+
out.push({
|
|
577
|
+
assertion: 'usage.cachedShare',
|
|
578
|
+
message: `${pct(u.cachedShare)} of its input (${u.cacheReadTokens.toLocaleString('en-US')} of ${u.inputTokens.toLocaleString('en-US')} tokens) was read from the prompt cache, not ${describeBound(share, pct)}`,
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
if (expect.choices === false) {
|
|
583
|
+
if (record.choices.length > 0) {
|
|
584
|
+
out.push({ assertion: 'choices', message: `the turn offered choices: ${record.choices.flatMap((c) => c.options.map((o) => JSON.stringify(o.label))).join(', ')}` });
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
else if (expect.choices) {
|
|
588
|
+
const wanted = expect.choices;
|
|
589
|
+
const options = record.choices.flatMap((c) => c.options);
|
|
590
|
+
if (record.choices.length === 0) {
|
|
591
|
+
out.push({ assertion: 'choices', message: `the turn offered no choices; the agent called ${callsText}` });
|
|
592
|
+
}
|
|
593
|
+
else {
|
|
594
|
+
const optionText = (o) => (o.description ? `${o.label}: ${o.description}` : o.label);
|
|
595
|
+
const listed = options.map((o) => `- ${optionText(o)}`).join('\n');
|
|
596
|
+
for (const matcher of wanted.options ?? []) {
|
|
597
|
+
if (typeof matcher === 'object' && 'rubric' in matcher) {
|
|
598
|
+
// A judge reads the options as the person sees them.
|
|
599
|
+
await textAssertion('choices', matcher, listed, true, 'the choices offered');
|
|
600
|
+
}
|
|
601
|
+
else if (!options.some((o) => matchesText(matcher, optionText(o)))) {
|
|
602
|
+
out.push({ assertion: 'choices', message: `no choice offered matches ${describeMatcher(matcher)}: ${options.map((o) => JSON.stringify(o.label)).join(', ')}` });
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
const question = record.choices.map((c) => c.question).join('\n\n');
|
|
606
|
+
for (const matcher of wanted.question ?? [])
|
|
607
|
+
await textAssertion('choices', matcher, question, true, 'the question asked with the choices');
|
|
608
|
+
if (wanted.count && !within(options.length, wanted.count)) {
|
|
609
|
+
out.push({ assertion: 'choices', message: `${options.length} choice${options.length === 1 ? ' was' : 's were'} offered, not ${describeBound(wanted.count)}` });
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
if (expect.page) {
|
|
614
|
+
const wanted = expect.page;
|
|
615
|
+
const page = record.page;
|
|
616
|
+
if (!page) {
|
|
617
|
+
out.push({ assertion: 'page', message: 'the scenario has no page: give the suite or the scenario one (`page`)' });
|
|
618
|
+
}
|
|
619
|
+
else {
|
|
620
|
+
const ranText = page.ran.length ? page.ran.map((r) => `${r.action} ${JSON.stringify(r.input)}`).join('; ') : 'nothing';
|
|
621
|
+
if (wanted.at !== undefined) {
|
|
622
|
+
const want = addressOf(wanted.at);
|
|
623
|
+
const got = addressOf(page.at);
|
|
624
|
+
if (got.path !== want.path || !Object.entries(want.query).every(([k, v]) => got.query[k] === v)) {
|
|
625
|
+
out.push({ assertion: 'page.at', message: `the page is at ${page.at}, not ${wanted.at}` });
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
for (const run of wanted.ran ?? []) {
|
|
629
|
+
const hit = page.ran.some((r) => (sameAction(r.action, run.action) || sameAction(r.id, run.action)) && (run.input === undefined || holdsSubset(r.input, run.input)));
|
|
630
|
+
if (!hit)
|
|
631
|
+
out.push({ assertion: 'page.ran', message: `${run.action}${run.input ? ` with ${JSON.stringify(run.input)}` : ''} did not run on the page; it ran ${ranText}` });
|
|
632
|
+
}
|
|
633
|
+
for (const name of wanted.notRan ?? []) {
|
|
634
|
+
const hit = name === '*' ? page.ran.length > 0 : page.ran.some((r) => sameAction(r.action, name) || sameAction(r.id, name));
|
|
635
|
+
if (hit)
|
|
636
|
+
out.push({ assertion: 'page.notRan', message: `${name === '*' ? 'an action' : name} ran on the page: ${ranText}` });
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
451
640
|
return out;
|
|
452
641
|
}
|
|
453
642
|
//# sourceMappingURL=run.js.map
|