@tangle-network/agent-bench 5.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.
- package/CHANGELOG.md +17 -0
- package/HARNESS.md +6 -0
- package/README.md +10 -0
- package/dist/index.d.ts +23 -1
- package/dist/index.js +91 -5
- package/dist/index.js.map +1 -1
- package/package.json +8 -6
- package/pier_agents/candidate_contract.py +42 -14
- package/pier_agents/graph_driver.mjs +244 -0
- package/pier_agents/graph_process.py +344 -0
- package/pier_agents/tangle_candidate.py +120 -16
- package/scripts/verify-packed-consumer.mjs +6 -0
- package/src/pier-agent.test.mts +6 -0
- package/src/pier-agent.ts +60 -2
- package/src/pier-trial-controller.ts +95 -2
- package/src/swe-self-improve.mts +23 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/agent-bench",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Benchmark adapters and execution for agent-runtime across coding, tool-use, RAG, memory, browser, and terminal tasks.",
|
|
6
6
|
"repository": {
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@tangle-network/agent-eval": "^2.0.29",
|
|
32
|
-
"@tangle-network/agent-interface": "^5.10.
|
|
33
|
-
"@tangle-network/agent-knowledge": "^23.0.
|
|
34
|
-
"@tangle-network/agent-runtime": "^
|
|
35
|
-
"@tangle-network/sandbox": "^1.0.
|
|
31
|
+
"@tangle-network/agent-eval": "^2.0.29 || ^3.0.1",
|
|
32
|
+
"@tangle-network/agent-interface": "^5.10.41",
|
|
33
|
+
"@tangle-network/agent-knowledge": "^23.0.9",
|
|
34
|
+
"@tangle-network/agent-runtime": "^15.0.0",
|
|
35
|
+
"@tangle-network/sandbox": "^1.0.813"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@arethetypeswrong/cli": "0.18.5",
|
|
@@ -52,6 +52,8 @@
|
|
|
52
52
|
"scripts",
|
|
53
53
|
"pier_agents/__init__.py",
|
|
54
54
|
"pier_agents/candidate_contract.py",
|
|
55
|
+
"pier_agents/graph_driver.mjs",
|
|
56
|
+
"pier_agents/graph_process.py",
|
|
55
57
|
"pier_agents/process_boundary.py",
|
|
56
58
|
"pier_agents/tangle_candidate.py",
|
|
57
59
|
"pier_agents/workspace_boundary.py",
|
|
@@ -564,6 +564,7 @@ def _verify_plan_envelope(
|
|
|
564
564
|
receipt: dict[str, Any],
|
|
565
565
|
receipt_raw: bytes,
|
|
566
566
|
expected_receipt_digest: str,
|
|
567
|
+
graph_invocation: bytes | None = None,
|
|
567
568
|
) -> tuple[bool, str, str]:
|
|
568
569
|
receipt_digest = _digest(expected_receipt_digest, "expected receipt digest")
|
|
569
570
|
if sha256_bytes(receipt_raw) != receipt_digest:
|
|
@@ -608,21 +609,59 @@ def _verify_plan_envelope(
|
|
|
608
609
|
raise CandidateContractError(
|
|
609
610
|
"receipt execution-plan artifact differs from the executed bytes"
|
|
610
611
|
)
|
|
612
|
+
_verify_graph_invocation(plan, graph_invocation)
|
|
611
613
|
return search, receipt_digest, plan_digest
|
|
612
614
|
|
|
613
615
|
|
|
616
|
+
def _verify_graph_invocation(
|
|
617
|
+
plan: dict[str, Any], graph_invocation: bytes | None
|
|
618
|
+
) -> None:
|
|
619
|
+
launch = _object(plan.get("launch"), "plan.launch")
|
|
620
|
+
if "graph" not in launch and graph_invocation is None:
|
|
621
|
+
return
|
|
622
|
+
if graph_invocation is None:
|
|
623
|
+
raise CandidateContractError(
|
|
624
|
+
"this Pier process adapter cannot execute a sealed graph invocation"
|
|
625
|
+
)
|
|
626
|
+
graph = _object(launch.get("graph"), "plan.launch.graph")
|
|
627
|
+
invocation = _object(graph.get("invocation"), "plan.launch.graph.invocation")
|
|
628
|
+
if (
|
|
629
|
+
len(graph_invocation) != _integer(invocation.get("byteLength"), "graph invocation length")
|
|
630
|
+
or sha256_bytes(graph_invocation) != _digest(invocation.get("sha256"), "graph invocation digest")
|
|
631
|
+
):
|
|
632
|
+
raise CandidateContractError("graph invocation bytes differ from the sealed plan")
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
def _verified_model_binding(
|
|
636
|
+
plan: dict[str, Any],
|
|
637
|
+
receipt: dict[str, Any],
|
|
638
|
+
task: dict[str, Any],
|
|
639
|
+
max_model_calls: int,
|
|
640
|
+
) -> tuple[str, dict[str, Any], tuple[str, ...]]:
|
|
641
|
+
model = _object(plan.get("model"), "plan.model")
|
|
642
|
+
resolved = _object(model.get("resolved"), "plan.model.resolved")
|
|
643
|
+
requested = _string(resolved.get("requested"), "plan.model.resolved.requested")
|
|
644
|
+
_string(resolved.get("provider"), "plan.model.resolved.provider")
|
|
645
|
+
_string(resolved.get("model"), "plan.model.resolved.model")
|
|
646
|
+
_string(resolved.get("snapshot"), "plan.model.resolved.snapshot")
|
|
647
|
+
if receipt.get("resolvedModel") != resolved or task.get("model") != resolved:
|
|
648
|
+
raise CandidateContractError("receipt and plan resolved models differ")
|
|
649
|
+
return requested, resolved, _model_network_domains(model, max_model_calls)
|
|
650
|
+
|
|
651
|
+
|
|
614
652
|
def load_prepared_candidate_contract(
|
|
615
653
|
plan_path: Path,
|
|
616
654
|
receipt_path: Path,
|
|
617
655
|
expected_receipt_digest: str,
|
|
618
656
|
knowledge_bundle_path: Path | None = None,
|
|
657
|
+
graph_invocation: bytes | None = None,
|
|
619
658
|
) -> PreparedCandidateContract:
|
|
620
659
|
"""Load exact runtime bytes and prove the receipt binds the plan."""
|
|
621
660
|
|
|
622
661
|
plan, plan_raw = _read_json(plan_path, "execution plan")
|
|
623
662
|
receipt, receipt_raw = _read_json(receipt_path, "materialization receipt")
|
|
624
663
|
search, receipt_digest, plan_digest = _verify_plan_envelope(
|
|
625
|
-
plan, plan_raw, receipt, receipt_raw, expected_receipt_digest
|
|
664
|
+
plan, plan_raw, receipt, receipt_raw, expected_receipt_digest, graph_invocation
|
|
626
665
|
)
|
|
627
666
|
execution_id = _string(plan.get("executionId"), "plan.executionId")
|
|
628
667
|
run_cell, coordinates = _run_cell_coordinates(plan, execution_id, search=search)
|
|
@@ -984,20 +1023,9 @@ def load_prepared_candidate_contract(
|
|
|
984
1023
|
"arm64",
|
|
985
1024
|
}:
|
|
986
1025
|
raise CandidateContractError("Pier adapter requires a supported Linux platform")
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
requested_model = _string(
|
|
990
|
-
resolved_model.get("requested"), "plan.model.resolved.requested"
|
|
1026
|
+
requested_model, resolved_model, model_network_domains = _verified_model_binding(
|
|
1027
|
+
plan, receipt, task, max_model_calls
|
|
991
1028
|
)
|
|
992
|
-
_string(resolved_model.get("provider"), "plan.model.resolved.provider")
|
|
993
|
-
_string(resolved_model.get("model"), "plan.model.resolved.model")
|
|
994
|
-
_string(resolved_model.get("snapshot"), "plan.model.resolved.snapshot")
|
|
995
|
-
if (
|
|
996
|
-
receipt.get("resolvedModel") != resolved_model
|
|
997
|
-
or task.get("model") != resolved_model
|
|
998
|
-
):
|
|
999
|
-
raise CandidateContractError("receipt and plan resolved models differ")
|
|
1000
|
-
model_network_domains = _model_network_domains(model, max_model_calls)
|
|
1001
1029
|
if receipt.get("harness") != plan.get("harness") or receipt.get(
|
|
1002
1030
|
"harnessVersion"
|
|
1003
1031
|
) != plan.get("harnessVersion"):
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
import { createInterface } from 'node:readline'
|
|
4
|
+
import { canonicalAgentProfileDigest } from '@tangle-network/agent-interface'
|
|
5
|
+
import { redactProtectedValue, runProtectedCandidateGraph } from '@tangle-network/agent-runtime/candidate-execution'
|
|
6
|
+
import { contentAddress, createPrivateCasArtifactPort, FileSpawnJournal } from '@tangle-network/agent-runtime/kernel'
|
|
7
|
+
|
|
8
|
+
// The evaluator starts this process. Its stdout is the control channel to Pier, not a worker log.
|
|
9
|
+
const send = (value) => process.stdout.write(`${JSON.stringify(value)}\n`)
|
|
10
|
+
const digest = (value) => `sha256:${createHash('sha256').update(value).digest('hex')}`
|
|
11
|
+
console.log = console.error
|
|
12
|
+
const input = createInterface({ input: process.stdin })
|
|
13
|
+
const pending = new Map()
|
|
14
|
+
let next = 0
|
|
15
|
+
let execution
|
|
16
|
+
let protectedValues = []
|
|
17
|
+
|
|
18
|
+
function request(message, signal) {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
const id = next++
|
|
21
|
+
const abort = () => {
|
|
22
|
+
pending.delete(id)
|
|
23
|
+
reject(signal.reason)
|
|
24
|
+
}
|
|
25
|
+
signal?.throwIfAborted()
|
|
26
|
+
signal?.addEventListener('abort', abort, { once: true })
|
|
27
|
+
pending.set(id, (result) => {
|
|
28
|
+
signal?.removeEventListener('abort', abort)
|
|
29
|
+
resolve(result)
|
|
30
|
+
})
|
|
31
|
+
send({ ...message, id })
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function redact(value) {
|
|
36
|
+
return protectedValues.length ? redactProtectedValue(value, protectedValues).value : value
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function runCheck(command, outputs) {
|
|
40
|
+
command.signal?.throwIfAborted()
|
|
41
|
+
const result = await request({
|
|
42
|
+
kind: 'check', command: command.command, args: command.args,
|
|
43
|
+
timeoutMs: command.timeoutMs, env: command.env, outputs,
|
|
44
|
+
}, command.signal)
|
|
45
|
+
return {
|
|
46
|
+
...result,
|
|
47
|
+
stdout: redact(result.stdout),
|
|
48
|
+
stderr: redact(result.stderr),
|
|
49
|
+
...(result.outputSnapshot ? { outputSnapshot: { ...result.outputSnapshot, redact } } : {}),
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function protectedLeaf({ plan, leaf, graph, record }) {
|
|
54
|
+
const node = plan.launch.graph.nodeId
|
|
55
|
+
const selected = graph.nodes.find(({ id }) => id === node)
|
|
56
|
+
const profileDigest = selected && canonicalAgentProfileDigest(selected.profile)
|
|
57
|
+
const maxModelCalls = plan.limits.maxModelCalls
|
|
58
|
+
const tokenLimit = plan.limits.maxInputTokens + plan.limits.maxOutputTokens
|
|
59
|
+
let launched = false
|
|
60
|
+
return (profile, spawn) => {
|
|
61
|
+
if (!leaf || spawn?.route?.node !== node || spawn.continuity === 'resume' ||
|
|
62
|
+
!profileDigest || canonicalAgentProfileDigest(profile) !== profileDigest) {
|
|
63
|
+
throw new Error('Pier requires the single profile admitted in the protected graph plan')
|
|
64
|
+
}
|
|
65
|
+
const budget = spawn.budget
|
|
66
|
+
if (maxModelCalls && (
|
|
67
|
+
(budget.maxTokens !== undefined && budget.maxTokens < tokenLimit) ||
|
|
68
|
+
(budget.maxIterations !== undefined && budget.maxIterations < maxModelCalls)
|
|
69
|
+
)) {
|
|
70
|
+
throw new Error('The graph leaf reservation cannot cover the frozen trial grant')
|
|
71
|
+
}
|
|
72
|
+
let running
|
|
73
|
+
let result
|
|
74
|
+
let reported
|
|
75
|
+
let executionNode
|
|
76
|
+
const executor = {
|
|
77
|
+
runtime: 'cli',
|
|
78
|
+
async execute(task, signal) {
|
|
79
|
+
signal.throwIfAborted()
|
|
80
|
+
if (launched || next !== 0 || typeof task !== 'string' ||
|
|
81
|
+
Buffer.byteLength(task) !== leaf.instructionByteLength || digest(task) !== leaf.instructionDigest) {
|
|
82
|
+
throw new Error('Pier requires one signed leaf launch with the exact task as the first process')
|
|
83
|
+
}
|
|
84
|
+
launched = true
|
|
85
|
+
reported = {
|
|
86
|
+
iterations: 1,
|
|
87
|
+
tokens: { input: 0, output: 0 },
|
|
88
|
+
usd: 0,
|
|
89
|
+
ms: 0,
|
|
90
|
+
...(maxModelCalls ? { tokensKnown: false, usdKnown: false, iterationsKnown: false } : {}),
|
|
91
|
+
}
|
|
92
|
+
running = request({ kind: 'leaf', node, timeoutMs: budget.deadlineMs ?? plan.limits.timeoutMs })
|
|
93
|
+
const observed = await running
|
|
94
|
+
reported = { ...reported, ms: observed.elapsedMs }
|
|
95
|
+
let out = null
|
|
96
|
+
if (observed.exitCode === 0 && !observed.timedOut && !observed.stdoutTruncated) {
|
|
97
|
+
try {
|
|
98
|
+
const value = JSON.parse(observed.stdout)
|
|
99
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) out = redact(value)
|
|
100
|
+
} catch {
|
|
101
|
+
// The application output must be a complete JSON object to drive the graph.
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const capture = {
|
|
105
|
+
node,
|
|
106
|
+
execution: executionNode,
|
|
107
|
+
profileDigest,
|
|
108
|
+
profilePlanDigest: plan.profile.planDigest,
|
|
109
|
+
instructionDigest: leaf.instructionDigest,
|
|
110
|
+
exitCode: observed.exitCode,
|
|
111
|
+
timedOut: observed.timedOut,
|
|
112
|
+
elapsedMs: observed.elapsedMs,
|
|
113
|
+
stdoutDigest: observed.stdoutDigest,
|
|
114
|
+
stdoutTruncated: observed.stdoutTruncated,
|
|
115
|
+
stderrDigest: observed.stderrDigest,
|
|
116
|
+
output: out,
|
|
117
|
+
}
|
|
118
|
+
record(capture)
|
|
119
|
+
result = {
|
|
120
|
+
out,
|
|
121
|
+
outRef: contentAddress(out),
|
|
122
|
+
outputFormat: 'json',
|
|
123
|
+
outcome: out === null
|
|
124
|
+
? { success: false, error: 'The signed Pier leaf did not return a successful JSON result' }
|
|
125
|
+
: { success: true },
|
|
126
|
+
spent: reported,
|
|
127
|
+
}
|
|
128
|
+
return result
|
|
129
|
+
},
|
|
130
|
+
async teardown() {
|
|
131
|
+
// A reply is emitted only after Pier has closed the candidate UID processes.
|
|
132
|
+
await running
|
|
133
|
+
return { destroyed: true }
|
|
134
|
+
},
|
|
135
|
+
accounting() {
|
|
136
|
+
if (!reported) return undefined
|
|
137
|
+
return {
|
|
138
|
+
kind: 'leaf',
|
|
139
|
+
reported,
|
|
140
|
+
// Hold the graph allocation against the entire permitted grant. The actual model
|
|
141
|
+
// usage is unknown here and is settled once, independently, by the trial owner.
|
|
142
|
+
reservation: maxModelCalls ? {
|
|
143
|
+
iterations: maxModelCalls,
|
|
144
|
+
tokens: { input: plan.limits.maxInputTokens, output: plan.limits.maxOutputTokens },
|
|
145
|
+
usd: 0,
|
|
146
|
+
ms: reported.ms,
|
|
147
|
+
} : reported,
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
resultArtifact() {
|
|
151
|
+
if (!result) throw new Error('The signed Pier leaf has no terminal result')
|
|
152
|
+
return result
|
|
153
|
+
},
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
name: node,
|
|
157
|
+
act: async () => { throw new Error('The signed Pier process owns this graph leaf') },
|
|
158
|
+
executorSpec: {
|
|
159
|
+
profile,
|
|
160
|
+
harness: null,
|
|
161
|
+
executorFactory(_spec, { node: worker }) {
|
|
162
|
+
if (!worker || worker.parentId !== spawn.parentNodeId ||
|
|
163
|
+
worker.identity?.profileDigest !== profileDigest) {
|
|
164
|
+
throw new Error('Pier requires a Runtime assignment for the admitted graph profile')
|
|
165
|
+
}
|
|
166
|
+
const { rootId, parentId, nodeId, attemptId } = worker
|
|
167
|
+
executionNode = { rootId, parentId, nodeId, attemptId }
|
|
168
|
+
return executor
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async function bindLeafEvidence(runDir, capture) {
|
|
176
|
+
const { rootId, nodeId, parentId, attemptId } = capture.execution
|
|
177
|
+
const journal = new FileSpawnJournal(join(runDir, 'spawn-journal.jsonl'))
|
|
178
|
+
const events = await journal.loadTree(rootId)
|
|
179
|
+
const started = events?.find((event) => event.kind === 'spawned' && event.id === nodeId &&
|
|
180
|
+
event.attemptId === attemptId)
|
|
181
|
+
const routed = events?.find((event) => event.kind === 'edge' && event.id === nodeId &&
|
|
182
|
+
event.edge.kind === 'routes' && event.edge.to === capture.node)
|
|
183
|
+
if (!started?.assignmentId || started.parent !== parentId ||
|
|
184
|
+
started.identity?.profileDigest !== capture.profileDigest || !routed) {
|
|
185
|
+
throw new Error('The signed Pier leaf has no matching Runtime route and execution record')
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
...capture,
|
|
189
|
+
execution: { ...capture.execution, assignmentId: started.assignmentId },
|
|
190
|
+
route: { ...routed.edge, traversal: routed.traversal },
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
async function launch({ plan, taskDigest, invocation, traceRunId, runDir, workspace, publicEnv, leaf }) {
|
|
195
|
+
const invocationBytes = Buffer.from(invocation, 'base64')
|
|
196
|
+
const { graph } = JSON.parse(invocationBytes)
|
|
197
|
+
const artifactNamespace = createHash('sha256').update(traceRunId).digest('hex')
|
|
198
|
+
let nativeEvidence
|
|
199
|
+
const execution = await runProtectedCandidateGraph(
|
|
200
|
+
{
|
|
201
|
+
executionPlan: { value: { material: plan } },
|
|
202
|
+
graphInvocation: invocationBytes,
|
|
203
|
+
benchmark: { task: { digest: taskDigest } },
|
|
204
|
+
resolvedModel: plan.model.resolved,
|
|
205
|
+
trace: { runId: traceRunId },
|
|
206
|
+
hardLimits: { timeoutMs: plan.limits.timeoutMs },
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
runDir,
|
|
210
|
+
checkArtifacts: createPrivateCasArtifactPort(join(runDir, 'artifacts'), artifactNamespace),
|
|
211
|
+
checkProcess: { cwd: workspace, env: publicEnv, run: runCheck, runWithOutputs: runCheck },
|
|
212
|
+
makeLeafAgent: protectedLeaf({ plan, leaf, graph, record: (value) => { nativeEvidence = value } }),
|
|
213
|
+
},
|
|
214
|
+
)
|
|
215
|
+
const { result, record, ...identity } = execution
|
|
216
|
+
send({
|
|
217
|
+
kind: 'complete',
|
|
218
|
+
graphExecution: {
|
|
219
|
+
...identity,
|
|
220
|
+
record: Buffer.from(record).toString('base64'),
|
|
221
|
+
delivered: result.result.kind !== 'no-winner',
|
|
222
|
+
...(nativeEvidence ? { nativeEvidence: await bindLeafEvidence(runDir, nativeEvidence) } : {}),
|
|
223
|
+
},
|
|
224
|
+
})
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
input.on('line', (line) => {
|
|
228
|
+
const value = JSON.parse(line)
|
|
229
|
+
if (execution === undefined) {
|
|
230
|
+
protectedValues = value.protectedValues
|
|
231
|
+
execution = launch(value).catch((error) => {
|
|
232
|
+
console.error(redact(error instanceof Error ? error.message : String(error)))
|
|
233
|
+
process.exitCode = 1
|
|
234
|
+
input.close()
|
|
235
|
+
process.stdin.destroy()
|
|
236
|
+
})
|
|
237
|
+
return
|
|
238
|
+
}
|
|
239
|
+
const resolve = pending.get(value.id)
|
|
240
|
+
if (resolve) {
|
|
241
|
+
pending.delete(value.id)
|
|
242
|
+
resolve(value)
|
|
243
|
+
}
|
|
244
|
+
})
|