@tangle-network/agent-bench 0.4.1 → 0.4.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.
- package/CHANGELOG.md +9 -0
- package/dist/adapters.d.ts +4 -11
- package/dist/adapters.js +78 -41
- package/dist/adapters.js.map +1 -1
- package/dist/benchmarks/_harness.d.ts +48 -66
- package/dist/benchmarks/_harness.js +329 -33
- package/dist/benchmarks/_harness.js.map +1 -1
- package/dist/benchmarks/aec-bench.d.ts +4 -25
- package/dist/benchmarks/aec-bench.js +242 -7
- package/dist/benchmarks/aec-bench.js.map +1 -1
- package/dist/benchmarks/agentbench.d.ts +5 -13
- package/dist/benchmarks/agentbench.js +114 -9
- package/dist/benchmarks/agentbench.js.map +1 -1
- package/dist/benchmarks/appworld.d.ts +9 -29
- package/dist/benchmarks/appworld.js +317 -12
- package/dist/benchmarks/appworld.js.map +1 -1
- package/dist/benchmarks/bfcl.d.ts +5 -15
- package/dist/benchmarks/bfcl.js +264 -9
- package/dist/benchmarks/bfcl.js.map +1 -1
- package/dist/benchmarks/cad-design.d.ts +16 -41
- package/dist/benchmarks/cad-design.js +512 -6
- package/dist/benchmarks/cad-design.js.map +1 -1
- package/dist/benchmarks/cadbench.d.ts +4 -17
- package/dist/benchmarks/cadbench.js +2 -8
- package/dist/benchmarks/cadgenbench.d.ts +4 -20
- package/dist/benchmarks/cadgenbench.js +2 -8
- package/dist/benchmarks/commit0.d.ts +5 -27
- package/dist/benchmarks/commit0.js +187 -9
- package/dist/benchmarks/commit0.js.map +1 -1
- package/dist/benchmarks/crag.d.ts +4 -12
- package/dist/benchmarks/crag.js +110 -8
- package/dist/benchmarks/crag.js.map +1 -1
- package/dist/benchmarks/dabstep.d.ts +5 -15
- package/dist/benchmarks/dabstep.js +177 -9
- package/dist/benchmarks/dabstep.js.map +1 -1
- package/dist/benchmarks/enterpriseops-gym.d.ts +5 -34
- package/dist/benchmarks/enterpriseops-gym.js +236 -9
- package/dist/benchmarks/enterpriseops-gym.js.map +1 -1
- package/dist/benchmarks/finresearchbench.d.ts +4 -13
- package/dist/benchmarks/finresearchbench.js +218 -7
- package/dist/benchmarks/finresearchbench.js.map +1 -1
- package/dist/benchmarks/finsearchcomp.d.ts +8 -39
- package/dist/benchmarks/finsearchcomp.js +267 -6
- package/dist/benchmarks/finsearchcomp.js.map +1 -1
- package/dist/benchmarks/frames.d.ts +15 -37
- package/dist/benchmarks/frames.js +408 -11
- package/dist/benchmarks/frames.js.map +1 -1
- package/dist/benchmarks/hotpotqa.d.ts +4 -24
- package/dist/benchmarks/hotpotqa.js +250 -14
- package/dist/benchmarks/hotpotqa.js.map +1 -1
- package/dist/benchmarks/humaneval.d.ts +19 -37
- package/dist/benchmarks/humaneval.js +279 -16
- package/dist/benchmarks/humaneval.js.map +1 -1
- package/dist/benchmarks/mind2web.d.ts +7 -34
- package/dist/benchmarks/mind2web.js +257 -8
- package/dist/benchmarks/mind2web.js.map +1 -1
- package/dist/benchmarks/nomiracl.d.ts +4 -13
- package/dist/benchmarks/nomiracl.js +146 -8
- package/dist/benchmarks/nomiracl.js.map +1 -1
- package/dist/benchmarks/open-rag-bench.d.ts +4 -12
- package/dist/benchmarks/open-rag-bench.js +110 -8
- package/dist/benchmarks/open-rag-bench.js.map +1 -1
- package/dist/benchmarks/programbench.d.ts +5 -29
- package/dist/benchmarks/programbench.js +161 -9
- package/dist/benchmarks/programbench.js.map +1 -1
- package/dist/benchmarks/rag-shared.d.ts +21 -20
- package/dist/benchmarks/rag-shared.js +245 -38
- package/dist/benchmarks/rag-shared.js.map +1 -1
- package/dist/benchmarks/ragbench.d.ts +4 -14
- package/dist/benchmarks/ragbench.js +127 -8
- package/dist/benchmarks/ragbench.js.map +1 -1
- package/dist/benchmarks/simpleqa.d.ts +17 -44
- package/dist/benchmarks/simpleqa.js +293 -10
- package/dist/benchmarks/simpleqa.js.map +1 -1
- package/dist/benchmarks/swe-bench.d.ts +23 -36
- package/dist/benchmarks/swe-bench.js +234 -13
- package/dist/benchmarks/swe-bench.js.map +1 -1
- package/dist/benchmarks/t2-ragbench.d.ts +4 -12
- package/dist/benchmarks/t2-ragbench.js +118 -8
- package/dist/benchmarks/t2-ragbench.js.map +1 -1
- package/dist/benchmarks/tau-bench-shared.d.ts +14 -22
- package/dist/benchmarks/tau-bench-shared.js +169 -9
- package/dist/benchmarks/tau-bench-shared.js.map +1 -1
- package/dist/benchmarks/tau2-bench.d.ts +5 -5
- package/dist/benchmarks/tau2-bench.js +28 -10
- package/dist/benchmarks/tau2-bench.js.map +1 -1
- package/dist/benchmarks/tau3-banking.d.ts +4 -13
- package/dist/benchmarks/tau3-banking.js +28 -8
- package/dist/benchmarks/tau3-banking.js.map +1 -1
- package/dist/benchmarks/terminal-bench.d.ts +4 -22
- package/dist/benchmarks/terminal-bench.js +140 -7
- package/dist/benchmarks/terminal-bench.js.map +1 -1
- package/dist/benchmarks/toollm.d.ts +5 -13
- package/dist/benchmarks/toollm.js +184 -9
- package/dist/benchmarks/toollm.js.map +1 -1
- package/dist/benchmarks/trata-hedge.d.ts +4 -30
- package/dist/benchmarks/trata-hedge.js +336 -6
- package/dist/benchmarks/trata-hedge.js.map +1 -1
- package/dist/benchmarks/types.d.ts +85 -94
- package/dist/benchmarks/types.js +1 -1
- package/dist/benchmarks/webarena-verified.d.ts +5 -13
- package/dist/benchmarks/webarena-verified.js +152 -9
- package/dist/benchmarks/webarena-verified.js.map +1 -1
- package/dist/cadbench-DpQWZHp4.js +285 -0
- package/dist/cadbench-DpQWZHp4.js.map +1 -0
- package/dist/cadgenbench-DRhczfsG.js +151 -0
- package/dist/cadgenbench-DRhczfsG.js.map +1 -0
- package/dist/index.d.ts +245 -293
- package/dist/index.js +1669 -1791
- package/dist/index.js.map +1 -1
- package/package.json +17 -14
- package/scripts/verify-packed-consumer.mjs +20 -17
- package/src/corpus.test.mts +13 -0
- package/src/corpus.ts +4 -0
- package/src/profile-coordinates.ts +2 -2
- package/src/rollout-ledger/backfill-swe-arena.mts +5 -1
- package/src/rollout-ledger/settle-capture.mts +7 -1
- package/src/search-bench/profiles.ts +1 -1
- package/src/skill-sandbox-smoke.mts +2 -1
- package/src/swe-arena/gepa-seat.mts +1 -1
- package/src/swe-arena/ledger-orphans.test.mts +36 -34
- package/dist/benchmarks/cadbench.js.map +0 -1
- package/dist/benchmarks/cadgenbench.js.map +0 -1
- package/dist/benchmarks/types.js.map +0 -1
- package/dist/chunk-53UPUNBZ.js +0 -325
- package/dist/chunk-53UPUNBZ.js.map +0 -1
- package/dist/chunk-5FEQDSCT.js +0 -211
- package/dist/chunk-5FEQDSCT.js.map +0 -1
- package/dist/chunk-5H5XV76F.js +0 -240
- package/dist/chunk-5H5XV76F.js.map +0 -1
- package/dist/chunk-67ACKDCX.js +0 -118
- package/dist/chunk-67ACKDCX.js.map +0 -1
- package/dist/chunk-7FKBWOQT.js +0 -147
- package/dist/chunk-7FKBWOQT.js.map +0 -1
- package/dist/chunk-BEN6IF2X.js +0 -221
- package/dist/chunk-BEN6IF2X.js.map +0 -1
- package/dist/chunk-BZY5QARD.js +0 -120
- package/dist/chunk-BZY5QARD.js.map +0 -1
- package/dist/chunk-C7T7WEK2.js +0 -103
- package/dist/chunk-C7T7WEK2.js.map +0 -1
- package/dist/chunk-CLIKAXKH.js +0 -276
- package/dist/chunk-CLIKAXKH.js.map +0 -1
- package/dist/chunk-CWIOBFSP.js +0 -197
- package/dist/chunk-CWIOBFSP.js.map +0 -1
- package/dist/chunk-CXDUTWQE.js +0 -318
- package/dist/chunk-CXDUTWQE.js.map +0 -1
- package/dist/chunk-DWALFME7.js +0 -182
- package/dist/chunk-DWALFME7.js.map +0 -1
- package/dist/chunk-EEOC6QPJ.js +0 -144
- package/dist/chunk-EEOC6QPJ.js.map +0 -1
- package/dist/chunk-EIETHPD5.js +0 -321
- package/dist/chunk-EIETHPD5.js.map +0 -1
- package/dist/chunk-GC2EPS6L.js +0 -130
- package/dist/chunk-GC2EPS6L.js.map +0 -1
- package/dist/chunk-GCHL6XPM.js +0 -169
- package/dist/chunk-GCHL6XPM.js.map +0 -1
- package/dist/chunk-HQ5HCCKF.js +0 -142
- package/dist/chunk-HQ5HCCKF.js.map +0 -1
- package/dist/chunk-HVW25KSX.js +0 -208
- package/dist/chunk-HVW25KSX.js.map +0 -1
- package/dist/chunk-INNOYXCP.js +0 -387
- package/dist/chunk-INNOYXCP.js.map +0 -1
- package/dist/chunk-J6BU3NTM.js +0 -251
- package/dist/chunk-J6BU3NTM.js.map +0 -1
- package/dist/chunk-JSQOUKXS.js +0 -149
- package/dist/chunk-JSQOUKXS.js.map +0 -1
- package/dist/chunk-JTHWEDEW.js +0 -32
- package/dist/chunk-JTHWEDEW.js.map +0 -1
- package/dist/chunk-NRMGT25X.js +0 -116
- package/dist/chunk-NRMGT25X.js.map +0 -1
- package/dist/chunk-PA2ZKHJC.js +0 -230
- package/dist/chunk-PA2ZKHJC.js.map +0 -1
- package/dist/chunk-PUIRNYI7.js +0 -189
- package/dist/chunk-PUIRNYI7.js.map +0 -1
- package/dist/chunk-QZZEAHWJ.js +0 -136
- package/dist/chunk-QZZEAHWJ.js.map +0 -1
- package/dist/chunk-SEVJPLZC.js +0 -260
- package/dist/chunk-SEVJPLZC.js.map +0 -1
- package/dist/chunk-TBKU5XQI.js +0 -228
- package/dist/chunk-TBKU5XQI.js.map +0 -1
- package/dist/chunk-UPAMRDX4.js +0 -233
- package/dist/chunk-UPAMRDX4.js.map +0 -1
- package/dist/chunk-VQRS7VUC.js +0 -342
- package/dist/chunk-VQRS7VUC.js.map +0 -1
- package/dist/chunk-WG7TM7UV.js +0 -30
- package/dist/chunk-WG7TM7UV.js.map +0 -1
- package/dist/chunk-X3BTXCJ4.js +0 -262
- package/dist/chunk-X3BTXCJ4.js.map +0 -1
- package/dist/chunk-XXFF3RRD.js +0 -162
- package/dist/chunk-XXFF3RRD.js.map +0 -1
- package/dist/chunk-ZFNOM7WR.js +0 -27
- package/dist/chunk-ZFNOM7WR.js.map +0 -1
- package/dist/chunk-ZNCCYTFG.js +0 -170
- package/dist/chunk-ZNCCYTFG.js.map +0 -1
package/dist/chunk-CXDUTWQE.js
DELETED
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
benchRoot,
|
|
3
|
-
preflightVenvImports,
|
|
4
|
-
runVenvScriptStdin,
|
|
5
|
-
venvPython
|
|
6
|
-
} from "./chunk-EIETHPD5.js";
|
|
7
|
-
|
|
8
|
-
// src/benchmarks/appworld.ts
|
|
9
|
-
import { spawn } from "child_process";
|
|
10
|
-
import { join } from "path";
|
|
11
|
-
import { createInterface } from "readline";
|
|
12
|
-
import { routerToolLoop } from "@tangle-network/agent-runtime/loops";
|
|
13
|
-
var DRIVER = join(benchRoot, "scripts", "appworld_driver.py");
|
|
14
|
-
var DEFAULT_SPLIT = "test_normal";
|
|
15
|
-
var appworldSolutionOutput = {
|
|
16
|
-
parse(events) {
|
|
17
|
-
let text = "";
|
|
18
|
-
for (const ev of events) {
|
|
19
|
-
const d = ev?.data;
|
|
20
|
-
const t = d?.finalText ?? d?.text ?? d?.result;
|
|
21
|
-
if (typeof t === "string" && t.length > 0) text = t;
|
|
22
|
-
}
|
|
23
|
-
const fences = [...text.matchAll(/```(?:python|py)?\s*\n([\s\S]*?)```/g)];
|
|
24
|
-
return (fences.at(-1)?.[1] ?? text).trim();
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
var WORKER_CONTRACT = [
|
|
28
|
-
"",
|
|
29
|
-
"Solve this by writing Python that calls the available app APIs (the `apis.<app>.<function>(...)` surface). You may inspect API docs with `apis.api_docs.show_api_descriptions(app_name=...)` and `apis.api_docs.show_api_doc(app_name=..., api_name=...)`.",
|
|
30
|
-
"Authenticate where needed via the supervisor-provided credentials, perform every step the task requires, and FINISH with `apis.supervisor.complete_task()`.",
|
|
31
|
-
"Emit your COMPLETE solution as the LAST thing in your reply, in a single fenced ```python block. Nothing after the closing fence."
|
|
32
|
-
].join("\n");
|
|
33
|
-
function readMeta(task) {
|
|
34
|
-
const md = task.metadata;
|
|
35
|
-
if (!md || typeof md.taskId !== "string") {
|
|
36
|
-
throw new Error(`appworld task ${task.id} missing metadata.taskId \u2014 loadTasks did not populate it`);
|
|
37
|
-
}
|
|
38
|
-
return md;
|
|
39
|
-
}
|
|
40
|
-
async function driver(args, input = "") {
|
|
41
|
-
let stdout;
|
|
42
|
-
try {
|
|
43
|
-
stdout = await runVenvScriptStdin(DRIVER, args, input, { cwd: benchRoot });
|
|
44
|
-
} catch (err) {
|
|
45
|
-
const e = err;
|
|
46
|
-
throw new Error(`appworld driver failed (${args.join(" ")}): ${(e.message || String(err)).slice(0, 1500)}`);
|
|
47
|
-
}
|
|
48
|
-
const last = stdout.trim().split("\n").at(-1) ?? "{}";
|
|
49
|
-
const parsed = JSON.parse(last);
|
|
50
|
-
if (parsed.error) throw new Error(`appworld driver error: ${parsed.error}`);
|
|
51
|
-
return parsed;
|
|
52
|
-
}
|
|
53
|
-
function createAppWorldAdapter() {
|
|
54
|
-
return {
|
|
55
|
-
name: "appworld",
|
|
56
|
-
output: appworldSolutionOutput,
|
|
57
|
-
async preflight() {
|
|
58
|
-
await preflightVenvImports({
|
|
59
|
-
modules: ["appworld"],
|
|
60
|
-
requireDocker: false,
|
|
61
|
-
fix: "Fix: bench/.venv/bin/pip install appworld ; bench/.venv/bin/appworld install ; bench/.venv/bin/appworld download data (unpacks the engine + downloads the simulated-app data/tasks). Set APPWORLD_ROOT to the data root if not the default."
|
|
62
|
-
});
|
|
63
|
-
},
|
|
64
|
-
async loadTasks(opts = {}) {
|
|
65
|
-
const split = opts.split ?? DEFAULT_SPLIT;
|
|
66
|
-
const out = await driver([
|
|
67
|
-
"load",
|
|
68
|
-
"--split",
|
|
69
|
-
split,
|
|
70
|
-
...opts.limit !== void 0 ? ["--limit", String(opts.limit)] : [],
|
|
71
|
-
...opts.ids ? ["--ids", opts.ids.join(",")] : []
|
|
72
|
-
]);
|
|
73
|
-
const tasks = out.tasks ?? [];
|
|
74
|
-
if (tasks.length === 0) {
|
|
75
|
-
throw new Error(`appworld loadTasks returned no tasks for split=${split} ${JSON.stringify(opts)}`);
|
|
76
|
-
}
|
|
77
|
-
return tasks.map(
|
|
78
|
-
(t) => ({
|
|
79
|
-
id: t.task_id,
|
|
80
|
-
split,
|
|
81
|
-
prompt: t.instruction + WORKER_CONTRACT,
|
|
82
|
-
metadata: { taskId: t.task_id, split }
|
|
83
|
-
})
|
|
84
|
-
);
|
|
85
|
-
},
|
|
86
|
-
async goldArtifact() {
|
|
87
|
-
return void 0;
|
|
88
|
-
},
|
|
89
|
-
async judge(task, artifact) {
|
|
90
|
-
const meta = readMeta(task);
|
|
91
|
-
const out = await driver(["evaluate", "--task-id", meta.taskId, "--split", meta.split], artifact);
|
|
92
|
-
const passes = out.passes ?? 0;
|
|
93
|
-
const fails = out.fails ?? 0;
|
|
94
|
-
const total = out.num_tests ?? passes + fails;
|
|
95
|
-
const score = total > 0 ? passes / total : 0;
|
|
96
|
-
const failures = Array.isArray(out.failure_names) ? out.failure_names : [];
|
|
97
|
-
return {
|
|
98
|
-
resolved: out.success === true,
|
|
99
|
-
score,
|
|
100
|
-
detail: JSON.stringify({
|
|
101
|
-
taskId: meta.taskId,
|
|
102
|
-
success: out.success,
|
|
103
|
-
passes,
|
|
104
|
-
fails,
|
|
105
|
-
total,
|
|
106
|
-
...failures.length ? { failures } : {}
|
|
107
|
-
})
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
var REACT_HEADER = /^@appworld-react (\S+) (\S+)\n?/;
|
|
113
|
-
var SESSION_SYSTEM = [
|
|
114
|
-
"You are completing a task in AppWorld, a simulated multi-app environment.",
|
|
115
|
-
"Use the execute_python tool to run Python that calls the app APIs (the `apis.<app>.<function>(...)` surface).",
|
|
116
|
-
"Inspect API docs with `apis.api_docs.show_api_descriptions(app_name=...)` and `apis.api_docs.show_api_doc(app_name=..., api_name=...)`.",
|
|
117
|
-
"Authenticate where needed via the supervisor-provided credentials (`apis.supervisor.show_account_passwords()`).",
|
|
118
|
-
"Work incrementally: small snippets, read each output, correct course.",
|
|
119
|
-
"When every step of the task is done, run `apis.supervisor.complete_task()` and then reply WITHOUT calling the tool again."
|
|
120
|
-
].join("\n");
|
|
121
|
-
var EXECUTE_TOOL = {
|
|
122
|
-
type: "function",
|
|
123
|
-
function: {
|
|
124
|
-
name: "execute_python",
|
|
125
|
-
description: "Execute a Python snippet in the persistent AppWorld world. State persists across calls. Returns the execution output (API results or errors).",
|
|
126
|
-
parameters: {
|
|
127
|
-
type: "object",
|
|
128
|
-
properties: { code: { type: "string", description: "Python code calling apis.<app>.<fn>(...)" } },
|
|
129
|
-
required: ["code"]
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
async function withWorldSession(taskId, split, fn) {
|
|
134
|
-
const child = spawn(venvPython, [DRIVER, "session", "--task-id", taskId, "--split", split], {
|
|
135
|
-
cwd: benchRoot
|
|
136
|
-
});
|
|
137
|
-
const rl = createInterface({ input: child.stdout });
|
|
138
|
-
const pending = [];
|
|
139
|
-
const backlog = [];
|
|
140
|
-
rl.on("line", (l) => {
|
|
141
|
-
const next = pending.shift();
|
|
142
|
-
if (next) next(l);
|
|
143
|
-
else backlog.push(l);
|
|
144
|
-
});
|
|
145
|
-
let stderr = "";
|
|
146
|
-
child.stderr.on("data", (c) => {
|
|
147
|
-
stderr += c.toString("utf8");
|
|
148
|
-
});
|
|
149
|
-
const nextLine = (timeoutMs) => new Promise((resolve, reject) => {
|
|
150
|
-
const fromBacklog = backlog.shift();
|
|
151
|
-
if (fromBacklog !== void 0) return resolve(fromBacklog);
|
|
152
|
-
const t = setTimeout(
|
|
153
|
-
() => reject(new Error(`appworld session: no response in ${timeoutMs}ms; stderr: ${stderr.slice(-400)}`)),
|
|
154
|
-
timeoutMs
|
|
155
|
-
);
|
|
156
|
-
const onExit = (code) => {
|
|
157
|
-
clearTimeout(t);
|
|
158
|
-
reject(new Error(`appworld session exited (${code}); stderr: ${stderr.slice(-400)}`));
|
|
159
|
-
};
|
|
160
|
-
pending.push((l) => {
|
|
161
|
-
clearTimeout(t);
|
|
162
|
-
child.removeListener("exit", onExit);
|
|
163
|
-
resolve(l);
|
|
164
|
-
});
|
|
165
|
-
child.once("exit", onExit);
|
|
166
|
-
});
|
|
167
|
-
try {
|
|
168
|
-
const ready = JSON.parse(await nextLine(12e4));
|
|
169
|
-
if (!ready.ready) throw new Error(`appworld session failed to start: ${ready.error ?? "no ready line"}`);
|
|
170
|
-
const call = async (cmd) => {
|
|
171
|
-
child.stdin.write(`${JSON.stringify(cmd)}
|
|
172
|
-
`);
|
|
173
|
-
const res = JSON.parse(await nextLine(18e4));
|
|
174
|
-
if (typeof res.error === "string") throw new Error(`appworld session op failed: ${res.error}`);
|
|
175
|
-
return res;
|
|
176
|
-
};
|
|
177
|
-
return await fn(call, ready.instruction ?? "");
|
|
178
|
-
} finally {
|
|
179
|
-
child.stdin.end();
|
|
180
|
-
child.kill("SIGTERM");
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
function appworldToolLoopClient(cfg) {
|
|
184
|
-
const maxTurns = cfg.maxTurns ?? Number(process.env.REACT_MAX_TURNS ?? 40);
|
|
185
|
-
let seq = 0;
|
|
186
|
-
return {
|
|
187
|
-
async create() {
|
|
188
|
-
const id = `appworld-toolloop-${seq++}`;
|
|
189
|
-
return {
|
|
190
|
-
id,
|
|
191
|
-
async *streamPrompt(prompt) {
|
|
192
|
-
const m = prompt.match(REACT_HEADER);
|
|
193
|
-
if (!m) {
|
|
194
|
-
throw new Error(
|
|
195
|
-
`appworld-react leaf: prompt missing '@appworld-react <taskId> <split>' header \u2014 got: ${prompt.slice(0, 120)}`
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
const [, taskId, split] = m;
|
|
199
|
-
const directive = prompt.replace(REACT_HEADER, "").trim();
|
|
200
|
-
const out = await withWorldSession(taskId, split, async (call, instruction) => {
|
|
201
|
-
const system = directive ? `${SESSION_SYSTEM}
|
|
202
|
-
|
|
203
|
-
${directive}` : SESSION_SYSTEM;
|
|
204
|
-
const loop = await routerToolLoop(
|
|
205
|
-
{ routerBaseUrl: cfg.routerBaseUrl, routerKey: cfg.routerKey, model: cfg.model },
|
|
206
|
-
system,
|
|
207
|
-
`Task: ${instruction}`,
|
|
208
|
-
[EXECUTE_TOOL],
|
|
209
|
-
async (name, args) => {
|
|
210
|
-
if (name !== "execute_python") return `error: unknown tool ${name}`;
|
|
211
|
-
const res = await call({ op: "execute", code: String(args.code ?? "") });
|
|
212
|
-
const done = res.task_completed === true;
|
|
213
|
-
return `${String(res.output ?? "")}${done ? "\n\n[TASK MARKED COMPLETE \u2014 reply with a final summary and do not call the tool again]" : ""}`;
|
|
214
|
-
},
|
|
215
|
-
{ maxTurns }
|
|
216
|
-
);
|
|
217
|
-
const verdict = await call({ op: "evaluate" });
|
|
218
|
-
const transcript = loop.toolTrace.slice(-3).map((t) => `CODE:
|
|
219
|
-
${t.args.slice(0, 600)}
|
|
220
|
-
OUTPUT:
|
|
221
|
-
${t.result.slice(0, 600)}`).join("\n---\n").slice(0, 1600);
|
|
222
|
-
return {
|
|
223
|
-
...verdict,
|
|
224
|
-
turns: loop.turns,
|
|
225
|
-
input_tokens: loop.usage.input,
|
|
226
|
-
output_tokens: loop.usage.output,
|
|
227
|
-
transcript
|
|
228
|
-
};
|
|
229
|
-
});
|
|
230
|
-
if (out.input_tokens || out.output_tokens) {
|
|
231
|
-
yield {
|
|
232
|
-
type: "llm_call",
|
|
233
|
-
data: { tokensIn: out.input_tokens ?? 0, tokensOut: out.output_tokens ?? 0, model: cfg.model }
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
yield { type: "result", data: { finalText: JSON.stringify(out) } };
|
|
237
|
-
},
|
|
238
|
-
async delete() {
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
var reactEpisodeOutput = {
|
|
245
|
-
parse(events) {
|
|
246
|
-
let text = "";
|
|
247
|
-
for (const ev of events) {
|
|
248
|
-
const d = ev?.data;
|
|
249
|
-
const t = d?.finalText;
|
|
250
|
-
if (typeof t === "string" && t.length > 0) text = t;
|
|
251
|
-
}
|
|
252
|
-
return text;
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
function createAppWorldReactAdapter() {
|
|
256
|
-
const base = createAppWorldAdapter();
|
|
257
|
-
return {
|
|
258
|
-
name: "appworld-react",
|
|
259
|
-
output: reactEpisodeOutput,
|
|
260
|
-
preflight: () => base.preflight(),
|
|
261
|
-
async loadTasks(opts = {}) {
|
|
262
|
-
const tasks = await base.loadTasks(opts);
|
|
263
|
-
return tasks.map((t) => {
|
|
264
|
-
const meta = readMeta(t);
|
|
265
|
-
return {
|
|
266
|
-
...t,
|
|
267
|
-
// Header carries task identity to the leaf; the body (empty at round 0)
|
|
268
|
-
// is the directive slot the arms append their steer into.
|
|
269
|
-
prompt: `@appworld-react ${meta.taskId} ${meta.split}
|
|
270
|
-
`
|
|
271
|
-
};
|
|
272
|
-
});
|
|
273
|
-
},
|
|
274
|
-
goldArtifact: () => Promise.resolve(void 0),
|
|
275
|
-
async judge(task, artifact) {
|
|
276
|
-
const meta = readMeta(task);
|
|
277
|
-
let out;
|
|
278
|
-
try {
|
|
279
|
-
out = JSON.parse(artifact);
|
|
280
|
-
} catch {
|
|
281
|
-
throw new Error(
|
|
282
|
-
`appworld-react judge: artifact is not the episode's evaluation JSON (task ${meta.taskId}): ${artifact.slice(0, 200)}`
|
|
283
|
-
);
|
|
284
|
-
}
|
|
285
|
-
if (typeof out.success !== "boolean" || typeof out.num_tests !== "number") {
|
|
286
|
-
throw new Error(
|
|
287
|
-
`appworld-react judge: episode JSON missing success/num_tests (task ${meta.taskId}): ${artifact.slice(0, 200)}`
|
|
288
|
-
);
|
|
289
|
-
}
|
|
290
|
-
const passes = out.passes ?? 0;
|
|
291
|
-
const total = out.num_tests;
|
|
292
|
-
const failures = Array.isArray(out.failure_names) ? out.failure_names : [];
|
|
293
|
-
return {
|
|
294
|
-
resolved: out.success === true,
|
|
295
|
-
score: total > 0 ? passes / total : 0,
|
|
296
|
-
detail: JSON.stringify({
|
|
297
|
-
taskId: meta.taskId,
|
|
298
|
-
success: out.success,
|
|
299
|
-
passes,
|
|
300
|
-
fails: out.fails ?? 0,
|
|
301
|
-
total,
|
|
302
|
-
turns: out.turns,
|
|
303
|
-
...failures.length ? { failures } : {},
|
|
304
|
-
...out.transcript ? { transcriptTail: out.transcript.slice(-800) } : {}
|
|
305
|
-
})
|
|
306
|
-
};
|
|
307
|
-
},
|
|
308
|
-
leafClient: (c) => appworldToolLoopClient(c)
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
export {
|
|
313
|
-
appworldSolutionOutput,
|
|
314
|
-
createAppWorldAdapter,
|
|
315
|
-
appworldToolLoopClient,
|
|
316
|
-
createAppWorldReactAdapter
|
|
317
|
-
};
|
|
318
|
-
//# sourceMappingURL=chunk-CXDUTWQE.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/benchmarks/appworld.ts"],"sourcesContent":["/**\n * AppWorld adapter (StonyBrookNLP/appworld). Worker artifact = the agent's\n * Python solution that calls the simulated apps' APIs (the same `apis.<app>.<fn>`\n * surface AppWorld exposes inside `world.execute(...)`), ending in\n * `apis.supervisor.complete_task()`. Judge = AppWorld's OWN programmatic\n * evaluator: a driver runs the solution in a fresh `AppWorld(task_id=...)` world,\n * then `world.evaluate().to_dict()` reports `success` (binary TGC), `num_tests`\n * (per-requirement total) and the `passes`/`failures` lists. Score =\n * passes / num_tests — GRADED; resolved = success. Fully deterministic — no LLM judge.\n *\n * loadTasks enumerates the real task suite via `load_task_ids(split)`\n * (train|dev|test_normal|test_challenge); the prompt = `world.task.instruction`.\n * The OutputAdapter is stream-only, so the worker emits its solution as a fenced\n * ```python block which the driver executes.\n *\n * Requires for a live run: the bench `.venv` with `appworld` installed + the\n * unpacked engine + downloaded data (`appworld install` ; `appworld download\n * data`). preflight + loadTasks + judge all fail loud with the exact step when the\n * engine/data is absent — never a fabricated score.\n */\n\nimport { spawn } from 'node:child_process'\nimport { join } from 'node:path'\nimport { createInterface } from 'node:readline'\nimport { type OutputAdapter, routerToolLoop, type ToolSpec } from '@tangle-network/agent-runtime/loops'\nimport { benchRoot, preflightVenvImports, runVenvScriptStdin, venvPython } from './_harness'\nimport type { BenchmarkAdapter, BenchScore, BenchTask, LoadOptions } from './types'\n\nconst DRIVER = join(benchRoot, 'scripts', 'appworld_driver.py')\n\n/** AppWorld splits; only the test splits ship evaluation-only (no setup/solution). */\nconst DEFAULT_SPLIT = 'test_normal'\n\ninterface AppWorldMeta {\n taskId: string\n split: string\n}\n\n/** Worker solution code = the last fenced ```python block, else the raw text. */\nexport const appworldSolutionOutput: OutputAdapter<string> = {\n parse(events) {\n let text = ''\n for (const ev of events) {\n const d = (ev as { data?: Record<string, unknown> })?.data\n const t = d?.finalText ?? d?.text ?? d?.result\n if (typeof t === 'string' && t.length > 0) text = t\n }\n const fences = [...text.matchAll(/```(?:python|py)?\\s*\\n([\\s\\S]*?)```/g)]\n return (fences.at(-1)?.[1] ?? text).trim()\n },\n}\n\nconst WORKER_CONTRACT = [\n '',\n 'Solve this by writing Python that calls the available app APIs (the `apis.<app>.<function>(...)` surface). You may inspect API docs with `apis.api_docs.show_api_descriptions(app_name=...)` and `apis.api_docs.show_api_doc(app_name=..., api_name=...)`.',\n 'Authenticate where needed via the supervisor-provided credentials, perform every step the task requires, and FINISH with `apis.supervisor.complete_task()`.',\n 'Emit your COMPLETE solution as the LAST thing in your reply, in a single fenced ```python block. Nothing after the closing fence.',\n].join('\\n')\n\nfunction readMeta(task: BenchTask): AppWorldMeta {\n const md = task.metadata\n if (!md || typeof md.taskId !== 'string') {\n throw new Error(`appworld task ${task.id} missing metadata.taskId — loadTasks did not populate it`)\n }\n return md as unknown as AppWorldMeta\n}\n\n/**\n * Run the appworld engine driver with a subcommand; JSON on the LAST stdout line.\n * The solution code (evaluate) is piped to stdin via the shared stdin-aware runner —\n * execFile's `input` option is not honored async and hangs the driver's\n * sys.stdin.read() forever. `load` ignores stdin, so an empty pipe is harmless.\n */\nasync function driver(args: string[], input = ''): Promise<unknown> {\n let stdout: string\n try {\n stdout = await runVenvScriptStdin(DRIVER, args, input, { cwd: benchRoot })\n } catch (err) {\n const e = err as { message?: string }\n throw new Error(`appworld driver failed (${args.join(' ')}): ${(e.message || String(err)).slice(0, 1500)}`)\n }\n const last = stdout.trim().split('\\n').at(-1) ?? '{}'\n const parsed = JSON.parse(last) as { error?: string }\n if (parsed.error) throw new Error(`appworld driver error: ${parsed.error}`)\n return parsed\n}\n\nexport function createAppWorldAdapter(): BenchmarkAdapter {\n return {\n name: 'appworld',\n output: appworldSolutionOutput,\n\n async preflight() {\n await preflightVenvImports({\n modules: ['appworld'],\n requireDocker: false,\n fix:\n 'Fix: bench/.venv/bin/pip install appworld ; ' +\n 'bench/.venv/bin/appworld install ; bench/.venv/bin/appworld download data ' +\n '(unpacks the engine + downloads the simulated-app data/tasks). ' +\n 'Set APPWORLD_ROOT to the data root if not the default.',\n })\n },\n\n async loadTasks(opts: LoadOptions = {}): Promise<BenchTask[]> {\n const split = opts.split ?? DEFAULT_SPLIT\n const out = (await driver([\n 'load',\n '--split', split,\n ...(opts.limit !== undefined ? ['--limit', String(opts.limit)] : []),\n ...(opts.ids ? ['--ids', opts.ids.join(',')] : []),\n ])) as { tasks?: Array<{ task_id: string; instruction: string }> }\n const tasks = out.tasks ?? []\n if (tasks.length === 0) {\n throw new Error(`appworld loadTasks returned no tasks for split=${split} ${JSON.stringify(opts)}`)\n }\n return tasks.map(\n (t): BenchTask => ({\n id: t.task_id,\n split,\n prompt: t.instruction + WORKER_CONTRACT,\n metadata: { taskId: t.task_id, split } as unknown as Record<string, unknown>,\n }),\n )\n },\n\n async goldArtifact() {\n // Reference solution code ships only for train/dev, and only inside the\n // engine's decrypted `.bundle` (it is not a portable string this adapter can\n // emit across splits). The test splits are evaluation-only. So verify-judge\n // here requires a real solve on a train/dev task through the live engine\n // rather than a synthetic gold — returning a fabricated artifact would be a\n // fake. Returns undefined.\n return undefined\n },\n\n async judge(task: BenchTask, artifact: string): Promise<BenchScore> {\n const meta = readMeta(task)\n const out = (await driver(['evaluate', '--task-id', meta.taskId, '--split', meta.split], artifact)) as {\n success?: boolean\n passes?: number\n fails?: number\n num_tests?: number\n failure_names?: string[]\n }\n const passes = out.passes ?? 0\n const fails = out.fails ?? 0\n // num_tests is the evaluator's authoritative per-requirement count; prefer it\n // over passes+fails (which can disagree if a requirement neither passed nor\n // failed). Never default the total to a phantom denominator.\n const total = out.num_tests ?? passes + fails\n const score = total > 0 ? passes / total : 0\n // failure_names = WHICH sub-tests failed — the evidence a trace analyst\n // steers on. Carried in `detail` so it reaches the verdict's `notes`.\n const failures = Array.isArray(out.failure_names) ? out.failure_names : []\n return {\n resolved: out.success === true,\n score,\n detail: JSON.stringify({\n taskId: meta.taskId,\n success: out.success,\n passes,\n fails,\n total,\n ...(failures.length ? { failures } : {}),\n }),\n }\n },\n }\n}\n\n/**\n * AppWorld in its NATIVE protocol, run by OUR runtime: the worker is\n * `routerToolLoop` (the runtime's off-box agentic tool loop) with one tool —\n * `execute_python` — bound to a persistent AppWorld world session. The driver's\n * `session` subcommand is a dumb world shim (stdin JSONL: execute → output,\n * evaluate → verdict); every inference turn, the metering, and the typed\n * toolTrace the analyst steers on belong to the runtime, so runtime\n * improvements are what this benchmark measures.\n *\n * The one-shot codegen adapter above plays a strictly harder game (no execution\n * feedback — the first wrong API call kills the whole program at judge time),\n * which flatlines the score against ANY steering; this mode is what the\n * benchmark's published baselines use, where behavior can move sub-tests.\n *\n * Protocol: the round task string is `@appworld-react <taskId> <split>` on\n * line 1; everything after line 1 is the steer (an analyst correction, a push\n * directive) appended to the system prompt — so the existing arms steer this\n * worker without modification. The artifact is the episode evaluation JSON\n * (AppWorld's evaluator ran in-world); judge() parses it, never re-executes.\n */\n\ninterface ReactResult {\n success?: boolean\n passes?: number\n fails?: number\n num_tests?: number\n failure_names?: string[]\n turns?: number\n input_tokens?: number\n output_tokens?: number\n transcript?: string\n}\n\nconst REACT_HEADER = /^@appworld-react (\\S+) (\\S+)\\n?/\n\nconst SESSION_SYSTEM = [\n 'You are completing a task in AppWorld, a simulated multi-app environment.',\n 'Use the execute_python tool to run Python that calls the app APIs (the `apis.<app>.<function>(...)` surface).',\n 'Inspect API docs with `apis.api_docs.show_api_descriptions(app_name=...)` and `apis.api_docs.show_api_doc(app_name=..., api_name=...)`.',\n 'Authenticate where needed via the supervisor-provided credentials (`apis.supervisor.show_account_passwords()`).',\n 'Work incrementally: small snippets, read each output, correct course.',\n 'When every step of the task is done, run `apis.supervisor.complete_task()` and then reply WITHOUT calling the tool again.',\n].join('\\n')\n\nconst EXECUTE_TOOL: ToolSpec = {\n type: 'function',\n function: {\n name: 'execute_python',\n description:\n 'Execute a Python snippet in the persistent AppWorld world. State persists across calls. Returns the execution output (API results or errors).',\n parameters: {\n type: 'object',\n properties: { code: { type: 'string', description: 'Python code calling apis.<app>.<fn>(...)' } },\n required: ['code'],\n },\n },\n}\n\n/** One persistent world session: line-JSONL request/response over the driver. */\nasync function withWorldSession<T>(\n taskId: string,\n split: string,\n fn: (call: (cmd: Record<string, unknown>) => Promise<Record<string, unknown>>, instruction: string) => Promise<T>,\n): Promise<T> {\n const child = spawn(venvPython, [DRIVER, 'session', '--task-id', taskId, '--split', split], {\n cwd: benchRoot,\n })\n const rl = createInterface({ input: child.stdout })\n const pending: Array<(line: string) => void> = []\n const backlog: string[] = []\n rl.on('line', (l) => {\n const next = pending.shift()\n if (next) next(l)\n else backlog.push(l)\n })\n let stderr = ''\n child.stderr.on('data', (c: Buffer) => {\n stderr += c.toString('utf8')\n })\n const nextLine = (timeoutMs: number): Promise<string> =>\n new Promise((resolve, reject) => {\n const fromBacklog = backlog.shift()\n if (fromBacklog !== undefined) return resolve(fromBacklog)\n const t = setTimeout(\n () => reject(new Error(`appworld session: no response in ${timeoutMs}ms; stderr: ${stderr.slice(-400)}`)),\n timeoutMs,\n )\n // One exit listener per await leaks (25-turn episodes blow the listener\n // cap) — remove it on the resolve path.\n const onExit = (code: number | null): void => {\n clearTimeout(t)\n reject(new Error(`appworld session exited (${code}); stderr: ${stderr.slice(-400)}`))\n }\n pending.push((l) => {\n clearTimeout(t)\n child.removeListener('exit', onExit)\n resolve(l)\n })\n child.once('exit', onExit)\n })\n try {\n const ready = JSON.parse(await nextLine(120_000)) as { ready?: boolean; instruction?: string; error?: string }\n if (!ready.ready) throw new Error(`appworld session failed to start: ${ready.error ?? 'no ready line'}`)\n const call = async (cmd: Record<string, unknown>): Promise<Record<string, unknown>> => {\n child.stdin.write(`${JSON.stringify(cmd)}\\n`)\n const res = JSON.parse(await nextLine(180_000)) as Record<string, unknown>\n if (typeof res.error === 'string') throw new Error(`appworld session op failed: ${res.error}`)\n return res\n }\n return await fn(call, ready.instruction ?? '')\n } finally {\n child.stdin.end()\n child.kill('SIGTERM')\n }\n}\n\n/** SandboxClient whose leaf is OUR routerToolLoop driving a persistent world session. */\nexport function appworldToolLoopClient(cfg: {\n model: string\n routerBaseUrl: string\n routerKey: string\n maxTurns?: number\n}): unknown {\n const maxTurns = cfg.maxTurns ?? Number(process.env.REACT_MAX_TURNS ?? 40)\n let seq = 0\n return {\n async create() {\n const id = `appworld-toolloop-${seq++}`\n return {\n id,\n async *streamPrompt(prompt: string) {\n const m = prompt.match(REACT_HEADER)\n if (!m) {\n throw new Error(\n `appworld-react leaf: prompt missing '@appworld-react <taskId> <split>' header — got: ${prompt.slice(0, 120)}`,\n )\n }\n const [, taskId, split] = m\n const directive = prompt.replace(REACT_HEADER, '').trim()\n const out = await withWorldSession(taskId as string, split as string, async (call, instruction) => {\n const system = directive ? `${SESSION_SYSTEM}\\n\\n${directive}` : SESSION_SYSTEM\n const loop = await routerToolLoop(\n { routerBaseUrl: cfg.routerBaseUrl, routerKey: cfg.routerKey, model: cfg.model },\n system,\n `Task: ${instruction}`,\n [EXECUTE_TOOL],\n async (name, args) => {\n if (name !== 'execute_python') return `error: unknown tool ${name}`\n const res = await call({ op: 'execute', code: String(args.code ?? '') })\n const done = res.task_completed === true\n return `${String(res.output ?? '')}${done ? '\\n\\n[TASK MARKED COMPLETE — reply with a final summary and do not call the tool again]' : ''}`\n },\n { maxTurns },\n )\n const verdict = (await call({ op: 'evaluate' })) as unknown as ReactResult\n const transcript = loop.toolTrace\n .slice(-3)\n .map((t) => `CODE:\\n${t.args.slice(0, 600)}\\nOUTPUT:\\n${t.result.slice(0, 600)}`)\n .join('\\n---\\n')\n .slice(0, 1600)\n return {\n ...verdict,\n turns: loop.turns,\n input_tokens: loop.usage.input,\n output_tokens: loop.usage.output,\n transcript,\n } satisfies ReactResult\n })\n // Real usage from the episode — flat llm_call so the kernel meters it.\n if (out.input_tokens || out.output_tokens) {\n yield {\n type: 'llm_call',\n data: { tokensIn: out.input_tokens ?? 0, tokensOut: out.output_tokens ?? 0, model: cfg.model },\n }\n }\n yield { type: 'result', data: { finalText: JSON.stringify(out) } }\n },\n async delete() {},\n }\n },\n }\n}\n\n/** Artifact = the episode's evaluation JSON, verbatim (no fence extraction). */\nconst reactEpisodeOutput: OutputAdapter<string> = {\n parse(events) {\n let text = ''\n for (const ev of events) {\n const d = (ev as { data?: Record<string, unknown> })?.data\n const t = d?.finalText\n if (typeof t === 'string' && t.length > 0) text = t\n }\n return text\n },\n}\n\nexport function createAppWorldReactAdapter(): BenchmarkAdapter {\n const base = createAppWorldAdapter()\n return {\n name: 'appworld-react',\n output: reactEpisodeOutput,\n preflight: () => base.preflight(),\n\n async loadTasks(opts: LoadOptions = {}): Promise<BenchTask[]> {\n const tasks = await base.loadTasks(opts)\n return tasks.map((t) => {\n const meta = readMeta(t)\n return {\n ...t,\n // Header carries task identity to the leaf; the body (empty at round 0)\n // is the directive slot the arms append their steer into.\n prompt: `@appworld-react ${meta.taskId} ${meta.split}\\n`,\n }\n })\n },\n\n goldArtifact: () => Promise.resolve(undefined),\n\n async judge(task: BenchTask, artifact: string): Promise<BenchScore> {\n const meta = readMeta(task)\n let out: ReactResult\n try {\n out = JSON.parse(artifact) as ReactResult\n } catch {\n throw new Error(\n `appworld-react judge: artifact is not the episode's evaluation JSON (task ${meta.taskId}): ${artifact.slice(0, 200)}`,\n )\n }\n if (typeof out.success !== 'boolean' || typeof out.num_tests !== 'number') {\n throw new Error(\n `appworld-react judge: episode JSON missing success/num_tests (task ${meta.taskId}): ${artifact.slice(0, 200)}`,\n )\n }\n const passes = out.passes ?? 0\n const total = out.num_tests\n const failures = Array.isArray(out.failure_names) ? out.failure_names : []\n return {\n resolved: out.success === true,\n score: total > 0 ? passes / total : 0,\n detail: JSON.stringify({\n taskId: meta.taskId,\n success: out.success,\n passes,\n fails: out.fails ?? 0,\n total,\n turns: out.turns,\n ...(failures.length ? { failures } : {}),\n ...(out.transcript ? { transcriptTail: out.transcript.slice(-800) } : {}),\n }),\n }\n },\n\n leafClient: (c) => appworldToolLoopClient(c),\n }\n}\n"],"mappings":";;;;;;;;AAqBA,SAAS,aAAa;AACtB,SAAS,YAAY;AACrB,SAAS,uBAAuB;AAChC,SAA6B,sBAAqC;AAIlE,IAAM,SAAS,KAAK,WAAW,WAAW,oBAAoB;AAG9D,IAAM,gBAAgB;AAQf,IAAM,yBAAgD;AAAA,EAC3D,MAAM,QAAQ;AACZ,QAAI,OAAO;AACX,eAAW,MAAM,QAAQ;AACvB,YAAM,IAAK,IAA2C;AACtD,YAAM,IAAI,GAAG,aAAa,GAAG,QAAQ,GAAG;AACxC,UAAI,OAAO,MAAM,YAAY,EAAE,SAAS,EAAG,QAAO;AAAA,IACpD;AACA,UAAM,SAAS,CAAC,GAAG,KAAK,SAAS,sCAAsC,CAAC;AACxE,YAAQ,OAAO,GAAG,EAAE,IAAI,CAAC,KAAK,MAAM,KAAK;AAAA,EAC3C;AACF;AAEA,I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Q,IAAI;AAClB,YAAM,WAAW,MAAM,QAAQ,IAAI,aAAa,IAAI,IAAI,gBAAgB,CAAC;AACzE,aAAO;AAAA,QACL,UAAU,IAAI,YAAY;AAAA,QAC1B,OAAO,QAAQ,IAAI,SAAS,QAAQ;AAAA,QACpC,QAAQ,KAAK,UAAU;AAAA,UACrB,QAAQ,KAAK;AAAA,UACb,SAAS,IAAI;AAAA,UACb;AAAA,UACA,OAAO,IAAI,SAAS;AAAA,UACpB;AAAA,UACA,OAAO,IAAI;AAAA,UACX,GAAI,SAAS,SAAS,EAAE,SAAS,IAAI,CAAC;AAAA,UACtC,GAAI,IAAI,aAAa,EAAE,gBAAgB,IAAI,WAAW,MAAM,IAAI,EAAE,IAAI,CAAC;AAAA,QACzE,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IAEA,YAAY,CAAC,MAAM,uBAAuB,CAAC;AAAA,EAC7C;AACF;","names":[]}
|
package/dist/chunk-DWALFME7.js
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
benchRoot,
|
|
3
|
-
runVenvPython,
|
|
4
|
-
runVenvScriptStdin
|
|
5
|
-
} from "./chunk-EIETHPD5.js";
|
|
6
|
-
|
|
7
|
-
// src/benchmarks/dabstep.ts
|
|
8
|
-
import { join } from "path";
|
|
9
|
-
import { access, readFile, stat } from "fs/promises";
|
|
10
|
-
var FIXTURES = join(benchRoot, "fixtures", "dabstep.json");
|
|
11
|
-
var DEFAULT_SPLIT = "easy";
|
|
12
|
-
var dabstepDir = () => process.env.DABSTEP_DIR;
|
|
13
|
-
var gradeFile = (dir) => join(dir, "grade.py");
|
|
14
|
-
var resourceRoot = (dir) => join(dir, "files");
|
|
15
|
-
async function assertFile(path, label) {
|
|
16
|
-
try {
|
|
17
|
-
await access(path);
|
|
18
|
-
} catch (err) {
|
|
19
|
-
throw new Error(`DABStep: missing ${label} at ${path} (${err instanceof Error ? err.message : err})`);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
async function assertOfficialFiles(dir, split) {
|
|
23
|
-
await assertFile(join(dir, "dataset.csv"), "released dataset.csv");
|
|
24
|
-
await assertFile(join(dir, "splits", `${split}.txt`), `${split} split file`);
|
|
25
|
-
await assertFile(gradeFile(dir), "official grade.py");
|
|
26
|
-
const files = resourceRoot(dir);
|
|
27
|
-
try {
|
|
28
|
-
const s = await stat(files);
|
|
29
|
-
if (!s.isDirectory()) throw new Error("not a directory");
|
|
30
|
-
} catch (err) {
|
|
31
|
-
throw new Error(`DABStep: missing benchmark files directory at ${files} (${err instanceof Error ? err.message : err})`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
var dabstepAnswerOutput = {
|
|
35
|
-
parse(events) {
|
|
36
|
-
let text = "";
|
|
37
|
-
for (const ev of events) {
|
|
38
|
-
const d = ev?.data;
|
|
39
|
-
const t = d?.finalText ?? d?.text ?? d?.result;
|
|
40
|
-
if (typeof t === "string" && t.length > 0) text = t;
|
|
41
|
-
}
|
|
42
|
-
const fences = [...text.matchAll(/```(?:text|answer)?\s*\n([\s\S]*?)```/g)];
|
|
43
|
-
return (fences.at(-1)?.[1] ?? text).trim();
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
function rowToTask(row, split, dir) {
|
|
47
|
-
const meta = {
|
|
48
|
-
taskId: row.task_id,
|
|
49
|
-
split,
|
|
50
|
-
golds: row.all_golds_by_task,
|
|
51
|
-
...dir ? { resourceRoot: resourceRoot(dir) } : {}
|
|
52
|
-
};
|
|
53
|
-
return {
|
|
54
|
-
id: String(row.task_id),
|
|
55
|
-
split,
|
|
56
|
-
prompt: [
|
|
57
|
-
"Solve this DABStep data-analysis task using the mounted payment files.",
|
|
58
|
-
"Use code or shell commands as needed, then return only the final answer.",
|
|
59
|
-
"",
|
|
60
|
-
row.instructions
|
|
61
|
-
].join("\n"),
|
|
62
|
-
metadata: meta
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
function readMeta(task) {
|
|
66
|
-
const md = task.metadata;
|
|
67
|
-
if (!md || typeof md.taskId !== "number" || !Array.isArray(md.golds)) {
|
|
68
|
-
throw new Error(`dabstep task ${task.id} missing metadata \u2014 loadTasks did not populate it`);
|
|
69
|
-
}
|
|
70
|
-
return md;
|
|
71
|
-
}
|
|
72
|
-
function selectRows(rows, opts, split, dir) {
|
|
73
|
-
let tasks = rows.map((row) => rowToTask(row, split, dir));
|
|
74
|
-
if (opts.ids) {
|
|
75
|
-
const want = new Set(opts.ids);
|
|
76
|
-
tasks = tasks.filter((task) => want.has(task.id));
|
|
77
|
-
} else if (opts.limit !== void 0) {
|
|
78
|
-
tasks = tasks.slice(0, opts.limit);
|
|
79
|
-
}
|
|
80
|
-
if (tasks.length === 0) throw new Error(`DABStep: no tasks matched ${JSON.stringify(opts)} for split=${split}`);
|
|
81
|
-
return tasks;
|
|
82
|
-
}
|
|
83
|
-
async function loadFixtures(opts, split) {
|
|
84
|
-
const rows = JSON.parse(await readFile(FIXTURES, "utf8"));
|
|
85
|
-
console.warn(`[dabstep] DABSTEP_FIXTURES=1 \u2014 loading ${rows.length} adapter fixtures from ${FIXTURES}`);
|
|
86
|
-
return selectRows(rows, opts, split);
|
|
87
|
-
}
|
|
88
|
-
async function loadOfficialTasks(dir, opts, split) {
|
|
89
|
-
const script = `
|
|
90
|
-
import ast, csv, json, sys
|
|
91
|
-
from pathlib import Path
|
|
92
|
-
|
|
93
|
-
root = Path(sys.argv[1])
|
|
94
|
-
split = sys.argv[2]
|
|
95
|
-
limit = None if sys.argv[3] == "" else int(sys.argv[3])
|
|
96
|
-
ids = set(json.loads(sys.argv[4]))
|
|
97
|
-
dataset = root / "dataset.csv"
|
|
98
|
-
split_file = root / "splits" / f"{split}.txt"
|
|
99
|
-
if not dataset.exists():
|
|
100
|
-
raise SystemExit(f"missing official DABStep dataset.csv at {dataset}")
|
|
101
|
-
if not split_file.exists():
|
|
102
|
-
raise SystemExit(f"missing official DABStep split file at {split_file}")
|
|
103
|
-
split_ids = {int(line.strip()) for line in split_file.read_text().splitlines() if line.strip()}
|
|
104
|
-
out = []
|
|
105
|
-
with dataset.open(newline="") as f:
|
|
106
|
-
for row in csv.DictReader(f):
|
|
107
|
-
task_id = int(row["task_id"])
|
|
108
|
-
if task_id not in split_ids:
|
|
109
|
-
continue
|
|
110
|
-
if ids and str(task_id) not in ids:
|
|
111
|
-
continue
|
|
112
|
-
out.append({
|
|
113
|
-
"task_id": task_id,
|
|
114
|
-
"instructions": f"{row['question']}\\n{row['guidelines']}",
|
|
115
|
-
"all_golds_by_task": ast.literal_eval(str(row["all_golds_by_task"])),
|
|
116
|
-
})
|
|
117
|
-
if limit is not None and len(out) >= limit:
|
|
118
|
-
break
|
|
119
|
-
if not out:
|
|
120
|
-
raise SystemExit(f"no DABStep rows matched split={split} ids={sorted(ids)} limit={limit}")
|
|
121
|
-
print(json.dumps(out))
|
|
122
|
-
`;
|
|
123
|
-
const stdout = await runVenvPython(script, [dir, split, opts.limit === void 0 ? "" : String(opts.limit), JSON.stringify(opts.ids ?? [])]);
|
|
124
|
-
return selectRows(JSON.parse(stdout), opts, split, dir);
|
|
125
|
-
}
|
|
126
|
-
function createDabstepAdapter() {
|
|
127
|
-
const fixturesMode = process.env.DABSTEP_FIXTURES === "1";
|
|
128
|
-
return {
|
|
129
|
-
name: "dabstep",
|
|
130
|
-
output: dabstepAnswerOutput,
|
|
131
|
-
async preflight() {
|
|
132
|
-
if (fixturesMode) return;
|
|
133
|
-
const dir = dabstepDir();
|
|
134
|
-
if (!dir) {
|
|
135
|
-
throw new Error(
|
|
136
|
-
"DABSTEP_DIR is required. Fix: clone https://github.com/EnvCommons/DABStep, add the released dataset.csv under that checkout, then set DABSTEP_DIR=/path/to/DABStep."
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
await assertOfficialFiles(dir, DEFAULT_SPLIT);
|
|
140
|
-
await loadOfficialTasks(dir, { limit: 1 }, DEFAULT_SPLIT);
|
|
141
|
-
},
|
|
142
|
-
async loadTasks(opts = {}) {
|
|
143
|
-
const split = opts.split ?? DEFAULT_SPLIT;
|
|
144
|
-
if (fixturesMode) return loadFixtures(opts, split);
|
|
145
|
-
const dir = dabstepDir();
|
|
146
|
-
if (!dir) throw new Error("DABSTEP_DIR is required to load official DABStep tasks");
|
|
147
|
-
return loadOfficialTasks(dir, opts, split);
|
|
148
|
-
},
|
|
149
|
-
async goldArtifact(task) {
|
|
150
|
-
const meta = readMeta(task);
|
|
151
|
-
const first = meta.golds[0];
|
|
152
|
-
if (!first) return void 0;
|
|
153
|
-
const value = first.value;
|
|
154
|
-
return value === void 0 ? void 0 : String(value);
|
|
155
|
-
},
|
|
156
|
-
async judge(task, artifact) {
|
|
157
|
-
const meta = readMeta(task);
|
|
158
|
-
const dir = dabstepDir();
|
|
159
|
-
if (!dir) throw new Error("DABSTEP_DIR is required to judge DABStep tasks with the official grade.py");
|
|
160
|
-
const stdout = await runVenvScriptStdin(
|
|
161
|
-
join(benchRoot, "scripts", "dabstep_judge.py"),
|
|
162
|
-
["--grade-file", gradeFile(dir)],
|
|
163
|
-
JSON.stringify({ prediction: artifact, golds: meta.golds }),
|
|
164
|
-
{ cwd: benchRoot }
|
|
165
|
-
);
|
|
166
|
-
const report = JSON.parse(stdout.trim().split("\n").at(-1) ?? "{}");
|
|
167
|
-
if (report.error) throw new Error(`DABStep judge error for ${task.id}: ${report.error}`);
|
|
168
|
-
const score = typeof report.score === "number" ? report.score : 0;
|
|
169
|
-
return {
|
|
170
|
-
resolved: report.correct === true,
|
|
171
|
-
score,
|
|
172
|
-
detail: JSON.stringify({ taskId: meta.taskId, split: meta.split, correct: report.correct })
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export {
|
|
179
|
-
dabstepAnswerOutput,
|
|
180
|
-
createDabstepAdapter
|
|
181
|
-
};
|
|
182
|
-
//# sourceMappingURL=chunk-DWALFME7.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/benchmarks/dabstep.ts"],"sourcesContent":["/**\n * DABStep adapter (EnvCommons/DABStep) — data-analysis questions over synthetic\n * payment files. Worker artifact = final answer text. Judge = the official\n * DABStep `grade.py` normalization/matching function. No LLM judge.\n *\n * Live tasks require `DABSTEP_DIR` pointing at an official DABStep checkout that\n * includes `dataset.csv`, `splits/*.txt`, `files/*`, and `grade.py`. The adapter\n * exposes `metadata.resourceRoot` so runners can mount the benchmark files into\n * AgentProfile.resources.files; it does not paste the dataset into prompt text.\n */\n\nimport { join } from 'node:path'\nimport { access, readFile, stat } from 'node:fs/promises'\nimport type { OutputAdapter } from '@tangle-network/agent-runtime/loops'\nimport { benchRoot, runVenvPython, runVenvScriptStdin } from './_harness'\nimport type { BenchmarkAdapter, BenchScore, BenchTask, LoadOptions } from './types'\n\nconst FIXTURES = join(benchRoot, 'fixtures', 'dabstep.json')\nconst DEFAULT_SPLIT = 'easy'\n\ninterface DabstepFixtureRow {\n task_id: number\n instructions: string\n all_golds_by_task: Array<Record<string, unknown>>\n}\n\ninterface DabstepMeta {\n taskId: number\n split: string\n golds: Array<Record<string, unknown>>\n resourceRoot?: string\n}\n\nconst dabstepDir = (): string | undefined => process.env.DABSTEP_DIR\nconst gradeFile = (dir: string): string => join(dir, 'grade.py')\nconst resourceRoot = (dir: string): string => join(dir, 'files')\n\nasync function assertFile(path: string, label: string): Promise<void> {\n try {\n await access(path)\n } catch (err) {\n throw new Error(`DABStep: missing ${label} at ${path} (${err instanceof Error ? err.message : err})`)\n }\n}\n\nasync function assertOfficialFiles(dir: string, split: string): Promise<void> {\n await assertFile(join(dir, 'dataset.csv'), 'released dataset.csv')\n await assertFile(join(dir, 'splits', `${split}.txt`), `${split} split file`)\n await assertFile(gradeFile(dir), 'official grade.py')\n const files = resourceRoot(dir)\n try {\n const s = await stat(files)\n if (!s.isDirectory()) throw new Error('not a directory')\n } catch (err) {\n throw new Error(`DABStep: missing benchmark files directory at ${files} (${err instanceof Error ? err.message : err})`)\n }\n}\n\nexport const dabstepAnswerOutput: OutputAdapter<string> = {\n parse(events) {\n let text = ''\n for (const ev of events) {\n const d = (ev as { data?: Record<string, unknown> })?.data\n const t = d?.finalText ?? d?.text ?? d?.result\n if (typeof t === 'string' && t.length > 0) text = t\n }\n const fences = [...text.matchAll(/```(?:text|answer)?\\s*\\n([\\s\\S]*?)```/g)]\n return (fences.at(-1)?.[1] ?? text).trim()\n },\n}\n\nfunction rowToTask(row: DabstepFixtureRow, split: string, dir?: string): BenchTask {\n const meta: DabstepMeta = {\n taskId: row.task_id,\n split,\n golds: row.all_golds_by_task,\n ...(dir ? { resourceRoot: resourceRoot(dir) } : {}),\n }\n return {\n id: String(row.task_id),\n split,\n prompt: [\n 'Solve this DABStep data-analysis task using the mounted payment files.',\n 'Use code or shell commands as needed, then return only the final answer.',\n '',\n row.instructions,\n ].join('\\n'),\n metadata: meta as unknown as Record<string, unknown>,\n }\n}\n\nfunction readMeta(task: BenchTask): DabstepMeta {\n const md = task.metadata\n if (!md || typeof md.taskId !== 'number' || !Array.isArray(md.golds)) {\n throw new Error(`dabstep task ${task.id} missing metadata — loadTasks did not populate it`)\n }\n return md as unknown as DabstepMeta\n}\n\nfunction selectRows(rows: DabstepFixtureRow[], opts: LoadOptions, split: string, dir?: string): BenchTask[] {\n let tasks = rows.map((row) => rowToTask(row, split, dir))\n if (opts.ids) {\n const want = new Set(opts.ids)\n tasks = tasks.filter((task) => want.has(task.id))\n } else if (opts.limit !== undefined) {\n tasks = tasks.slice(0, opts.limit)\n }\n if (tasks.length === 0) throw new Error(`DABStep: no tasks matched ${JSON.stringify(opts)} for split=${split}`)\n return tasks\n}\n\nasync function loadFixtures(opts: LoadOptions, split: string): Promise<BenchTask[]> {\n const rows = JSON.parse(await readFile(FIXTURES, 'utf8')) as DabstepFixtureRow[]\n console.warn(`[dabstep] DABSTEP_FIXTURES=1 — loading ${rows.length} adapter fixtures from ${FIXTURES}`)\n return selectRows(rows, opts, split)\n}\n\nasync function loadOfficialTasks(dir: string, opts: LoadOptions, split: string): Promise<BenchTask[]> {\n const script = `\nimport ast, csv, json, sys\nfrom pathlib import Path\n\nroot = Path(sys.argv[1])\nsplit = sys.argv[2]\nlimit = None if sys.argv[3] == \"\" else int(sys.argv[3])\nids = set(json.loads(sys.argv[4]))\ndataset = root / \"dataset.csv\"\nsplit_file = root / \"splits\" / f\"{split}.txt\"\nif not dataset.exists():\n raise SystemExit(f\"missing official DABStep dataset.csv at {dataset}\")\nif not split_file.exists():\n raise SystemExit(f\"missing official DABStep split file at {split_file}\")\nsplit_ids = {int(line.strip()) for line in split_file.read_text().splitlines() if line.strip()}\nout = []\nwith dataset.open(newline=\"\") as f:\n for row in csv.DictReader(f):\n task_id = int(row[\"task_id\"])\n if task_id not in split_ids:\n continue\n if ids and str(task_id) not in ids:\n continue\n out.append({\n \"task_id\": task_id,\n \"instructions\": f\"{row['question']}\\\\n{row['guidelines']}\",\n \"all_golds_by_task\": ast.literal_eval(str(row[\"all_golds_by_task\"])),\n })\n if limit is not None and len(out) >= limit:\n break\nif not out:\n raise SystemExit(f\"no DABStep rows matched split={split} ids={sorted(ids)} limit={limit}\")\nprint(json.dumps(out))\n`\n const stdout = await runVenvPython(script, [dir, split, opts.limit === undefined ? '' : String(opts.limit), JSON.stringify(opts.ids ?? [])])\n return selectRows(JSON.parse(stdout) as DabstepFixtureRow[], opts, split, dir)\n}\n\nexport function createDabstepAdapter(): BenchmarkAdapter {\n const fixturesMode = process.env.DABSTEP_FIXTURES === '1'\n\n return {\n name: 'dabstep',\n output: dabstepAnswerOutput,\n\n async preflight() {\n if (fixturesMode) return\n const dir = dabstepDir()\n if (!dir) {\n throw new Error(\n 'DABSTEP_DIR is required. Fix: clone https://github.com/EnvCommons/DABStep, add the released dataset.csv under that checkout, then set DABSTEP_DIR=/path/to/DABStep.',\n )\n }\n await assertOfficialFiles(dir, DEFAULT_SPLIT)\n await loadOfficialTasks(dir, { limit: 1 }, DEFAULT_SPLIT)\n },\n\n async loadTasks(opts: LoadOptions = {}) {\n const split = opts.split ?? DEFAULT_SPLIT\n if (fixturesMode) return loadFixtures(opts, split)\n const dir = dabstepDir()\n if (!dir) throw new Error('DABSTEP_DIR is required to load official DABStep tasks')\n return loadOfficialTasks(dir, opts, split)\n },\n\n async goldArtifact(task: BenchTask) {\n const meta = readMeta(task)\n const first = meta.golds[0]\n if (!first) return undefined\n const value = first.value\n return value === undefined ? undefined : String(value)\n },\n\n async judge(task: BenchTask, artifact: string): Promise<BenchScore> {\n const meta = readMeta(task)\n const dir = dabstepDir()\n if (!dir) throw new Error('DABSTEP_DIR is required to judge DABStep tasks with the official grade.py')\n const stdout = await runVenvScriptStdin(\n join(benchRoot, 'scripts', 'dabstep_judge.py'),\n ['--grade-file', gradeFile(dir)],\n JSON.stringify({ prediction: artifact, golds: meta.golds }),\n { cwd: benchRoot },\n )\n const report = JSON.parse(stdout.trim().split('\\n').at(-1) ?? '{}') as { correct?: boolean; score?: number; error?: string }\n if (report.error) throw new Error(`DABStep judge error for ${task.id}: ${report.error}`)\n const score = typeof report.score === 'number' ? report.score : 0\n return {\n resolved: report.correct === true,\n score,\n detail: JSON.stringify({ taskId: meta.taskId, split: meta.split, correct: report.correct }),\n }\n },\n }\n}\n"],"mappings":";;;;;;;AAWA,SAAS,YAAY;AACrB,SAAS,QAAQ,UAAU,YAAY;AAKvC,IAAM,WAAW,KAAK,WAAW,YAAY,cAAc;AAC3D,IAAM,gBAAgB;AAetB,IAAM,aAAa,MAA0B,QAAQ,IAAI;AACzD,IAAM,YAAY,CAAC,QAAwB,KAAK,KAAK,UAAU;AAC/D,IAAM,eAAe,CAAC,QAAwB,KAAK,KAAK,OAAO;AAE/D,eAAe,WAAW,MAAc,OAA8B;AACpE,MAAI;AACF,UAAM,OAAO,IAAI;AAAA,EACnB,SAAS,KAAK;AACZ,UAAM,IAAI,MAAM,oBAAoB,KAAK,OAAO,IAAI,KAAK,eAAe,QAAQ,IAAI,UAAU,GAAG,GAAG;AAA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