@tangle-network/agent-bench 4.0.0 → 4.0.3

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.
@@ -14,12 +14,16 @@ import { tmpdir } from 'node:os'
14
14
  import path from 'node:path'
15
15
  import test from 'node:test'
16
16
  import { validateRunRecord } from '@tangle-network/agent-eval'
17
- import { runPublished, PUBLISHED_BENCHMARKS } from './published'
17
+ import { runPublished, PUBLISHED_BENCHMARKS, type PublishedRun } from './published'
18
18
 
19
19
  const TASK = 'simple.email_sf_contact_phone_update'
20
20
  let uv = true
21
21
  try { execFileSync('uv', ['--version'], { stdio: 'ignore' }) } catch { uv = false }
22
22
 
23
+ function assertGoldTask({ taskScores }: PublishedRun) {
24
+ assert.deepEqual(taskScores.map(({ id, passed, score }) => ({ id, passed, score })), [{ id: TASK, passed: true, score: 1 }])
25
+ }
26
+
23
27
  /** One chat-completions answer: the gold tool call first, then a closing message; or a closing message alone. */
24
28
  function standIn(gold: boolean) {
25
29
  const requests: Array<{ tools: number; messages: number }> = []
@@ -62,7 +66,8 @@ async function run(gold: boolean, cacheDir: string) {
62
66
  env: { AGENT_BENCH_ROUTER_URL: `http://127.0.0.1:${(server.address() as AddressInfo).port}/v1`, TANGLE_API_KEY: 'local-stand-in' },
63
67
  })
64
68
  const runRecords = (await readFile(result.runRecords, 'utf8')).trim().split('\n').map((line) => JSON.parse(line) as Record<string, unknown>)
65
- return { result, requests, record: JSON.parse(await readFile(path.join(out, 'automationbench-run.json'), 'utf8')), runRecords }
69
+ const publisher = JSON.parse(await readFile(result.resultPath, 'utf8'))
70
+ return { result, requests, record: JSON.parse(await readFile(path.join(out, 'automationbench-run.json'), 'utf8')), runRecords, publisher }
66
71
  } finally {
67
72
  server.close()
68
73
  await rm(out, { recursive: true, force: true })
@@ -74,7 +79,7 @@ test('AutomationBench: the publisher\'s grader passes the gold tool call and fai
74
79
  try {
75
80
  const gold = await run(true, cacheDir)
76
81
  assert.equal(gold.result.tasks, 1)
77
- assert.deepEqual(gold.result.taskScores, [{ id: TASK, passed: true, score: 1 }])
82
+ assertGoldTask(gold.result)
78
83
  assert.equal(gold.result.measured, 'model-shaped')
79
84
  assert.equal(gold.result.official, true)
80
85
  assert.equal(gold.result.ref, PUBLISHED_BENCHMARKS.automationbench!.ref)
@@ -89,6 +94,12 @@ test('AutomationBench: the publisher\'s grader passes the gold tool call and fai
89
94
  assert.equal(row.outcome.raw.passed, 1)
90
95
  assert.equal(row.candidateId, 'model:stand-in-model')
91
96
  assert.deepEqual([row.model, row.terminalOutcome, row.costUsd], ['unknown', 'unknown', null])
97
+ const publisher = gold.publisher.tasks[0]
98
+ assert.ok(publisher.input_tokens > 0 && publisher.output_tokens > 0)
99
+ assert.equal(row.outcome.raw.publisherInputTokens, publisher.input_tokens)
100
+ assert.equal(row.outcome.raw.publisherOutputTokens, publisher.output_tokens)
101
+ assert.equal(row.outcome.raw.publisherEstimatedCostUsd, publisher.cost)
102
+ assert.equal(row.tokenUsage.tokensKnown, false)
92
103
 
93
104
  const none = await run(false, cacheDir)
94
105
  assert.equal(none.result.tasks, 1)
@@ -188,12 +199,15 @@ test('AutomationBench on profile and app targets: its runner drives a harness lo
188
199
  }
189
200
  const result = await runPublished('automationbench', 'profile:claude-code/own-loop-peer', { ...options, out: path.join(out, 'profile') })
190
201
  assert.equal(result.measured, 'own-loop')
191
- assert.deepEqual(result.taskScores, [{ id: TASK, passed: true, score: 1 }])
202
+ assertGoldTask(result)
203
+ const [publisherTask] = JSON.parse(await readFile(result.resultPath, 'utf8')).tasks
204
+ assert.equal(result.taskScores[0]?.raw?.publisherInputTokens, publisherTask.input_tokens)
205
+ assert.equal(result.taskScores[0]?.raw?.publisherOutputTokens, publisherTask.output_tokens)
192
206
 
193
207
  const apps = JSON.stringify({ 'bench-app': `http://127.0.0.1:${(appServer.address() as AddressInfo).port}/api/tools/profile?definition` })
194
208
  const app = await runPublished('automationbench', 'app:bench-app@claude-code/app-peer', { ...options, env: { ...options.env, AGENT_BENCH_APPS: apps }, out: path.join(out, 'app') })
195
209
  assert.equal(app.measured, 'own-loop')
196
- assert.deepEqual(app.taskScores, [{ id: TASK, passed: true, score: 1 }])
210
+ assertGoldTask(app)
197
211
  assert.equal(app.model, 'claude-code/app-peer')
198
212
  assert.equal(app.app?.app, 'bench-app')
199
213
  assert.equal(app.app?.profileVersion, '1.0.0')
@@ -205,7 +219,7 @@ test('AutomationBench on profile and app targets: its runner drives a harness lo
205
219
  const file = path.join(root, 'bench-app-profile.json')
206
220
  await writeFile(file, JSON.stringify(served))
207
221
  const fromFile = await runPublished('automationbench', 'app:bench-app@claude-code/app-peer', { ...options, env: { ...options.env, AGENT_BENCH_APPS: JSON.stringify({ 'bench-app': file }) }, out: path.join(out, 'app-file') })
208
- assert.deepEqual(fromFile.taskScores, [{ id: TASK, passed: true, score: 1 }])
222
+ assertGoldTask(fromFile)
209
223
  assert.equal(fromFile.app?.profileDigest, app.app?.profileDigest)
210
224
  assert.equal(fromFile.app?.profileUrl, file)
211
225
  } finally {
@@ -339,6 +353,15 @@ test('Harvey LAB: the publisher\'s harness and rubric grader, with a substituted
339
353
  assert.equal(result.taskScores[0]!.raw?.['crit.C-001'], gold ? 1 : 0)
340
354
  const row = validateRunRecord(JSON.parse((await readFile(result.runRecords, 'utf8')).trim()))
341
355
  assert.equal(row.outcome.raw['crit.C-001'], gold ? 1 : 0)
356
+ const [runId] = (await readFile(path.join(result.resultPath, 'tasks.tsv'), 'utf8')).split('\t')
357
+ assert.ok(runId)
358
+ const metrics = JSON.parse(await readFile(path.join(result.resultPath, runId, 'metrics.json'), 'utf8'))
359
+ assert.ok(metrics.input_tokens > 0 && metrics.output_tokens > 0)
360
+ assert.deepEqual(row.tokenUsage, {
361
+ input: metrics.input_tokens, output: metrics.output_tokens, tokensKnown: false,
362
+ })
363
+ assert.equal(row.outcome.raw.publisherAgentWallMs, metrics.wall_clock_seconds * 1_000)
364
+ assert.equal(row.costUsd, null)
342
365
  } finally {
343
366
  server.closeAllConnections()
344
367
  server.close()
package/src/published.ts CHANGED
@@ -103,6 +103,18 @@ export interface PublishedTaskScore {
103
103
  score: number
104
104
  notes?: string
105
105
  raw?: Record<string, number>
106
+ /** Observed provider counters retained by the publisher. A subtotal keeps tokensKnown false. */
107
+ tokenUsage?: RunRecord['tokenUsage']
108
+ }
109
+
110
+ function nonnegativeCounter(value: unknown): number | undefined {
111
+ return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0
112
+ ? value
113
+ : undefined
114
+ }
115
+
116
+ function nonnegativeMeasurement(value: unknown): number | undefined {
117
+ return typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : undefined
106
118
  }
107
119
 
108
120
  export interface PublishedBenchmark {
@@ -178,13 +190,32 @@ export const PUBLISHED_BENCHMARKS: Readonly<Record<string, PublishedBenchmark>>
178
190
  ...(options.args ?? []),
179
191
  ],
180
192
  parse: async (resultPath) => {
181
- const tasks = (JSON.parse(await readFile(resultPath, 'utf8')) as { tasks?: Array<{ name?: unknown; score?: unknown; passed?: unknown }> }).tasks
193
+ const tasks = (JSON.parse(await readFile(resultPath, 'utf8')) as { tasks?: Array<Record<string, unknown>> }).tasks
182
194
  if (!Array.isArray(tasks)) throw new Error('AutomationBench result has no tasks array')
183
195
  return tasks.map((task) => {
184
196
  if (typeof task.name !== 'string' || typeof task.score !== 'number' || typeof task.passed !== 'boolean') {
185
197
  throw new Error(`AutomationBench task result is malformed: ${JSON.stringify(task).slice(0, 200)}`)
186
198
  }
187
- return { id: task.name, passed: task.passed, score: task.score }
199
+ // This export can fall back to counting text characters. Its pricing is also calculated by
200
+ // the publisher. Keep these fields with the score without attesting provider usage or billing.
201
+ const raw: Record<string, number> = {}
202
+ const counters = {
203
+ publisherInputTokens: task.input_tokens,
204
+ publisherOutputTokens: task.output_tokens,
205
+ publisherCachedInputTokens: task.cached_input_tokens,
206
+ publisherReasoningTokens: task.reasoning_tokens,
207
+ publisherModelCalls: task.num_model_calls,
208
+ }
209
+ for (const [key, counter] of Object.entries(counters)) {
210
+ const value = nonnegativeCounter(counter)
211
+ if (value !== undefined) raw[key] = value
212
+ }
213
+ const estimate = nonnegativeMeasurement(task.cost)
214
+ if (estimate !== undefined) raw.publisherEstimatedCostUsd = estimate
215
+ return {
216
+ id: task.name, passed: task.passed, score: task.score,
217
+ ...(Object.keys(raw).length && { raw }),
218
+ }
188
219
  })
189
220
  },
190
221
  },
@@ -254,17 +285,30 @@ export const PUBLISHED_BENCHMARKS: Readonly<Record<string, PublishedBenchmark>>
254
285
  const runs = (await readFile(path.join(resultPath, 'tasks.tsv'), 'utf8')).trim().split('\n').map((line) => line.split('\t') as [string, string])
255
286
  return Promise.all(runs.map(async ([run, task]) => {
256
287
  const read = (file: string) => readFile(path.join(resultPath, run, file), 'utf8').then((text) => JSON.parse(text) as Record<string, unknown>, () => null)
288
+ const metrics = await read('metrics.json')
289
+ const input = nonnegativeCounter(metrics?.input_tokens)
290
+ const output = nonnegativeCounter(metrics?.output_tokens)
291
+ const agentSeconds = nonnegativeMeasurement(metrics?.wall_clock_seconds)
292
+ const raw = agentSeconds === undefined ? undefined : { publisherAgentWallMs: agentSeconds * 1_000 }
293
+ // The publisher retains supported response counters, without a per-call completeness flag.
294
+ const telemetry: Pick<PublishedTaskScore, 'tokenUsage' | 'raw'> = {
295
+ ...(raw && { raw }),
296
+ ...(input !== undefined && output !== undefined && {
297
+ tokenUsage: { input, output, tokensKnown: false },
298
+ }),
299
+ }
257
300
  const dual = await read('scores_dual.json')
258
- if (dual) return { id: task, passed: dual.all_pass === true, score: Number(dual.dual_all_pass_rate), notes: `dual-judge criterion pass ${String(dual.dual_criterion_pass)}` }
301
+ if (dual) return { id: task, passed: dual.all_pass === true, score: Number(dual.dual_all_pass_rate), notes: `dual-judge criterion pass ${String(dual.dual_criterion_pass)}`, ...telemetry }
259
302
  const single = await read('scores.json')
260
303
  if (single) {
261
304
  const criteria = Array.isArray(single.criteria_results) ? single.criteria_results as Array<{ id?: unknown; verdict?: unknown }> : []
262
305
  return { id: task, passed: single.all_pass === true, score: single.all_pass === true ? 1 : 0,
263
306
  notes: `${String(single.n_passed)} of ${String(single.n_criteria)} criteria passed${single.n_grading_errors ? `; ${String(single.n_grading_errors)} grading errors` : ''}`,
264
- raw: { criteria_passed: Number(single.n_passed) || 0, criteria_total: Number(single.n_criteria) || 0,
307
+ ...telemetry,
308
+ raw: { ...raw, criteria_passed: Number(single.n_passed) || 0, criteria_total: Number(single.n_criteria) || 0,
265
309
  ...Object.fromEntries(criteria.filter((c) => typeof c.id === 'string').map((c) => [`crit.${String(c.id)}`, c.verdict === 'pass' ? 1 : 0])) } }
266
310
  }
267
- return { id: task, passed: false, score: 0, notes: 'no scores: the harness or the grader failed (see the runner log)' }
311
+ return { id: task, passed: false, score: 0, notes: 'no scores: the harness or the grader failed (see the runner log)', ...telemetry }
268
312
  }))
269
313
  },
270
314
  },
@@ -467,8 +511,8 @@ export async function runPublished(name: string, target: string, options: Publis
467
511
  }
468
512
 
469
513
  /**
470
- * One agent-eval RunRecord per task, validated by agent-eval's own validator. The publisher's runner makes the model calls,
471
- * so cost and tokens are uncaptured, never zero. A RunRecord's model must name a served snapshot; a subscription harness
514
+ * One agent-eval RunRecord per task, validated by agent-eval's own validator. Preserve an observed publisher subtotal
515
+ * and leave missing provider bills unknown. A RunRecord's model must name a served snapshot; a subscription harness
472
516
  * reports none, and a snapshot invented from the date would be false, so such rows record `unknown` with terminal outcome
473
517
  * `unknown` and keep the requested model in `candidateId`. A pinned model id (a Router snapshot) is recorded as served.
474
518
  */
@@ -483,7 +527,8 @@ function runRecords(run: PublishedRun, options: PublishedRunOptions): RunRecord[
483
527
  // The publisher owns the prompt; an app run's prompt is its profile.
484
528
  promptHash: run.app?.profileDigest ?? sha(run.target), configHash, commitSha: run.ref,
485
529
  wallMs: Math.max(0, Date.parse(run.finishedAt) - Date.parse(run.startedAt)),
486
- costUsd: null, costProvenance: { kind: 'uncaptured', usd: null }, tokenUsage: { input: 0, output: 0, tokensKnown: false },
530
+ costUsd: null, costProvenance: { kind: 'uncaptured', usd: null },
531
+ tokenUsage: task.tokenUsage ?? { input: 0, output: 0, tokensKnown: false },
487
532
  terminalOutcome: 'succeeded',
488
533
  outcome: { [split === 'holdout' ? 'holdoutScore' : 'searchScore']: task.score, raw: { passed: task.passed ? 1 : 0, ...task.raw } },
489
534
  splitTag: split, scenarioId: `${run.benchmark}:${task.id}`,