@tangle-network/agent-bench 5.0.0 → 6.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 +9 -0
- package/HARNESS.md +6 -0
- package/README.md +6 -0
- package/dist/index.d.ts +14 -1
- package/dist/index.js +69 -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 +84 -0
- package/pier_agents/graph_process.py +289 -0
- package/pier_agents/tangle_candidate.py +32 -0
- package/scripts/verify-packed-consumer.mjs +6 -0
- package/src/pier-agent.test.mts +6 -0
- package/src/pier-agent.ts +53 -2
- package/src/pier-trial-controller.ts +64 -1
- 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": "6.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": "^14.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,84 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
import { createInterface } from 'node:readline'
|
|
4
|
+
import { runProtectedCandidateGraph } from '@tangle-network/agent-runtime/candidate-execution'
|
|
5
|
+
import { createPrivateCasArtifactPort } from '@tangle-network/agent-runtime/kernel'
|
|
6
|
+
|
|
7
|
+
// The evaluator starts this process. Its stdout is the control channel to Pier, not a worker log.
|
|
8
|
+
const send = (value) => process.stdout.write(`${JSON.stringify(value)}\n`)
|
|
9
|
+
console.log = console.error
|
|
10
|
+
const input = createInterface({ input: process.stdin })
|
|
11
|
+
const pending = new Map()
|
|
12
|
+
let next = 0
|
|
13
|
+
let run
|
|
14
|
+
|
|
15
|
+
async function launch({ plan, taskDigest, invocation, traceRunId, runDir, workspace, publicEnv }) {
|
|
16
|
+
const artifactNamespace = createHash('sha256').update(traceRunId).digest('hex')
|
|
17
|
+
const run = (command, outputs) => new Promise((resolve, reject) => {
|
|
18
|
+
const id = next++
|
|
19
|
+
const abort = () => {
|
|
20
|
+
pending.delete(id)
|
|
21
|
+
reject(command.signal.reason)
|
|
22
|
+
}
|
|
23
|
+
command.signal?.throwIfAborted()
|
|
24
|
+
command.signal?.addEventListener('abort', abort, { once: true })
|
|
25
|
+
pending.set(id, (result) => {
|
|
26
|
+
command.signal?.removeEventListener('abort', abort)
|
|
27
|
+
resolve(result)
|
|
28
|
+
})
|
|
29
|
+
send({
|
|
30
|
+
kind: 'check', id, command: command.command, args: command.args,
|
|
31
|
+
timeoutMs: command.timeoutMs, env: command.env, outputs,
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
const execution = await runProtectedCandidateGraph(
|
|
35
|
+
{
|
|
36
|
+
executionPlan: { value: { material: plan } },
|
|
37
|
+
graphInvocation: Buffer.from(invocation, 'base64'),
|
|
38
|
+
benchmark: { task: { digest: taskDigest } },
|
|
39
|
+
resolvedModel: plan.model.resolved,
|
|
40
|
+
trace: { runId: traceRunId },
|
|
41
|
+
hardLimits: { timeoutMs: plan.limits.timeoutMs },
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
runDir,
|
|
45
|
+
checkArtifacts: createPrivateCasArtifactPort(join(runDir, 'artifacts'), artifactNamespace),
|
|
46
|
+
checkProcess: {
|
|
47
|
+
cwd: workspace,
|
|
48
|
+
env: publicEnv,
|
|
49
|
+
run,
|
|
50
|
+
runWithOutputs: run,
|
|
51
|
+
},
|
|
52
|
+
makeLeafAgent() {
|
|
53
|
+
throw new Error('This protected Pier trial does not admit native model calls')
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
)
|
|
57
|
+
const { result, record, ...identity } = execution
|
|
58
|
+
send({
|
|
59
|
+
kind: 'complete',
|
|
60
|
+
graphExecution: {
|
|
61
|
+
...identity,
|
|
62
|
+
record: Buffer.from(record).toString('base64'),
|
|
63
|
+
delivered: result.result.kind !== 'no-winner',
|
|
64
|
+
},
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
input.on('line', (line) => {
|
|
69
|
+
const value = JSON.parse(line)
|
|
70
|
+
if (run === undefined) {
|
|
71
|
+
run = launch(value).catch((error) => {
|
|
72
|
+
console.error(error)
|
|
73
|
+
process.exitCode = 1
|
|
74
|
+
input.close()
|
|
75
|
+
process.stdin.destroy()
|
|
76
|
+
})
|
|
77
|
+
return
|
|
78
|
+
}
|
|
79
|
+
const resolve = pending.get(value.id)
|
|
80
|
+
if (resolve) {
|
|
81
|
+
pending.delete(value.id)
|
|
82
|
+
resolve(value)
|
|
83
|
+
}
|
|
84
|
+
})
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"""Evaluator-side graph coordination with candidate-UID command execution."""
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import base64
|
|
5
|
+
import json
|
|
6
|
+
import math
|
|
7
|
+
import os
|
|
8
|
+
import secrets
|
|
9
|
+
import shlex
|
|
10
|
+
import time
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
from pier.models.agent.context import AgentContext
|
|
15
|
+
from pier.environments.base import BaseEnvironment
|
|
16
|
+
|
|
17
|
+
from .candidate_contract import CandidateContractError, _safe_relative, sha256_bytes
|
|
18
|
+
from .workspace_boundary import candidate_git_env
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
async def _output_file_state(
|
|
22
|
+
agent: Any, environment: BaseEnvironment, path: str
|
|
23
|
+
) -> tuple[int, str] | str:
|
|
24
|
+
quoted = shlex.quote(path)
|
|
25
|
+
try:
|
|
26
|
+
result = await agent._exec(
|
|
27
|
+
environment,
|
|
28
|
+
f"""set -eu
|
|
29
|
+
file={quoted}
|
|
30
|
+
if ! test -e "$file" && ! test -L "$file"; then exit 3; fi
|
|
31
|
+
if ! test -f "$file" || test -L "$file" ||
|
|
32
|
+
test "$(realpath -e -- "$file")" != "$file" ||
|
|
33
|
+
test "$(stat -c %h -- "$file")" != 1; then exit 4; fi
|
|
34
|
+
stat -c '%s %d:%i %y %z' -- "$file"
|
|
35
|
+
""",
|
|
36
|
+
user="root",
|
|
37
|
+
check=False,
|
|
38
|
+
timeout_sec=5,
|
|
39
|
+
)
|
|
40
|
+
except TimeoutError:
|
|
41
|
+
return "timeout"
|
|
42
|
+
except Exception:
|
|
43
|
+
return "capture-failed"
|
|
44
|
+
if result.return_code == 3:
|
|
45
|
+
return "missing"
|
|
46
|
+
if result.return_code == 4:
|
|
47
|
+
return "unsafe-path"
|
|
48
|
+
size, _, identity = (result.stdout or "").strip().partition(" ")
|
|
49
|
+
if result.return_code != 0 or not size.isdigit() or not identity:
|
|
50
|
+
return "capture-failed"
|
|
51
|
+
return int(size), identity
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
async def _snapshot_outputs(
|
|
55
|
+
agent: Any,
|
|
56
|
+
environment: BaseEnvironment,
|
|
57
|
+
directory: Path,
|
|
58
|
+
prior: dict[str, tuple[int, str] | str],
|
|
59
|
+
max_file_bytes: int,
|
|
60
|
+
max_total_bytes: int,
|
|
61
|
+
timeout_ms: int,
|
|
62
|
+
) -> dict[str, Any]:
|
|
63
|
+
directory.mkdir(mode=0o700, parents=True)
|
|
64
|
+
failures: dict[str, str] = {}
|
|
65
|
+
pending = set(prior)
|
|
66
|
+
try:
|
|
67
|
+
async with asyncio.timeout(timeout_ms / 1000):
|
|
68
|
+
for path, before in prior.items():
|
|
69
|
+
source = f"{agent._contract.task_root}/{path}"
|
|
70
|
+
after = await _output_file_state(agent, environment, source)
|
|
71
|
+
destination = directory / path
|
|
72
|
+
if isinstance(after, str):
|
|
73
|
+
failures[path] = after
|
|
74
|
+
elif before == after:
|
|
75
|
+
failures[path] = "capture-failed"
|
|
76
|
+
elif after[0] > min(max_file_bytes, max_total_bytes):
|
|
77
|
+
failures[path] = "size-limit"
|
|
78
|
+
else:
|
|
79
|
+
destination.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
80
|
+
boundary = agent._process_boundary
|
|
81
|
+
staging = f"{boundary.config.control_root}/check-output-{secrets.token_hex(16)}"
|
|
82
|
+
copied = False
|
|
83
|
+
try:
|
|
84
|
+
# Pier changes ownership when it downloads files. Keep the command's workspace intact.
|
|
85
|
+
await agent._exec(
|
|
86
|
+
environment,
|
|
87
|
+
f"umask 077; {shlex.join(['cp', '--', source, staging])}",
|
|
88
|
+
user="root",
|
|
89
|
+
)
|
|
90
|
+
await environment.download_file(staging, destination)
|
|
91
|
+
copied = destination.stat().st_size == after[0]
|
|
92
|
+
if copied:
|
|
93
|
+
max_total_bytes -= after[0]
|
|
94
|
+
except Exception:
|
|
95
|
+
pass
|
|
96
|
+
finally:
|
|
97
|
+
if not copied:
|
|
98
|
+
failures[path] = "capture-failed"
|
|
99
|
+
destination.unlink(missing_ok=True)
|
|
100
|
+
await asyncio.shield(
|
|
101
|
+
boundary.remove_control_files(environment, None, staging)
|
|
102
|
+
)
|
|
103
|
+
pending.remove(path)
|
|
104
|
+
except TimeoutError:
|
|
105
|
+
failures.update((path, "timeout") for path in pending)
|
|
106
|
+
return {"directory": str(directory), "failures": failures}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
async def _run_check(
|
|
110
|
+
agent: Any,
|
|
111
|
+
environment: BaseEnvironment,
|
|
112
|
+
request: dict[str, Any],
|
|
113
|
+
run_dir: Path,
|
|
114
|
+
public_env: dict[str, str],
|
|
115
|
+
) -> dict[str, Any]:
|
|
116
|
+
boundary = agent._process_boundary
|
|
117
|
+
contract = agent._contract
|
|
118
|
+
identifier = request["id"]
|
|
119
|
+
command = request["command"]
|
|
120
|
+
arguments = request["args"]
|
|
121
|
+
milliseconds = request["timeoutMs"]
|
|
122
|
+
check_env = dict(request["env"])
|
|
123
|
+
if (
|
|
124
|
+
type(identifier) is not int
|
|
125
|
+
or identifier < 0
|
|
126
|
+
or command != "/bin/sh"
|
|
127
|
+
or not isinstance(arguments, list)
|
|
128
|
+
or len(arguments) != 2
|
|
129
|
+
or arguments[0] != "-c"
|
|
130
|
+
or not isinstance(arguments[1], str)
|
|
131
|
+
or type(milliseconds) is not int
|
|
132
|
+
or milliseconds <= 0
|
|
133
|
+
):
|
|
134
|
+
raise CandidateContractError("invalid evaluator graph command")
|
|
135
|
+
source = Path(check_env.pop("GRAPH_EVIDENCE"))
|
|
136
|
+
task_file = Path(check_env.pop("GRAPH_INPUT"))
|
|
137
|
+
if (
|
|
138
|
+
source.resolve() != source
|
|
139
|
+
or not source.is_relative_to(run_dir / "graph-evidence")
|
|
140
|
+
or task_file != source / "_input" / "task.json"
|
|
141
|
+
or any(public_env.get(name) != value for name, value in check_env.items())
|
|
142
|
+
):
|
|
143
|
+
raise CandidateContractError("graph check evidence or public environment changed")
|
|
144
|
+
target = f"{boundary.config.evaluator_root}/graph-evidence/{identifier}"
|
|
145
|
+
for file in source.rglob("*"):
|
|
146
|
+
if file.is_symlink():
|
|
147
|
+
raise CandidateContractError("graph evidence contains a symlink")
|
|
148
|
+
if not file.is_file():
|
|
149
|
+
continue
|
|
150
|
+
content = file.read_bytes()
|
|
151
|
+
await agent._write_verified_file(
|
|
152
|
+
environment,
|
|
153
|
+
file,
|
|
154
|
+
f"{target}/{file.relative_to(source).as_posix()}",
|
|
155
|
+
anchor=boundary.config.evaluator_root,
|
|
156
|
+
mode=0o444,
|
|
157
|
+
digest=sha256_bytes(content),
|
|
158
|
+
byte_length=len(content),
|
|
159
|
+
)
|
|
160
|
+
check_env.update(GRAPH_EVIDENCE=target, GRAPH_INPUT=f"{target}/_input/task.json")
|
|
161
|
+
outputs = request.get("outputs")
|
|
162
|
+
prior = {}
|
|
163
|
+
if outputs:
|
|
164
|
+
for item in outputs["paths"]:
|
|
165
|
+
path = _safe_relative(item, "graph check output")
|
|
166
|
+
prior[path] = await _output_file_state(
|
|
167
|
+
agent, environment, f"{contract.task_root}/{path}"
|
|
168
|
+
)
|
|
169
|
+
wrapper, marker = await boundary.stage_wrapper(environment)
|
|
170
|
+
try:
|
|
171
|
+
seconds = min(milliseconds, contract.timeout_ms) / 1000
|
|
172
|
+
call = shlex.join([
|
|
173
|
+
wrapper, marker, str(boundary.config.uid), str(boundary.config.gid),
|
|
174
|
+
f"{seconds:.3f}", "2", "-",
|
|
175
|
+
*(f"{name}={value}" for name, value in check_env.items()),
|
|
176
|
+
command, *arguments,
|
|
177
|
+
])
|
|
178
|
+
result = await agent._exec(
|
|
179
|
+
environment,
|
|
180
|
+
call,
|
|
181
|
+
cwd=contract.task_root,
|
|
182
|
+
env={
|
|
183
|
+
**candidate_git_env(contract.task_root),
|
|
184
|
+
"HOME": boundary.config.home,
|
|
185
|
+
"TMPDIR": boundary.config.temporary,
|
|
186
|
+
"PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
|
187
|
+
},
|
|
188
|
+
user="root",
|
|
189
|
+
timeout_sec=math.ceil(seconds) + 12,
|
|
190
|
+
check=False,
|
|
191
|
+
)
|
|
192
|
+
timed_out = await boundary.timeout_marker_exists(environment, marker)
|
|
193
|
+
receipt: dict[str, Any] = {
|
|
194
|
+
"id": identifier,
|
|
195
|
+
"exitCode": result.return_code,
|
|
196
|
+
"stdout": (result.stdout or "")[-131072:],
|
|
197
|
+
"stderr": (result.stderr or "")[-131072:],
|
|
198
|
+
"killedBySignal": None,
|
|
199
|
+
"timedOut": timed_out,
|
|
200
|
+
}
|
|
201
|
+
if outputs:
|
|
202
|
+
receipt["outputSnapshot"] = await _snapshot_outputs(
|
|
203
|
+
agent,
|
|
204
|
+
environment,
|
|
205
|
+
run_dir / "transport-output" / str(identifier),
|
|
206
|
+
prior,
|
|
207
|
+
outputs["maxFileBytes"],
|
|
208
|
+
outputs["maxTotalBytes"],
|
|
209
|
+
outputs.get("timeoutMs", 30_000),
|
|
210
|
+
)
|
|
211
|
+
return receipt
|
|
212
|
+
finally:
|
|
213
|
+
await asyncio.shield(boundary.remove_control_files(environment, wrapper, marker))
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
async def run_graph_in_pier(
|
|
217
|
+
agent: Any,
|
|
218
|
+
environment: BaseEnvironment,
|
|
219
|
+
context: AgentContext,
|
|
220
|
+
*,
|
|
221
|
+
driver: tuple[str, str],
|
|
222
|
+
invocation: bytes,
|
|
223
|
+
trace_run_id: str,
|
|
224
|
+
) -> None:
|
|
225
|
+
contract = agent._contract
|
|
226
|
+
root = agent.logs_dir.resolve() / "graph-runtime"
|
|
227
|
+
root.mkdir(mode=0o700)
|
|
228
|
+
workspace = root / "workspace-evidence"
|
|
229
|
+
workspace.mkdir(mode=0o700)
|
|
230
|
+
run_dir = root / "run"
|
|
231
|
+
public_env = dict(contract.env)
|
|
232
|
+
# The zero-model lane has no protected gateway credentials in its host or command environment.
|
|
233
|
+
public_env.pop("PATH", None)
|
|
234
|
+
context.metadata = {**agent._identity_metadata(), "termination": {"kind": "running"}}
|
|
235
|
+
started = time.monotonic()
|
|
236
|
+
async with asyncio.timeout(contract.timeout_ms / 1000):
|
|
237
|
+
with (root / "coordinator.stderr").open("wb") as stderr:
|
|
238
|
+
process = await asyncio.create_subprocess_exec(
|
|
239
|
+
*driver,
|
|
240
|
+
stdin=asyncio.subprocess.PIPE,
|
|
241
|
+
stdout=asyncio.subprocess.PIPE,
|
|
242
|
+
stderr=stderr,
|
|
243
|
+
env={"PATH": os.defpath},
|
|
244
|
+
cwd=root,
|
|
245
|
+
limit=4 * 1024 * 1024,
|
|
246
|
+
)
|
|
247
|
+
assert process.stdin is not None and process.stdout is not None
|
|
248
|
+
|
|
249
|
+
async def send(value: dict[str, Any]) -> None:
|
|
250
|
+
process.stdin.write((json.dumps(value) + "\n").encode())
|
|
251
|
+
await process.stdin.drain()
|
|
252
|
+
|
|
253
|
+
try:
|
|
254
|
+
await send({
|
|
255
|
+
"plan": contract.plan,
|
|
256
|
+
"taskDigest": contract.receipt["benchmark"]["task"]["digest"],
|
|
257
|
+
"invocation": base64.b64encode(invocation).decode("ascii"),
|
|
258
|
+
"traceRunId": trace_run_id,
|
|
259
|
+
"runDir": str(run_dir),
|
|
260
|
+
"workspace": str(workspace),
|
|
261
|
+
"publicEnv": public_env,
|
|
262
|
+
})
|
|
263
|
+
record = None
|
|
264
|
+
while line := await process.stdout.readline():
|
|
265
|
+
message = json.loads(line)
|
|
266
|
+
if message.get("kind") == "check":
|
|
267
|
+
# The process wrapper stops every process of this trial's candidate UID.
|
|
268
|
+
result = await _run_check(agent, environment, message, run_dir, public_env)
|
|
269
|
+
await send(result)
|
|
270
|
+
elif message.get("kind") == "complete":
|
|
271
|
+
record = message["graphExecution"]
|
|
272
|
+
break
|
|
273
|
+
else:
|
|
274
|
+
raise CandidateContractError("invalid graph coordinator response")
|
|
275
|
+
process.stdin.close()
|
|
276
|
+
if await process.wait() != 0 or record is None:
|
|
277
|
+
raise CandidateContractError("graph coordinator produced no terminal record")
|
|
278
|
+
finally:
|
|
279
|
+
if process.returncode is None:
|
|
280
|
+
process.kill()
|
|
281
|
+
await asyncio.shield(process.wait())
|
|
282
|
+
await asyncio.shield(agent._process_boundary.kill_and_wait(environment))
|
|
283
|
+
await asyncio.shield(agent._restore_profile_and_capture_solution(environment))
|
|
284
|
+
context.metadata = {
|
|
285
|
+
**agent._identity_metadata(),
|
|
286
|
+
"termination": {"kind": "exit", "exitCode": 0 if record["delivered"] else 1},
|
|
287
|
+
"observedElapsedMs": int((time.monotonic() - started) * 1000),
|
|
288
|
+
"graphExecution": record,
|
|
289
|
+
}
|
|
@@ -36,6 +36,7 @@ from .candidate_contract import (
|
|
|
36
36
|
load_prepared_candidate_contract,
|
|
37
37
|
sha256_bytes,
|
|
38
38
|
)
|
|
39
|
+
from .graph_process import run_graph_in_pier
|
|
39
40
|
from .process_boundary import CandidateProcessBoundary, ProcessBoundaryConfig
|
|
40
41
|
from .workspace_boundary import (
|
|
41
42
|
CandidateWorkspaceBoundary,
|
|
@@ -174,6 +175,9 @@ class TangleCandidateAgent(BaseAgent):
|
|
|
174
175
|
knowledge_bundle_path: str | None = None,
|
|
175
176
|
pier_version: str | None = None,
|
|
176
177
|
extra_env: dict[str, str] | None = None,
|
|
178
|
+
graph_invocation_path: str | None = None,
|
|
179
|
+
graph_node_path: str | None = None,
|
|
180
|
+
graph_driver_path: str | None = None,
|
|
177
181
|
*args: Any,
|
|
178
182
|
**kwargs: Any,
|
|
179
183
|
) -> None:
|
|
@@ -191,6 +195,18 @@ class TangleCandidateAgent(BaseAgent):
|
|
|
191
195
|
raise PierCandidateError("task_dir, profile_dir, and pier_version are required")
|
|
192
196
|
|
|
193
197
|
self._expected_pier_version = pier_version
|
|
198
|
+
self._graph_invocation = (
|
|
199
|
+
Path(graph_invocation_path).read_bytes() if graph_invocation_path else None
|
|
200
|
+
)
|
|
201
|
+
self._graph_driver: tuple[str, str] | None = None
|
|
202
|
+
if self._graph_invocation is not None:
|
|
203
|
+
if not graph_node_path or not graph_driver_path:
|
|
204
|
+
raise PierCandidateError("sealed graph requires an evaluator coordinator")
|
|
205
|
+
self._graph_driver = (
|
|
206
|
+
str(Path(graph_node_path).resolve(strict=True)),
|
|
207
|
+
str(Path(graph_driver_path).resolve(strict=True)),
|
|
208
|
+
)
|
|
209
|
+
self._trace_run_id = trace_run_id
|
|
194
210
|
self._contract = load_prepared_candidate_contract(
|
|
195
211
|
Path(plan_path).expanduser().resolve(),
|
|
196
212
|
Path(receipt_path).expanduser().resolve(),
|
|
@@ -198,7 +214,13 @@ class TangleCandidateAgent(BaseAgent):
|
|
|
198
214
|
Path(knowledge_bundle_path).expanduser().absolute()
|
|
199
215
|
if knowledge_bundle_path
|
|
200
216
|
else None,
|
|
217
|
+
self._graph_invocation,
|
|
201
218
|
)
|
|
219
|
+
if (
|
|
220
|
+
self._graph_driver is not None
|
|
221
|
+
and self._contract.plan["limits"]["maxModelCalls"] != 0
|
|
222
|
+
):
|
|
223
|
+
raise PierCandidateError("this Pier graph executor requires a zero-model task")
|
|
202
224
|
if model_name != self._contract.requested_model:
|
|
203
225
|
raise PierCandidateError(
|
|
204
226
|
"Pier model does not match the runtime-resolved request: "
|
|
@@ -898,6 +920,16 @@ fi""",
|
|
|
898
920
|
environment: BaseEnvironment,
|
|
899
921
|
context: AgentContext,
|
|
900
922
|
) -> None:
|
|
923
|
+
if self._graph_driver is not None and self._graph_invocation is not None:
|
|
924
|
+
await run_graph_in_pier(
|
|
925
|
+
self,
|
|
926
|
+
environment,
|
|
927
|
+
context,
|
|
928
|
+
driver=self._graph_driver,
|
|
929
|
+
invocation=self._graph_invocation,
|
|
930
|
+
trace_run_id=self._trace_run_id,
|
|
931
|
+
)
|
|
932
|
+
return
|
|
901
933
|
argv, stdin_path, instruction_path = await self._upload_instruction(
|
|
902
934
|
environment, instruction
|
|
903
935
|
)
|
|
@@ -252,6 +252,7 @@ root = Path(pier_agents.__file__).parent
|
|
|
252
252
|
expected = {
|
|
253
253
|
"__init__.py",
|
|
254
254
|
"candidate_contract.py",
|
|
255
|
+
"graph_process.py",
|
|
255
256
|
"process_boundary.py",
|
|
256
257
|
"tangle_candidate.py",
|
|
257
258
|
"workspace_boundary.py",
|
|
@@ -307,6 +308,11 @@ for name in sorted(expected):
|
|
|
307
308
|
await run('npm', ['exec', '--', 'tsx', 'managed-execution.ts'], consumerDir)
|
|
308
309
|
const installedPackage = path.join(consumerDir, 'node_modules', '@tangle-network', 'agent-bench')
|
|
309
310
|
await access(path.join(installedPackage, 'dist', 'pier-trial-supervisor.mjs'))
|
|
311
|
+
await run(
|
|
312
|
+
'node',
|
|
313
|
+
['--check', path.join(installedPackage, 'pier_agents', 'graph_driver.mjs')],
|
|
314
|
+
consumerDir,
|
|
315
|
+
)
|
|
310
316
|
const prepared = await run(
|
|
311
317
|
'npm',
|
|
312
318
|
[
|
package/src/pier-agent.test.mts
CHANGED
|
@@ -39,6 +39,12 @@ function prepared(root: string): PreparedAgentCandidateExecution {
|
|
|
39
39
|
kind: 'agent-candidate-execution-plan-material',
|
|
40
40
|
runCell: { bundleDigest },
|
|
41
41
|
executionId,
|
|
42
|
+
launch: {
|
|
43
|
+
executable: 'python3',
|
|
44
|
+
args: [{ kind: 'public', value: '/opt/tangle-candidate/runner.py' }],
|
|
45
|
+
env: { PUBLIC_MODE: { kind: 'public', value: 'fixture' } },
|
|
46
|
+
cwd: { workspace: 'task', path: '.' },
|
|
47
|
+
},
|
|
42
48
|
limits: {
|
|
43
49
|
timeoutMs: 60_000,
|
|
44
50
|
maxSteps: 8,
|