@tangle-network/agent-bench 6.0.0 → 7.0.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.
@@ -27,7 +27,7 @@ import type {
27
27
  AgentCandidateExecutorRequest,
28
28
  } from '@tangle-network/agent-runtime/candidate-execution'
29
29
 
30
- import type { TraceStore } from '@tangle-network/agent-eval'
30
+ import { canonicalJson, type TraceStore } from '@tangle-network/agent-eval'
31
31
 
32
32
  import type {
33
33
  PierCandidateTerminationAcknowledgement,
@@ -107,6 +107,8 @@ export interface FilePierCandidateTrialControllerOptions<
107
107
  readonly directory: string
108
108
  /** Both the registered launch and durable result reader handle sealed graph dispatch. */
109
109
  readonly graphDispatch?: true
110
+ /** Registered graph dispatch can start the signed profile as a leaf. */
111
+ readonly graphLeafDispatch?: true
110
112
  readonly launch?: (
111
113
  staged: StagedPierCandidateExecution,
112
114
  context: {
@@ -139,8 +141,10 @@ export interface CreatePierTaskTrialControllerOptions {
139
141
  readonly prefix?: readonly string[]
140
142
  }
141
143
  readonly dockerConnection?: PierDockerConnection
142
- /** Allow the bundled graph coordinator for the approved zero-model task cohort. */
144
+ /** Allow the bundled graph coordinator for approved tasks. */
143
145
  readonly graphDispatch?: true
146
+ /** Allow the signed process launch to run once as the admitted graph leaf. */
147
+ readonly graphLeafDispatch?: true
144
148
  }
145
149
 
146
150
  /** Run one approved Pier task and reopen its official result through the durable controller. */
@@ -169,13 +173,20 @@ export function createPierTaskTrialController<
169
173
  directory: options.directory,
170
174
  dockerConnection: options.dockerConnection,
171
175
  ...(options.graphDispatch ? { graphDispatch: true } : {}),
176
+ ...(options.graphLeafDispatch ? { graphLeafDispatch: true } : {}),
172
177
  readResult,
173
178
  launch(staged, { request }) {
174
179
  const task = tasks.get(request.benchmark.task.digest)
175
180
  if (!task) throw new Error('Pier has no directory for this approved task')
176
181
  assertRealDirectory(task, 'Pier task directory')
177
182
  if (staged.graphInvocationPath && request.benchmark.task.limits.maxModelCalls !== 0) {
178
- throw new Error('The bundled Pier graph coordinator requires a zero-model task')
183
+ const { limits, model } = request.executionPlan.value.material
184
+ if (
185
+ !options.graphLeafDispatch || limits.maxCostUsd !== 0 ||
186
+ model.access.network.mode !== 'gateway-only' || model.access.network.domains.length !== 1
187
+ ) {
188
+ throw new Error('A model-backed Pier graph requires an admitted profile leaf and a zero-cost gateway grant')
189
+ }
179
190
  }
180
191
  const jobName = `candidate-${trialKey({
181
192
  executionId: request.executionId,
@@ -192,6 +203,7 @@ export function createPierTaskTrialController<
192
203
  '--agent-kwarg', `graph_invocation_path=${staged.graphInvocationPath}`,
193
204
  '--agent-kwarg', `graph_node_path=${process.execPath}`,
194
205
  '--agent-kwarg', `graph_driver_path=${graphDriver}`,
206
+ ...(options.graphLeafDispatch ? ['--agent-kwarg', 'graph_leaf_dispatch=true'] : []),
195
207
  ]
196
208
  : []),
197
209
  ...staged.attemptArgs,
@@ -238,17 +250,21 @@ function readOfficialTrial(directory: string, maxEvidenceBytes: number): PierCan
238
250
  function readOfficialGraph(
239
251
  value: unknown,
240
252
  patch: Uint8Array,
241
- ): Pick<PierCandidateTrialResult, 'graphExecution' | 'graphDelivered'> {
253
+ ): Pick<PierCandidateTrialResult, 'graphExecution' | 'graphDelivered' | 'nativeEvidence'> {
242
254
  const raw = (value as {
243
255
  agent_result?: { metadata?: { graphExecution?: unknown } }
244
256
  }).agent_result?.metadata?.graphExecution
245
257
  if (raw === undefined) return {}
258
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
259
+ throw new Error('Pier emitted invalid evaluator graph evidence')
260
+ }
246
261
  const graph = raw as {
247
262
  runId: string
248
263
  graphDigest: `sha256:${string}`
249
264
  invocationDigest: `sha256:${string}`
250
265
  record: string
251
266
  delivered: boolean
267
+ nativeEvidence?: Record<string, unknown>
252
268
  }
253
269
  if (
254
270
  typeof graph.runId !== 'string' ||
@@ -266,6 +282,15 @@ function readOfficialGraph(
266
282
  }
267
283
  return {
268
284
  graphDelivered: graph.delivered,
285
+ ...(graph.nativeEvidence ? {
286
+ nativeEvidence: Buffer.from(canonicalJson({
287
+ ...graph.nativeEvidence,
288
+ kind: 'pier-native-graph-leaf',
289
+ runId: graph.runId,
290
+ graphDigest: graph.graphDigest,
291
+ invocationDigest: graph.invocationDigest,
292
+ })),
293
+ } : {}),
269
294
  graphExecution: {
270
295
  runId: graph.runId,
271
296
  graphDigest: graph.graphDigest,
@@ -679,6 +704,7 @@ export class FilePierCandidateTrialController<
679
704
  Format extends AgentCandidateExecutionFormat = 'experiment',
680
705
  > implements PierCandidateTrialController<Format> {
681
706
  readonly graphDispatch?: true
707
+ readonly graphLeafDispatch?: true
682
708
  private readonly directory: string
683
709
  private readonly launch?: NonNullable<FilePierCandidateTrialControllerOptions<Format>['launch']>
684
710
  private readonly readResult?: NonNullable<FilePierCandidateTrialControllerOptions<Format>['readResult']>
@@ -693,7 +719,11 @@ export class FilePierCandidateTrialController<
693
719
  if (options.graphDispatch && (!options.launch || !options.readResult)) {
694
720
  throw new Error('Pier graph dispatch requires both launch and durable graph capture')
695
721
  }
722
+ if (options.graphLeafDispatch && !options.graphDispatch) {
723
+ throw new Error('A protected Pier profile leaf requires graph dispatch')
724
+ }
696
725
  this.graphDispatch = options.graphDispatch
726
+ this.graphLeafDispatch = options.graphLeafDispatch
697
727
  const configuredDocker = options.dockerConnection
698
728
  if (configuredDocker?.id === defaultDockerConnectionId) {
699
729
  throw new Error(`${defaultDockerConnectionId} is reserved for the implicit local connection`)