@ouispec/agent-evals 0.0.0-stage → 0.19.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/LICENSE +21 -0
- package/README.md +23 -2
- package/dist/cassettes.d.ts +33 -0
- package/dist/cassettes.d.ts.map +1 -0
- package/dist/cassettes.js +59 -0
- package/dist/cassettes.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +157 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +94 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +5 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/judge.d.ts +15 -0
- package/dist/judge.d.ts.map +1 -0
- package/dist/judge.js +38 -0
- package/dist/judge.js.map +1 -0
- package/dist/matchers.d.ts +26 -0
- package/dist/matchers.d.ts.map +1 -0
- package/dist/matchers.js +44 -0
- package/dist/matchers.js.map +1 -0
- package/dist/memory.d.ts +49 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +147 -0
- package/dist/memory.js.map +1 -0
- package/dist/report.d.ts +11 -0
- package/dist/report.d.ts.map +1 -0
- package/dist/report.js +53 -0
- package/dist/report.js.map +1 -0
- package/dist/run.d.ts +108 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +453 -0
- package/dist/run.js.map +1 -0
- package/dist/suite.d.ts +17 -0
- package/dist/suite.d.ts.map +1 -0
- package/dist/suite.js +136 -0
- package/dist/suite.js.map +1 -0
- package/examples/dealer/agent-evals.config.mjs +47 -0
- package/examples/dealer/cassettes/dealer/ai-disclosure.sms.json +17 -0
- package/examples/dealer/cassettes/dealer/ai-disclosure.voice.json +17 -0
- package/examples/dealer/cassettes/dealer/ai-disclosure.web_chat.json +17 -0
- package/examples/dealer/cassettes/dealer/hand-off.sms.json +23 -0
- package/examples/dealer/cassettes/dealer/hand-off.voice.json +23 -0
- package/examples/dealer/cassettes/dealer/hand-off.web_chat.json +23 -0
- package/examples/dealer/cassettes/dealer/injected-instruction.sms.json +23 -0
- package/examples/dealer/cassettes/dealer/injected-instruction.voice.json +17 -0
- package/examples/dealer/cassettes/dealer/injected-instruction.web_chat.json +17 -0
- package/examples/dealer/cassettes/dealer/price-only.sms.json +23 -0
- package/examples/dealer/cassettes/dealer/price-only.voice.json +23 -0
- package/examples/dealer/cassettes/dealer/price-only.web_chat.json +23 -0
- package/examples/dealer/cassettes/dealer/service-booking-readback.sms.json +23 -0
- package/examples/dealer/cassettes/dealer/service-booking-readback.voice.json +23 -0
- package/examples/dealer/cassettes/dealer/service-booking-readback.web_chat.json +23 -0
- package/examples/dealer/cassettes/dealer/ssn-refused.sms.json +23 -0
- package/examples/dealer/cassettes/dealer/ssn-refused.voice.json +23 -0
- package/examples/dealer/cassettes/dealer/ssn-refused.web_chat.json +17 -0
- package/examples/dealer/cassettes/dealer/takeover-and-hand-back.sms.json +35 -0
- package/examples/dealer/cassettes/dealer/takeover-and-hand-back.voice.json +35 -0
- package/examples/dealer/cassettes/dealer/takeover-and-hand-back.web_chat.json +35 -0
- package/examples/dealer/dealer-agent.mjs +148 -0
- package/examples/dealer/dealer.evals.yaml +115 -0
- package/package.json +55 -3
package/dist/run.js
ADDED
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Running a suite: every scenario on every channel it runs on,
|
|
3
|
+
* each turn through the SDK's own turn runner with the product's real agent
|
|
4
|
+
* configuration, and every expectation checked after its turn.
|
|
5
|
+
*
|
|
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) and each tool's execution (its stub).
|
|
9
|
+
*/
|
|
10
|
+
import { resolve } from 'node:path';
|
|
11
|
+
import { fileURLToPath } from 'node:url';
|
|
12
|
+
import { AGENT_SOCKET_EVENTS, } from '@ouispec/agent-core';
|
|
13
|
+
import { createAgentTurnRunner, describeModel, historyOf, hostSystemPrompt, withoutClientUI, } from '@ouispec/agent-worker';
|
|
14
|
+
import { recordingFetch, replayingFetch } from '@ouispec/agent-worker/testing';
|
|
15
|
+
import { CASSETTE_VERSION, cassettePath, fingerprint, readCassette, writeCassette } from './cassettes.js';
|
|
16
|
+
import { checkSuite, readSuiteFile } from './suite.js';
|
|
17
|
+
import { DEFAULT_REFUSAL, describeMatcher, holdsSubset, matchesText } from './matchers.js';
|
|
18
|
+
import { judge } from './judge.js';
|
|
19
|
+
import { NO_PAGE, createMemoryApprovalStore, createMemoryEmit, createMemoryStops } from './memory.js';
|
|
20
|
+
/** A case whose assertions did not all hold, with every failure in its message. */
|
|
21
|
+
export class EvalCaseFailed extends Error {
|
|
22
|
+
result;
|
|
23
|
+
constructor(result) {
|
|
24
|
+
super(`${result.suite} › ${result.scenario} [${result.channel}] failed:\n${result.failures.map((f) => ` - ${failureLine(f)}`).join('\n')}`);
|
|
25
|
+
this.result = result;
|
|
26
|
+
this.name = 'EvalCaseFailed';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export const failureLine = (f) => `${f.turn >= 0 ? `turn ${f.turn + 1}, ` : ''}${f.assertion}: ${f.message}`;
|
|
30
|
+
// ─── Finding the cases ──────────────────────────────────────────────────────
|
|
31
|
+
function rootOf(config, fallback) {
|
|
32
|
+
if (config.root instanceof URL)
|
|
33
|
+
return fileURLToPath(config.root);
|
|
34
|
+
if (typeof config.root === 'string')
|
|
35
|
+
return config.root.startsWith('file:') ? fileURLToPath(config.root) : resolve(config.root);
|
|
36
|
+
return resolve(fallback ?? process.cwd());
|
|
37
|
+
}
|
|
38
|
+
/** Every scenario on every channel it runs on, as cases to run. */
|
|
39
|
+
export async function evalCases(config, options = {}) {
|
|
40
|
+
const root = rootOf(config, options.root);
|
|
41
|
+
const channelNames = Object.keys(config.channels);
|
|
42
|
+
if (channelNames.length === 0)
|
|
43
|
+
throw new Error('[agent-evals] the configuration names no channels');
|
|
44
|
+
const mode = options.mode ?? 'replay';
|
|
45
|
+
const cassettes = resolve(root, config.cassettes);
|
|
46
|
+
const suites = config.suites.map((entry) => {
|
|
47
|
+
if (typeof entry !== 'string')
|
|
48
|
+
return checkSuite(entry, `the suite "${entry.name ?? '(unnamed)'}"`, channelNames);
|
|
49
|
+
const path = resolve(root, entry);
|
|
50
|
+
return checkSuite(readSuiteFile(path), path, channelNames);
|
|
51
|
+
});
|
|
52
|
+
for (const name of options.channels ?? []) {
|
|
53
|
+
if (!channelNames.includes(name))
|
|
54
|
+
throw new Error(`[agent-evals] no channel "${name}" in the configuration (${channelNames.join(', ')})`);
|
|
55
|
+
}
|
|
56
|
+
const cases = [];
|
|
57
|
+
for (const suite of suites) {
|
|
58
|
+
for (const scenario of suite.scenarios) {
|
|
59
|
+
if (options.scenarios && !options.scenarios.includes(scenario.id))
|
|
60
|
+
continue;
|
|
61
|
+
for (const channel of scenario.channels ?? suite.channels ?? channelNames) {
|
|
62
|
+
if (options.channels && !options.channels.includes(channel))
|
|
63
|
+
continue;
|
|
64
|
+
const run = () => runEvalCase(config, { suite, scenario, channel, mode, cassettes });
|
|
65
|
+
cases.push({
|
|
66
|
+
name: `${suite.name} › ${scenario.id} [${channel}]`,
|
|
67
|
+
suite,
|
|
68
|
+
scenario,
|
|
69
|
+
channel,
|
|
70
|
+
run,
|
|
71
|
+
async assert() {
|
|
72
|
+
const result = await run();
|
|
73
|
+
if (!result.passed)
|
|
74
|
+
throw new EvalCaseFailed(result);
|
|
75
|
+
return result;
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (options.scenarios) {
|
|
82
|
+
const found = new Set(cases.map((c) => c.scenario.id));
|
|
83
|
+
const missing = options.scenarios.filter((id) => !found.has(id));
|
|
84
|
+
if (missing.length > 0)
|
|
85
|
+
throw new Error(`[agent-evals] no scenario ${missing.join(', ')} on the channels asked for`);
|
|
86
|
+
}
|
|
87
|
+
return cases;
|
|
88
|
+
}
|
|
89
|
+
/** Runs every case, one after another, and reports them all. */
|
|
90
|
+
export async function runEvals(config, options = {}) {
|
|
91
|
+
const results = [];
|
|
92
|
+
for (const evalCase of await evalCases(config, options)) {
|
|
93
|
+
const result = await evalCase.run();
|
|
94
|
+
results.push(result);
|
|
95
|
+
options.onCase?.(result);
|
|
96
|
+
}
|
|
97
|
+
const passed = results.filter((r) => r.passed).length;
|
|
98
|
+
return { mode: options.mode ?? 'replay', cases: results, passed, failed: results.length - passed };
|
|
99
|
+
}
|
|
100
|
+
// ─── One case ───────────────────────────────────────────────────────────────
|
|
101
|
+
const QUIET = { info() { }, warn() { }, error() { }, debug() { } };
|
|
102
|
+
/** The realtime server's URL as a run names it: every touchpoint is in memory, so nothing ever goes there. */
|
|
103
|
+
const NOWHERE = 'http://agent-evals.invalid';
|
|
104
|
+
const AGENT_PARTS = [
|
|
105
|
+
'persona',
|
|
106
|
+
'systemPrompt',
|
|
107
|
+
'toolPolicy',
|
|
108
|
+
'turnPolicy',
|
|
109
|
+
'maxRounds',
|
|
110
|
+
'maxTokens',
|
|
111
|
+
'temperature',
|
|
112
|
+
'toolTimeoutMs',
|
|
113
|
+
'turnDeadlineMs',
|
|
114
|
+
'retries',
|
|
115
|
+
'beforeTurn',
|
|
116
|
+
'filterEvent',
|
|
117
|
+
];
|
|
118
|
+
/** Only the parts a turn runs with: anything else a product's configuration carries (its storage, its realtime server) stays out. */
|
|
119
|
+
function agentParts(config) {
|
|
120
|
+
const parts = {};
|
|
121
|
+
for (const key of AGENT_PARTS)
|
|
122
|
+
if (config[key] !== undefined)
|
|
123
|
+
parts[key] = config[key];
|
|
124
|
+
return parts;
|
|
125
|
+
}
|
|
126
|
+
/** The text a stored turn's messages said to the customer, in order. */
|
|
127
|
+
const replyOf = (messages) => messages
|
|
128
|
+
.filter((m) => m.role === 'assistant' && m.content?.trim())
|
|
129
|
+
.map((m) => m.content.trim())
|
|
130
|
+
.join('\n\n');
|
|
131
|
+
/** Everything a turn stored, as text: what `doesNotStore` searches. */
|
|
132
|
+
const storedText = (messages) => messages
|
|
133
|
+
.flatMap((m) => [m.content ?? '', ...(m.toolCalls ?? []).map((c) => JSON.stringify(c.arguments))])
|
|
134
|
+
.join('\n');
|
|
135
|
+
export async function runEvalCase(config, target) {
|
|
136
|
+
const { suite, scenario, channel, mode } = target;
|
|
137
|
+
const started = Date.now();
|
|
138
|
+
const settings = config.channels[channel] ?? {};
|
|
139
|
+
const failures = [];
|
|
140
|
+
const turns = [];
|
|
141
|
+
const fail = (turn, assertion, message) => failures.push({ turn, assertion, message });
|
|
142
|
+
const path = cassettePath(target.cassettes, suite, scenario, channel);
|
|
143
|
+
let modelRequests = 0;
|
|
144
|
+
const result = () => ({
|
|
145
|
+
suite: suite.name,
|
|
146
|
+
scenario: scenario.id,
|
|
147
|
+
title: scenario.title,
|
|
148
|
+
channel,
|
|
149
|
+
mode,
|
|
150
|
+
passed: failures.length === 0,
|
|
151
|
+
failures,
|
|
152
|
+
turns,
|
|
153
|
+
cassette: path,
|
|
154
|
+
modelRequests,
|
|
155
|
+
durationMs: Date.now() - started,
|
|
156
|
+
});
|
|
157
|
+
const customer = { userId: config.customer?.userId ?? 'eval-customer', accountId: config.customer?.accountId ?? 'eval-account' };
|
|
158
|
+
const conversationId = `eval-${scenario.id}-${channel}`;
|
|
159
|
+
const approvalChannel = settings.approvals ?? 'ui';
|
|
160
|
+
const sharedContext = { ...(suite.context ?? {}), ...(settings.context ?? {}), ...(scenario.context ?? {}) };
|
|
161
|
+
// A customer's message on a voice channel says it was spoken; an approval's continuation is no message at all.
|
|
162
|
+
const context = { ...sharedContext, ...(settings.input ? { input: settings.input } : {}) };
|
|
163
|
+
// The product's real configuration for this channel and scenario.
|
|
164
|
+
const agent = await config.agent({ channel, scenario, suite });
|
|
165
|
+
const resolveTools = async (turnId) => typeof agent.tools === 'function' ? await agent.tools({ ...customer, turnId }) : agent.tools;
|
|
166
|
+
const configured = fingerprint({
|
|
167
|
+
systemPrompt: hostSystemPrompt(agent, { ...customer, context: withoutClientUI(context) }),
|
|
168
|
+
tools: await resolveTools(`${conversationId}-0`),
|
|
169
|
+
channel: { name: channel, settings },
|
|
170
|
+
suite,
|
|
171
|
+
scenario,
|
|
172
|
+
});
|
|
173
|
+
// The model's network: replayed, recorded or live, every request counted.
|
|
174
|
+
const exchanges = [];
|
|
175
|
+
let network;
|
|
176
|
+
let recorded = 0;
|
|
177
|
+
if (mode === 'replay') {
|
|
178
|
+
const cassette = readCassette(path);
|
|
179
|
+
if (!cassette) {
|
|
180
|
+
fail(-1, 'recording', `there is no recording at ${path}: record it with \`agent-evals --record\``);
|
|
181
|
+
return result();
|
|
182
|
+
}
|
|
183
|
+
if (cassette.fingerprint !== configured) {
|
|
184
|
+
fail(-1, 'recording', `${path} was recorded against another agent configuration or scenario (its system prompt, tools, channel or turns have changed since ${cassette.recordedAt}): record it again with \`agent-evals --record\``);
|
|
185
|
+
return result();
|
|
186
|
+
}
|
|
187
|
+
recorded = cassette.exchanges.length;
|
|
188
|
+
network = replayingFetch(cassette.exchanges);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
network = mode === 'record' ? recordingFetch(exchanges) : globalThis.fetch;
|
|
192
|
+
}
|
|
193
|
+
const counted = (input, init) => {
|
|
194
|
+
modelRequests += 1;
|
|
195
|
+
return network(input, init);
|
|
196
|
+
};
|
|
197
|
+
const model = config.model({ fetch: counted, mode, purpose: 'agent' });
|
|
198
|
+
const judgeModel = (config.judge ?? config.model)({ fetch: counted, mode, purpose: 'judge' });
|
|
199
|
+
// Each tool runs only as its stub says: an eval never reaches a real backend.
|
|
200
|
+
let currentTurn = -1;
|
|
201
|
+
const stubbed = async (tool, args, call) => {
|
|
202
|
+
for (const cases of [scenario.stubs?.[tool.name], suite.stubs?.[tool.name]]) {
|
|
203
|
+
const hit = cases?.find((c) => c.when === undefined || holdsSubset(args, c.when));
|
|
204
|
+
if (hit)
|
|
205
|
+
return hit.result;
|
|
206
|
+
}
|
|
207
|
+
return (await config.stubs?.[tool.name]?.(args, { channel, scenario, tool: tool.name, call })) ?? null;
|
|
208
|
+
};
|
|
209
|
+
const wrap = (tool) => ({
|
|
210
|
+
...tool,
|
|
211
|
+
async execute(args, call) {
|
|
212
|
+
const answer = await stubbed(tool, args, call);
|
|
213
|
+
if (answer)
|
|
214
|
+
return answer;
|
|
215
|
+
fail(currentTurn, 'stub', `the agent called ${tool.name} with ${JSON.stringify(args)}, and no stub answers that call`);
|
|
216
|
+
return { success: false, error: `[agent-evals] ${tool.name} has no stub for this call; nothing was run` };
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
// The realtime server and the product's store, in memory.
|
|
220
|
+
const emit = createMemoryEmit();
|
|
221
|
+
const approvals = createMemoryApprovalStore();
|
|
222
|
+
const stops = createMemoryStops();
|
|
223
|
+
const history = [];
|
|
224
|
+
let snapshot = [];
|
|
225
|
+
let stored = [];
|
|
226
|
+
const runner = createAgentTurnRunner({
|
|
227
|
+
...agentParts(agent),
|
|
228
|
+
tools: async ({ turnId }) => (await resolveTools(turnId)).map(wrap),
|
|
229
|
+
model,
|
|
230
|
+
...(config.promptCacheBreakpoint ? { promptCacheBreakpoint: config.promptCacheBreakpoint } : {}),
|
|
231
|
+
realtime: { url: NOWHERE, apiKey: 'agent-evals', emit },
|
|
232
|
+
uiActions: { channel: NO_PAGE },
|
|
233
|
+
approvals: {
|
|
234
|
+
store: approvals,
|
|
235
|
+
...(agent.approvals?.preview ? { preview: agent.approvals.preview } : {}),
|
|
236
|
+
...(agent.approvals?.validateBeforeApproval ? { validateBeforeApproval: agent.approvals.validateBeforeApproval } : {}),
|
|
237
|
+
},
|
|
238
|
+
stops: { client: stops },
|
|
239
|
+
getDb: async () => null,
|
|
240
|
+
getHistory: async () => snapshot,
|
|
241
|
+
persistMessages: async ({ messages, stopped }) => {
|
|
242
|
+
stored.push({ messages, ...(stopped ? { stopped } : {}) });
|
|
243
|
+
history.push(...historyOf(messages));
|
|
244
|
+
},
|
|
245
|
+
logger: QUIET,
|
|
246
|
+
});
|
|
247
|
+
const runTurn = async (index, kind, payload) => {
|
|
248
|
+
currentTurn = index;
|
|
249
|
+
const turnId = `${conversationId}-${index}`;
|
|
250
|
+
snapshot = [...history];
|
|
251
|
+
if (kind === 'user')
|
|
252
|
+
history.push({ role: 'user', content: payload.content });
|
|
253
|
+
stored = [];
|
|
254
|
+
const before = modelRequests;
|
|
255
|
+
const outcome = await runner.run({
|
|
256
|
+
turnId,
|
|
257
|
+
conversationId,
|
|
258
|
+
...customer,
|
|
259
|
+
socketRoom: `eval:turn:${turnId}`,
|
|
260
|
+
content: payload.content,
|
|
261
|
+
context: kind === 'user' ? context : sharedContext,
|
|
262
|
+
channel: approvalChannel,
|
|
263
|
+
...(payload.approval ? { approval: payload.approval } : {}),
|
|
264
|
+
});
|
|
265
|
+
const messages = stored.flatMap((s) => s.messages);
|
|
266
|
+
const asked = emit.events.find((e) => e.event === AGENT_SOCKET_EVENTS.APPROVAL_REQUIRED && e.data.turnId === turnId);
|
|
267
|
+
const pending = asked ? approvals.asked.find((a) => a.approvalId === asked.data.approvalId) : undefined;
|
|
268
|
+
const stopReason = outcome.status === 'stopped' ? outcome.stopReason : undefined;
|
|
269
|
+
const record = {
|
|
270
|
+
turn: index,
|
|
271
|
+
kind,
|
|
272
|
+
customer: payload.content,
|
|
273
|
+
reply: replyOf(messages),
|
|
274
|
+
toolCalls: messages.flatMap((m) => (m.toolCalls ?? []).map((c) => ({ name: c.name, args: c.arguments }))),
|
|
275
|
+
approval: pending ? { tool: pending.tool, args: pending.args, preview: pending.preview } : null,
|
|
276
|
+
held: stopReason === 'taken_over' && modelRequests === before,
|
|
277
|
+
modelRequests: modelRequests - before,
|
|
278
|
+
outcome: outcome.status,
|
|
279
|
+
...(stopReason ? { stopReason } : {}),
|
|
280
|
+
};
|
|
281
|
+
if (outcome.status === 'failed')
|
|
282
|
+
fail(index, 'turn', `the turn failed: ${outcome.error.code} ${outcome.error.message}`);
|
|
283
|
+
turns.push(record);
|
|
284
|
+
return { record, stored: storedText(messages) };
|
|
285
|
+
};
|
|
286
|
+
try {
|
|
287
|
+
let held = null;
|
|
288
|
+
for (const [index, turn] of scenario.turns.entries()) {
|
|
289
|
+
if ('staff' in turn) {
|
|
290
|
+
const action = turn.staff;
|
|
291
|
+
if ('takeOver' in action) {
|
|
292
|
+
const { displayName, role, userId } = action.takeOver;
|
|
293
|
+
held = { userId: userId ?? `staff-${displayName.toLowerCase().replace(/[^a-z0-9]+/g, '-')}`, displayName, ...(role ? { role } : {}) };
|
|
294
|
+
stops.hold(conversationId, held);
|
|
295
|
+
history.push({ role: 'staff', speaker: held, content: null, takeover: 'taken_over' });
|
|
296
|
+
}
|
|
297
|
+
else if ('say' in action) {
|
|
298
|
+
history.push({ role: 'staff', speaker: held, content: action.say });
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
stops.release(conversationId);
|
|
302
|
+
history.push({ role: 'staff', speaker: held, content: null, takeover: 'handed_back' });
|
|
303
|
+
held = null;
|
|
304
|
+
}
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
let ran;
|
|
308
|
+
if ('user' in turn) {
|
|
309
|
+
ran = await runTurn(index, 'user', { content: turn.user });
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
const waiting = turns.at(-1)?.approval ? approvals.asked.at(-1) : undefined;
|
|
313
|
+
if (!waiting) {
|
|
314
|
+
fail(index, 'scenario', `the customer answers an approval, but the turn before asked for none`);
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
const decided = approvals.answer(waiting.approvalId, { userId: customer.userId, decision: turn.approval, channel: approvalChannel });
|
|
318
|
+
if (!decided.ok) {
|
|
319
|
+
fail(index, 'scenario', `the approval of ${waiting.tool} could not be decided: ${decided.reason}`);
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
ran = await runTurn(index, 'approval', {
|
|
323
|
+
content: '',
|
|
324
|
+
approval: turn.approval === 'approve'
|
|
325
|
+
? { approvalId: waiting.approvalId, decision: 'approve', token: decided.decision === 'approve' ? decided.token : '' }
|
|
326
|
+
: { approvalId: waiting.approvalId, decision: 'decline' },
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
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);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
catch (err) {
|
|
335
|
+
fail(currentTurn, 'turn', `the run stopped: ${err instanceof Error ? err.message : String(err)}`);
|
|
336
|
+
}
|
|
337
|
+
// Replayed, the run asks exactly what was recorded: fewer requests is a run that went another way.
|
|
338
|
+
if (mode === 'replay' && failures.length === 0 && modelRequests !== recorded) {
|
|
339
|
+
fail(-1, 'recording', `the recording holds ${recorded} model responses and the run asked for ${modelRequests}: record it again with \`agent-evals --record\``);
|
|
340
|
+
}
|
|
341
|
+
if (mode === 'record') {
|
|
342
|
+
writeCassette(path, {
|
|
343
|
+
version: CASSETTE_VERSION,
|
|
344
|
+
suite: suite.name,
|
|
345
|
+
scenario: scenario.id,
|
|
346
|
+
channel,
|
|
347
|
+
model: describeModel(model),
|
|
348
|
+
recordedAt: new Date().toISOString(),
|
|
349
|
+
fingerprint: configured,
|
|
350
|
+
exchanges,
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
return result();
|
|
354
|
+
}
|
|
355
|
+
// ─── Checking a turn ────────────────────────────────────────────────────────
|
|
356
|
+
/** A turn's general expectation and its channel's, as one: lists joined, the channel's single values winning. */
|
|
357
|
+
export function mergeExpectations(general, channel) {
|
|
358
|
+
if (!general)
|
|
359
|
+
return channel ?? {};
|
|
360
|
+
if (!channel)
|
|
361
|
+
return general;
|
|
362
|
+
const lists = ['says', 'mustNotSay', 'toolCalled', 'toolNotCalled', 'doesNotStore'];
|
|
363
|
+
const merged = { ...general, ...channel };
|
|
364
|
+
for (const key of lists) {
|
|
365
|
+
const joined = [...(general[key] ?? []), ...(channel[key] ?? [])];
|
|
366
|
+
if (joined.length > 0)
|
|
367
|
+
merged[key] = joined;
|
|
368
|
+
}
|
|
369
|
+
return merged;
|
|
370
|
+
}
|
|
371
|
+
/** Whether a matcher matches `text`; a rubric is put to the judge. */
|
|
372
|
+
async function matches(matcher, text, record, judgeModel) {
|
|
373
|
+
if (typeof matcher === 'object' && 'rubric' in matcher) {
|
|
374
|
+
const verdict = await judge(judgeModel, matcher.rubric, record.customer, text);
|
|
375
|
+
return 'error' in verdict ? verdict : { matched: verdict.pass, why: verdict.reason };
|
|
376
|
+
}
|
|
377
|
+
return { matched: matchesText(matcher, text) };
|
|
378
|
+
}
|
|
379
|
+
const quoted = (text) => JSON.stringify(text.length > 400 ? `${text.slice(0, 400)}…` : text);
|
|
380
|
+
/** Every way a turn breaks its expectation. */
|
|
381
|
+
export async function check(expect, record, stored, judgeModel) {
|
|
382
|
+
const out = [];
|
|
383
|
+
const reply = record.reply;
|
|
384
|
+
const textAssertion = async (assertion, matcher, text, want, what) => {
|
|
385
|
+
const got = await matches(matcher, text, record, judgeModel);
|
|
386
|
+
if ('error' in got) {
|
|
387
|
+
out.push({ assertion, message: `${describeMatcher(matcher)} could not be judged: ${got.error}` });
|
|
388
|
+
}
|
|
389
|
+
else if (got.matched !== want) {
|
|
390
|
+
out.push({
|
|
391
|
+
assertion,
|
|
392
|
+
message: `${what} ${want ? 'does not match' : 'matches'} ${describeMatcher(matcher)}${got.why ? ` (judge: ${got.why})` : ''}: ${quoted(text)}`,
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
for (const matcher of expect.says ?? [])
|
|
397
|
+
await textAssertion('says', matcher, reply, true, 'the reply');
|
|
398
|
+
for (const matcher of expect.mustNotSay ?? [])
|
|
399
|
+
await textAssertion('mustNotSay', matcher, reply, false, 'the reply');
|
|
400
|
+
if (expect.refusal !== undefined) {
|
|
401
|
+
await textAssertion('refusal', expect.refusal === true ? DEFAULT_REFUSAL : expect.refusal, reply, true, 'the reply, as a refusal,');
|
|
402
|
+
}
|
|
403
|
+
for (const matcher of expect.doesNotStore ?? [])
|
|
404
|
+
await textAssertion('doesNotStore', matcher, stored, false, 'what the turn stored');
|
|
405
|
+
const calls = record.toolCalls;
|
|
406
|
+
const callsText = calls.length ? calls.map((c) => `${c.name} ${JSON.stringify(c.args)}`).join('; ') : 'no tool';
|
|
407
|
+
for (const wanted of expect.toolCalled ?? []) {
|
|
408
|
+
const hit = calls.some((c) => c.name === wanted.name && (wanted.args === undefined || holdsSubset(c.args, wanted.args)));
|
|
409
|
+
if (!hit) {
|
|
410
|
+
out.push({
|
|
411
|
+
assertion: 'toolCalled',
|
|
412
|
+
message: `${wanted.name}${wanted.args ? ` with ${JSON.stringify(wanted.args)}` : ''} was not called; the agent called ${callsText}`,
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
for (const name of expect.toolNotCalled ?? []) {
|
|
417
|
+
const hit = name === '*' ? calls.length > 0 : calls.some((c) => c.name === name);
|
|
418
|
+
if (hit)
|
|
419
|
+
out.push({ assertion: 'toolNotCalled', message: `${name === '*' ? 'a tool' : name} was called: ${callsText}` });
|
|
420
|
+
}
|
|
421
|
+
if (expect.approvalRequested === false) {
|
|
422
|
+
if (record.approval)
|
|
423
|
+
out.push({ assertion: 'approvalRequested', message: `the turn stopped for approval of ${record.approval.tool}` });
|
|
424
|
+
}
|
|
425
|
+
else if (expect.approvalRequested) {
|
|
426
|
+
const wanted = expect.approvalRequested;
|
|
427
|
+
const asked = record.approval;
|
|
428
|
+
if (!asked) {
|
|
429
|
+
out.push({ assertion: 'approvalRequested', message: `the turn did not stop for an approval; the agent called ${callsText}` });
|
|
430
|
+
}
|
|
431
|
+
else {
|
|
432
|
+
if (wanted.tool && asked.tool !== wanted.tool)
|
|
433
|
+
out.push({ assertion: 'approvalRequested', message: `the approval is of ${asked.tool}, not ${wanted.tool}` });
|
|
434
|
+
if (wanted.args && !holdsSubset(asked.args, wanted.args)) {
|
|
435
|
+
out.push({ assertion: 'approvalRequested', message: `the approval is of ${JSON.stringify(asked.args)}, which does not hold ${JSON.stringify(wanted.args)}` });
|
|
436
|
+
}
|
|
437
|
+
if (!asked.preview.readback.trim())
|
|
438
|
+
out.push({ assertion: 'approvalRequested', message: 'the approval has no readback' });
|
|
439
|
+
else if (wanted.readback)
|
|
440
|
+
await textAssertion('approvalRequested', wanted.readback, asked.preview.readback, true, 'the readback');
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
if (expect.held !== undefined && record.held !== expect.held) {
|
|
444
|
+
out.push({
|
|
445
|
+
assertion: 'held',
|
|
446
|
+
message: expect.held
|
|
447
|
+
? `the turn ran (${record.modelRequests} model request${record.modelRequests === 1 ? '' : 's'}, ${record.stopReason ?? record.outcome}): it should not have, while a person held the conversation`
|
|
448
|
+
: 'the turn did not run: a person held the conversation',
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
return out;
|
|
452
|
+
}
|
|
453
|
+
//# sourceMappingURL=run.js.map
|
package/dist/run.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EACL,mBAAmB,GAKpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,qBAAqB,EACrB,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,eAAe,GAOhB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,cAAc,EAAyB,MAAM,+BAA+B,CAAC;AAGtG,OAAO,EAAE,gBAAgB,EA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+1,17 @@
|
|
|
1
|
+
import type { AgentEvalSuite } from '@ouispec/contract';
|
|
2
|
+
/** A suite that cannot be run, with every reason. */
|
|
3
|
+
export declare class EvalSuiteError extends Error {
|
|
4
|
+
readonly source: string;
|
|
5
|
+
readonly problems: readonly string[];
|
|
6
|
+
constructor(source: string, problems: readonly string[]);
|
|
7
|
+
}
|
|
8
|
+
/** Parse a suite file: `.json`, or `.yaml`/`.yml`. */
|
|
9
|
+
export declare function readSuiteFile(path: string): unknown;
|
|
10
|
+
/**
|
|
11
|
+
* The suite, checked: the contract's schema, then the rules it cannot state.
|
|
12
|
+
* `channels` is the configuration's: every channel a suite names must be one.
|
|
13
|
+
*/
|
|
14
|
+
export declare function checkSuite(value: unknown, source: string, channels: readonly string[]): AgentEvalSuite;
|
|
15
|
+
/** Every rubric a suite's scenario asks a judge about: what its recordings were made answering. */
|
|
16
|
+
export declare function rubricsOf(scenario: AgentEvalSuite['scenarios'][number]): string[];
|
|
17
|
+
//# sourceMappingURL=suite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suite.d.ts","sourceRoot":"","sources":["../src/suite.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAwB,cAAc,EAAwB,MAAM,mBAAmB,CAAC;AAGpG,qDAAqD;AACrD,qBAAa,cAAe,SAAQ,KAAK;IAErC,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE;gBAD3B,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,SAAS,MAAM,EAAE;CAKvC;AAED,sDAAsD;AACtD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAMnD;AAmBD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,cAAc,CA4DtG;AAED,mGAAmG;AACnG,wBAAgB,SAAS,CAAC,QAAQ,EAAE,cAAc,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,CAIjF"}
|
package/dist/suite.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading a suite: a JSON or YAML file, held to the
|
|
3
|
+
* contract's `agent-evals.json`, then to what a schema cannot say: unique
|
|
4
|
+
* scenario ids, channels the configuration serves, regular expressions that
|
|
5
|
+
* compile, an approval answered only after a turn could have asked for one,
|
|
6
|
+
* and staff who take a conversation before they write in it.
|
|
7
|
+
*
|
|
8
|
+
* Every problem is reported at once, each with where it is.
|
|
9
|
+
*/
|
|
10
|
+
import { readFileSync } from 'node:fs';
|
|
11
|
+
import { extname } from 'node:path';
|
|
12
|
+
import { parse as parseYaml } from 'yaml';
|
|
13
|
+
import { contractProblems } from '@ouispec/contract/validate';
|
|
14
|
+
/** A suite that cannot be run, with every reason. */
|
|
15
|
+
export class EvalSuiteError extends Error {
|
|
16
|
+
source;
|
|
17
|
+
problems;
|
|
18
|
+
constructor(source, problems) {
|
|
19
|
+
super(`${source} is not a suite agent-evals can run:\n${problems.map((p) => ` - ${p}`).join('\n')}`);
|
|
20
|
+
this.source = source;
|
|
21
|
+
this.problems = problems;
|
|
22
|
+
this.name = 'EvalSuiteError';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** Parse a suite file: `.json`, or `.yaml`/`.yml`. */
|
|
26
|
+
export function readSuiteFile(path) {
|
|
27
|
+
const text = readFileSync(path, 'utf8');
|
|
28
|
+
const ext = extname(path).toLowerCase();
|
|
29
|
+
if (ext === '.json')
|
|
30
|
+
return JSON.parse(text);
|
|
31
|
+
if (ext === '.yaml' || ext === '.yml')
|
|
32
|
+
return parseYaml(text);
|
|
33
|
+
throw new EvalSuiteError(path, [`a suite is a .json, .yaml or .yml file, not ${ext || 'a file with no extension'}`]);
|
|
34
|
+
}
|
|
35
|
+
const matchersOf = (expect) => {
|
|
36
|
+
if (!expect)
|
|
37
|
+
return [];
|
|
38
|
+
const out = [...(expect.says ?? []), ...(expect.mustNotSay ?? []), ...(expect.doesNotStore ?? [])];
|
|
39
|
+
if (expect.refusal && expect.refusal !== true)
|
|
40
|
+
out.push(expect.refusal);
|
|
41
|
+
if (expect.approvalRequested && expect.approvalRequested.readback)
|
|
42
|
+
out.push(expect.approvalRequested.readback);
|
|
43
|
+
return out;
|
|
44
|
+
};
|
|
45
|
+
/** Every expectation of a turn, the general one and each channel's. */
|
|
46
|
+
function expectationsOf(turn) {
|
|
47
|
+
if ('staff' in turn)
|
|
48
|
+
return [];
|
|
49
|
+
return [
|
|
50
|
+
...(turn.expect ? [['expect', turn.expect]] : []),
|
|
51
|
+
...Object.entries(turn.expectOn ?? {}).map(([channel, e]) => [`expectOn/${channel}`, e]),
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The suite, checked: the contract's schema, then the rules it cannot state.
|
|
56
|
+
* `channels` is the configuration's: every channel a suite names must be one.
|
|
57
|
+
*/
|
|
58
|
+
export function checkSuite(value, source, channels) {
|
|
59
|
+
const structural = contractProblems('agent-evals.json', value);
|
|
60
|
+
if (structural.length > 0)
|
|
61
|
+
throw new EvalSuiteError(source, structural);
|
|
62
|
+
const suite = value;
|
|
63
|
+
const problems = [];
|
|
64
|
+
const known = new Set(channels);
|
|
65
|
+
const unknownChannels = (at, names) => {
|
|
66
|
+
for (const name of names ?? []) {
|
|
67
|
+
if (!known.has(name))
|
|
68
|
+
problems.push(`${at}: channel "${name}" is not one the configuration serves (${channels.join(', ') || 'none'})`);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
unknownChannels('/channels', suite.channels);
|
|
72
|
+
const suiteChannels = new Set(suite.channels ?? channels);
|
|
73
|
+
const ids = new Set();
|
|
74
|
+
suite.scenarios.forEach((scenario, s) => {
|
|
75
|
+
const at = `/scenarios/${s} (${scenario.id})`;
|
|
76
|
+
if (ids.has(scenario.id))
|
|
77
|
+
problems.push(`${at}: the id "${scenario.id}" is used twice`);
|
|
78
|
+
ids.add(scenario.id);
|
|
79
|
+
unknownChannels(`${at}/channels`, scenario.channels);
|
|
80
|
+
for (const name of scenario.channels ?? []) {
|
|
81
|
+
if (known.has(name) && !suiteChannels.has(name))
|
|
82
|
+
problems.push(`${at}/channels: "${name}" is not one of the suite's channels`);
|
|
83
|
+
}
|
|
84
|
+
let held = false;
|
|
85
|
+
let agentTurns = 0;
|
|
86
|
+
scenario.turns.forEach((turn, t) => {
|
|
87
|
+
const here = `${at}/turns/${t}`;
|
|
88
|
+
for (const [where, expectation] of expectationsOf(turn)) {
|
|
89
|
+
if (where.startsWith('expectOn/'))
|
|
90
|
+
unknownChannels(`${here}/${where}`, [where.slice('expectOn/'.length)]);
|
|
91
|
+
for (const matcher of matchersOf(expectation)) {
|
|
92
|
+
if (typeof matcher === 'object' && 'pattern' in matcher) {
|
|
93
|
+
try {
|
|
94
|
+
new RegExp(matcher.pattern, matcher.flags);
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
problems.push(`${here}/${where}: /${matcher.pattern}/ is not a regular expression: ${err instanceof Error ? err.message : String(err)}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if ('user' in turn)
|
|
103
|
+
agentTurns += 1;
|
|
104
|
+
else if ('approval' in turn) {
|
|
105
|
+
if (agentTurns === 0)
|
|
106
|
+
problems.push(`${here}: an approval is answered before any turn could have asked for one`);
|
|
107
|
+
agentTurns += 1;
|
|
108
|
+
}
|
|
109
|
+
else if ('takeOver' in turn.staff) {
|
|
110
|
+
if (held)
|
|
111
|
+
problems.push(`${here}: the conversation is already held`);
|
|
112
|
+
held = true;
|
|
113
|
+
}
|
|
114
|
+
else if ('say' in turn.staff) {
|
|
115
|
+
if (!held)
|
|
116
|
+
problems.push(`${here}: a person writes before anyone has taken the conversation over`);
|
|
117
|
+
}
|
|
118
|
+
else if (!held) {
|
|
119
|
+
problems.push(`${here}: the conversation is handed back while nobody holds it`);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
held = false;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
if (agentTurns === 0)
|
|
126
|
+
problems.push(`${at}: it has no turn of the agent's to check`);
|
|
127
|
+
});
|
|
128
|
+
if (problems.length > 0)
|
|
129
|
+
throw new EvalSuiteError(source, problems);
|
|
130
|
+
return suite;
|
|
131
|
+
}
|
|
132
|
+
/** Every rubric a suite's scenario asks a judge about: what its recordings were made answering. */
|
|
133
|
+
export function rubricsOf(scenario) {
|
|
134
|
+
return scenario.turns.flatMap((turn) => expectationsOf(turn).flatMap(([, e]) => matchersOf(e).flatMap((m) => (typeof m === 'object' && 'rubric' in m ? [m.rubric] : []))));
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=suite.js.map
|