AdithyaSK HF Staff commited on
Commit
00570c0
·
verified ·
1 Parent(s): 96f8585

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. tasks/0000_582_582934_qa_4/environment/Dockerfile +2 -0
  2. tasks/0000_582_582934_qa_4/environment/pull_bucket.py +41 -0
  3. tasks/0000_582_582934_qa_4/tests/grader.py +257 -0
  4. tasks/0000_582_582934_qa_4/tests/test.sh +13 -0
  5. tasks/0001_105_1105892_qa_5/environment/Dockerfile +2 -0
  6. tasks/0001_105_1105892_qa_5/environment/pull_bucket.py +41 -0
  7. tasks/0001_105_1105892_qa_5/tests/grader.py +257 -0
  8. tasks/0001_105_1105892_qa_5/tests/test.sh +13 -0
  9. tasks/0001_261_1261978_qa_5/environment/Dockerfile +2 -0
  10. tasks/0001_261_1261978_qa_5/environment/pull_bucket.py +41 -0
  11. tasks/0001_261_1261978_qa_5/tests/grader.py +257 -0
  12. tasks/0001_261_1261978_qa_5/tests/test.sh +13 -0
  13. tasks/0001_439_1439907_qa_3/environment/Dockerfile +2 -0
  14. tasks/0001_439_1439907_qa_3/environment/pull_bucket.py +41 -0
  15. tasks/0001_439_1439907_qa_3/tests/grader.py +257 -0
  16. tasks/0001_439_1439907_qa_3/tests/test.sh +13 -0
  17. tasks/0001_487_1487950_qa_1/environment/Dockerfile +2 -0
  18. tasks/0001_487_1487950_qa_1/environment/pull_bucket.py +41 -0
  19. tasks/0001_487_1487950_qa_1/tests/grader.py +257 -0
  20. tasks/0001_487_1487950_qa_1/tests/test.sh +13 -0
  21. tasks/0001_533_1533644_qa_3/environment/Dockerfile +2 -0
  22. tasks/0001_533_1533644_qa_3/environment/pull_bucket.py +41 -0
  23. tasks/0001_533_1533644_qa_3/tests/grader.py +257 -0
  24. tasks/0001_533_1533644_qa_3/tests/test.sh +13 -0
  25. tasks/0001_683_1683832_qa_5/environment/Dockerfile +2 -0
  26. tasks/0001_683_1683832_qa_5/environment/pull_bucket.py +41 -0
  27. tasks/0001_683_1683832_qa_5/tests/grader.py +257 -0
  28. tasks/0001_683_1683832_qa_5/tests/test.sh +13 -0
  29. tasks/0001_727_1727043_qa_4/environment/Dockerfile +2 -0
  30. tasks/0001_727_1727043_qa_4/environment/pull_bucket.py +41 -0
  31. tasks/0001_727_1727043_qa_4/tests/grader.py +257 -0
  32. tasks/0001_727_1727043_qa_4/tests/test.sh +13 -0
  33. tasks/0001_735_1735855_qa_3/environment/Dockerfile +2 -0
  34. tasks/0001_735_1735855_qa_3/environment/pull_bucket.py +41 -0
  35. tasks/0001_735_1735855_qa_3/tests/grader.py +257 -0
  36. tasks/0001_735_1735855_qa_3/tests/test.sh +13 -0
  37. tasks/0002_092_2092240_qa_5/environment/Dockerfile +2 -0
  38. tasks/0002_092_2092240_qa_5/environment/pull_bucket.py +41 -0
  39. tasks/0002_092_2092240_qa_5/tests/grader.py +257 -0
  40. tasks/0002_092_2092240_qa_5/tests/test.sh +13 -0
  41. tasks/0021_135_21135636_qa_3/environment/Dockerfile +2 -0
  42. tasks/0021_135_21135636_qa_3/environment/pull_bucket.py +41 -0
  43. tasks/0021_135_21135636_qa_3/tests/grader.py +257 -0
  44. tasks/0021_135_21135636_qa_3/tests/test.sh +13 -0
  45. tasks/0021_656_21656365_qa_5/environment/Dockerfile +2 -0
  46. tasks/0021_656_21656365_qa_5/environment/pull_bucket.py +41 -0
  47. tasks/0021_656_21656365_qa_5/tests/grader.py +257 -0
  48. tasks/0021_656_21656365_qa_5/tests/test.sh +13 -0
  49. tasks/0023_757_23757075_qa_3/environment/pull_bucket.py +41 -0
  50. tasks/0033_308_33308132_qa_3/environment/Dockerfile +2 -0
tasks/0000_582_582934_qa_4/environment/Dockerfile ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ FROM docker.io/savatar101/env-data-agent-train:base
2
+ WORKDIR /workdir
tasks/0000_582_582934_qa_4/environment/pull_bucket.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Pull this task's bucket prefix into /home/user/input/.
2
+
3
+ Invoked by Harbor's [environment.healthcheck] command (declared in task.toml)
4
+ — runs after container start, before the agent. Idempotent: skips work if
5
+ files are already present from a prior pull.
6
+ """
7
+
8
+ import os
9
+ import sys
10
+ from pathlib import Path
11
+
12
+ from huggingface_hub import download_bucket_files, list_bucket_tree
13
+
14
+
15
+ def main() -> int:
16
+ bucket = os.environ.get("HF_BUCKET") or "AdithyaSK/jupyter-agent-kaggle-all"
17
+ prefix = os.environ["BUCKET_PREFIX"].rstrip("/") + "/"
18
+ dest = Path("/home/user/input")
19
+ dest.mkdir(parents=True, exist_ok=True)
20
+
21
+ existing = [p for p in dest.iterdir() if p.is_file()]
22
+ if existing:
23
+ print(f"[pull_bucket] {dest}/ already has {len(existing)} file(s); skipping", flush=True)
24
+ return 0
25
+
26
+ targets = [
27
+ (it.path, str(dest / Path(it.path).name))
28
+ for it in list_bucket_tree(bucket, prefix=prefix, recursive=True)
29
+ if getattr(it, "type", None) == "file"
30
+ ]
31
+ if not targets:
32
+ print(f"[pull_bucket] FATAL: no files at hf://buckets/{bucket}/{prefix}", flush=True)
33
+ return 2
34
+
35
+ download_bucket_files(bucket, files=targets)
36
+ print(f"[pull_bucket] staged {len(targets)} file(s) from {bucket}/{prefix}", flush=True)
37
+ return 0
38
+
39
+
40
+ if __name__ == "__main__":
41
+ sys.exit(main())
tasks/0000_582_582934_qa_4/tests/grader.py ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Shared three-tier grader.
2
+
3
+ Used by both runtimes:
4
+ * `env/server.py` — inline inside the `final_answer` ORS @tool method
5
+ * `tests/test.sh` — Harbor CLI path; this module is mounted at /tests/grader.py
6
+ and invoked with `python3 /tests/grader.py < /workdir/answer.txt`
7
+
8
+ Tiers (cheapest → most expensive):
9
+ 1. Exact (case-insensitive, whitespace-collapsed)
10
+ 2. Numeric (parse a float, accept abs/rel diff ≤ 1e-3)
11
+ 3. LLM-judge (gpt-4o-mini, A/B/C verdict, OpenAI simple-evals prompt)
12
+ — only invoked if OPENAI_API_KEY is set
13
+
14
+ CLI form (used by tests/test.sh):
15
+ EXPECTED_ANSWER='5' QUESTION='How many...' python3 grader.py
16
+ → reads predicted answer from stdin
17
+ → writes a single float ('1.0' or '0.0') to stdout
18
+ → exits 0 always; harbor reads stdout from /logs/verifier/reward.txt
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ import os
24
+ import re
25
+ import sys
26
+ from dataclasses import dataclass
27
+
28
+
29
+ _NUMERIC_RE = re.compile(r"-?\d+(?:[.,]\d+)?(?:[eE][-+]?\d+)?")
30
+
31
+ # Locked in PLAN.md §"Locked decisions" — adapted from
32
+ # https://github.com/openai/simple-evals/blob/main/simpleqa_eval.py
33
+ JUDGE_PROMPT = """You are grading short answers from a data-science agent.
34
+ Decide whether the predicted answer is semantically equivalent to the gold answer.
35
+
36
+ Rules:
37
+ - Case, punctuation, whitespace, articles ("the"), and trailing units don't matter.
38
+ - For numbers: predicted must match to the last significant figure of the gold
39
+ (gold "0.544341", predicted "0.544" -> CORRECT; "0.5" -> INCORRECT).
40
+ - Extra surrounding prose is fine if the gold value is clearly stated
41
+ (gold "5", predicted "There are 5 distinct categories" -> CORRECT).
42
+ - Common synonyms/abbreviations count (gold "Not Applicable", predicted "N/A" -> CORRECT).
43
+ - Parenthetical annotations in the gold are equivalence hints, not required
44
+ (gold "Gandalf (Ainur)", predicted "Gandalf" -> CORRECT;
45
+ gold "No (correlation coefficient = 0.02)", predicted "No" -> CORRECT).
46
+ - Percent + qualifier: if the gold is "X% in YEAR", a prediction of X or X%
47
+ is CORRECT as long as the core numeric value matches
48
+ (gold "21.334% in 2014", predicted "21.334" -> CORRECT;
49
+ gold "21.334% in 2014", predicted "21.334% in 2013" -> INCORRECT — year mismatch).
50
+ - Multi-part gold like "0.987 (XGBoost and LGBM)" — if the question asks for one
51
+ thing (e.g. "which model?"), predicting either listed value is CORRECT.
52
+ - If the predicted answer hedges without committing to the gold value -> NOT_ATTEMPTED.
53
+ - If it commits to a different value -> INCORRECT.
54
+
55
+ Question: {question}
56
+ Gold answer: {gold}
57
+ Predicted answer: {pred}
58
+
59
+ Reply with exactly one token: A (CORRECT), B (INCORRECT), or C (NOT_ATTEMPTED)."""
60
+
61
+
62
+ @dataclass
63
+ class GradeResult:
64
+ reward: float
65
+ method: str # "exact" | "numeric" | "llm" | "miss"
66
+
67
+
68
+ def _normalize(s: str) -> str:
69
+ return re.sub(r"\s+", " ", (s or "").strip().lower())
70
+
71
+
72
+ def _to_float(s: str) -> float | None:
73
+ if not s:
74
+ return None
75
+ m = _NUMERIC_RE.search(s.replace(",", ""))
76
+ if not m:
77
+ return None
78
+ try:
79
+ return float(m.group(0))
80
+ except ValueError:
81
+ return None
82
+
83
+
84
+ def _math_verify_match(gold: str, candidate: str) -> bool:
85
+ """Deterministic symbolic/numeric equivalence via HuggingFace Math-Verify.
86
+
87
+ Catches equivalences the naive float-parse misses: thousands separators,
88
+ fractions (3/4 == 0.75), percentages (50% == 0.5), and symbolic forms.
89
+ Fails CLOSED — any parse error / prose gold / timeout returns False (never a
90
+ false positive). No network, no LLM.
91
+ """
92
+ try:
93
+ from math_verify import parse, verify
94
+
95
+ return bool(verify(parse(gold), parse(candidate), timeout_seconds=5))
96
+ except Exception: # noqa: BLE001
97
+ return False
98
+
99
+
100
+ def _is_clean_number(s: str) -> bool:
101
+ """True iff the whole string IS a single number (allowing a leading/trailing
102
+ %, $, and thousands-commas) — e.g. '95293', '95,293', '0.5', '-3.16', '50%'.
103
+ A COMPOUND string like 'Y=3 with 95,293 instances' is NOT a clean number, so
104
+ the numeric tier must not fire on it (its `_to_float` would grab the leading
105
+ '3' and false-positive-match any answer starting with 3)."""
106
+ t = (s or "").strip().strip("%$").strip().replace(",", "")
107
+ return bool(_NUMERIC_RE.fullmatch(t))
108
+
109
+
110
+ def grade(
111
+ gold: str,
112
+ candidate: str,
113
+ *,
114
+ question: str = "",
115
+ reward_mode: str = "",
116
+ judge: bool = True, # noqa: ARG001 — kept for signature compat; LLM tier removed
117
+ judge_model: str | None = None, # noqa: ARG001
118
+ rel_tol: float = 1e-3,
119
+ abs_tol: float = 1e-3,
120
+ ) -> GradeResult:
121
+ """Deterministic three-tier match — NO LLM judge.
122
+
123
+ exact -> numeric (abs_tol/rel_tol, gated to clean-number golds) -> math_verify
124
+ -> miss. `judge`/`judge_model` accepted but ignored (LLM tier removed).
125
+ """
126
+
127
+ if not gold or candidate is None:
128
+ return GradeResult(0.0, "miss")
129
+
130
+ # ── Tier 1: exact (case-insensitive, whitespace-collapsed) ─��───────
131
+ if _normalize(gold) == _normalize(candidate):
132
+ return GradeResult(1.0, "exact")
133
+
134
+ # ── Tier 2: numeric — ONLY when the gold is a single clean number ──
135
+ # (compound golds like "Y=3 with 95,293 instances" would otherwise match on
136
+ # the leading number; those must go to exact/math_verify, which fail closed).
137
+ if reward_mode == "numeric" or _is_clean_number(gold):
138
+ g, c = _to_float(gold), _to_float(candidate)
139
+ if g is not None and c is not None:
140
+ if abs(g - c) <= abs_tol or abs(g - c) / max(abs(g), 1e-9) <= rel_tol:
141
+ return GradeResult(1.0, "numeric")
142
+
143
+ # ── Tier 3: math-verify (symbolic/numeric equivalence, deterministic) ──
144
+ if _math_verify_match(gold, candidate):
145
+ return GradeResult(1.0, "math_verify")
146
+
147
+ return GradeResult(0.0, "miss")
148
+
149
+
150
+ def _tool_calls() -> int | None:
151
+ """Number of agent tool calls this rollout, for the efficiency reward.
152
+
153
+ Written by the harness into the sandbox (`/workdir/.n_tool_calls`); falls
154
+ back to the `N_TOOL_CALLS` env var. Returns None if neither is present
155
+ (efficiency reward becomes null — the harness didn't report a count).
156
+ """
157
+ try:
158
+ with open("/workdir/.n_tool_calls") as fh:
159
+ return int(fh.read().strip())
160
+ except (OSError, ValueError):
161
+ pass
162
+ raw = os.environ.get("N_TOOL_CALLS")
163
+ if raw is not None:
164
+ try:
165
+ return int(str(raw).strip())
166
+ except ValueError:
167
+ return None
168
+ return None
169
+
170
+
171
+ def _tool_efficiency(n_calls: int | None) -> float | None:
172
+ """0..1 efficiency signal: fewer tool calls -> higher. None if unknown.
173
+
174
+ clip(1 - n_calls / TOOL_BUDGET, 0, 1). TOOL_BUDGET default 15 (solved-4B
175
+ median was ~9-10 calls). Raw signal — NOT gated on correctness here; the
176
+ RL reward combiner decides gating/weights.
177
+ """
178
+ if n_calls is None:
179
+ return None
180
+ budget = float(os.environ.get("TOOL_BUDGET", "15") or "15")
181
+ if budget <= 0:
182
+ return None
183
+ return max(0.0, min(1.0, 1.0 - n_calls / budget))
184
+
185
+
186
+ def _tols() -> tuple[float, float]:
187
+ """Per-task (abs_tol, rel_tol) from ATOL/RTOL in [verifier.env]; 1e-3 default."""
188
+ def _f(name: str) -> float:
189
+ try:
190
+ return float(os.environ.get(name, "") or 1e-3)
191
+ except ValueError:
192
+ return 1e-3
193
+ return _f("ATOL"), _f("RTOL")
194
+
195
+
196
+ def main_cli() -> int:
197
+ """CLI shim for `tests/test.sh` — env-driven, stdout-only.
198
+
199
+ Inputs (via env vars set by Harbor's [verifier.env]):
200
+ EXPECTED_ANSWER — the gold
201
+ QUESTION — the original question
202
+ ATOL / RTOL — per-task numeric tolerances (default 1e-3)
203
+
204
+ Predicted answer is read from stdin.
205
+ Single float written to stdout. Exit code is always 0.
206
+ """
207
+ gold = (os.environ.get("EXPECTED_ANSWER") or "").strip()
208
+ question = (os.environ.get("QUESTION") or "").strip()
209
+ candidate = sys.stdin.read().strip()
210
+ at, rt = _tols()
211
+ result = grade(gold, candidate, question=question, reward_mode=os.environ.get("REWARD_MODE","") or "", abs_tol=at, rel_tol=rt)
212
+ print(f"{result.reward:.1f}")
213
+ print(f"[grader] gold={gold!r} pred={candidate[:80]!r} reward={result.reward} method={result.method}",
214
+ file=sys.stderr)
215
+ return 0
216
+
217
+
218
+ def main_json() -> int:
219
+ """Multi-reward shim for `tests/test.sh` — writes a `reward.json` dict.
220
+
221
+ Three named rewards (Harbor's VerifierResult.rewards carries them all):
222
+ correctness — 1.0 iff graded answer matches gold, else 0.0
223
+ submission — 1.0 iff a non-empty answer was submitted, else 0.0
224
+ tool_efficiency — 0..1 (fewer tool calls higher); null if count unknown
225
+
226
+ No submission -> all three 0. Predicted answer on stdin; JSON to stdout.
227
+ """
228
+ import json
229
+
230
+ gold = (os.environ.get("EXPECTED_ANSWER") or "").strip()
231
+ question = (os.environ.get("QUESTION") or "").strip()
232
+ candidate = sys.stdin.read().strip()
233
+
234
+ if not candidate:
235
+ print(json.dumps({"correctness": 0.0, "submission": 0.0, "tool_efficiency": 0.0}))
236
+ print("[grader] no submission -> all rewards 0", file=sys.stderr)
237
+ return 0
238
+
239
+ at, rt = _tols()
240
+ result = grade(gold, candidate, question=question, reward_mode=os.environ.get("REWARD_MODE","") or "", abs_tol=at, rel_tol=rt)
241
+ n_calls = _tool_calls()
242
+ eff = _tool_efficiency(n_calls)
243
+ print(json.dumps({
244
+ "correctness": float(result.reward),
245
+ "submission": 1.0,
246
+ "tool_efficiency": eff,
247
+ }))
248
+ print(f"[grader] gold={gold!r} pred={candidate[:80]!r} "
249
+ f"correctness={result.reward} method={result.method} "
250
+ f"tool_calls={n_calls} tool_efficiency={eff}", file=sys.stderr)
251
+ return 0
252
+
253
+
254
+ if __name__ == "__main__":
255
+ if "--json" in sys.argv[1:]:
256
+ raise SystemExit(main_json())
257
+ raise SystemExit(main_cli())
tasks/0000_582_582934_qa_4/tests/test.sh ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -u
3
+ mkdir -p /logs/verifier
4
+
5
+ answer_path="/workdir/answer.txt"
6
+ if [ ! -s "$answer_path" ]; then
7
+ echo "0.0" > /logs/verifier/reward.txt
8
+ echo "[grader] no answer at $answer_path" >&2
9
+ exit 0
10
+ fi
11
+
12
+ pip install --quiet math-verify >/dev/null 2>&1 || true
13
+ python3 /tests/grader.py < "$answer_path" > /logs/verifier/reward.txt
tasks/0001_105_1105892_qa_5/environment/Dockerfile ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ FROM docker.io/savatar101/env-data-agent-train:base
2
+ WORKDIR /workdir
tasks/0001_105_1105892_qa_5/environment/pull_bucket.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Pull this task's bucket prefix into /home/user/input/.
2
+
3
+ Invoked by Harbor's [environment.healthcheck] command (declared in task.toml)
4
+ — runs after container start, before the agent. Idempotent: skips work if
5
+ files are already present from a prior pull.
6
+ """
7
+
8
+ import os
9
+ import sys
10
+ from pathlib import Path
11
+
12
+ from huggingface_hub import download_bucket_files, list_bucket_tree
13
+
14
+
15
+ def main() -> int:
16
+ bucket = os.environ.get("HF_BUCKET") or "AdithyaSK/jupyter-agent-kaggle-all"
17
+ prefix = os.environ["BUCKET_PREFIX"].rstrip("/") + "/"
18
+ dest = Path("/home/user/input")
19
+ dest.mkdir(parents=True, exist_ok=True)
20
+
21
+ existing = [p for p in dest.iterdir() if p.is_file()]
22
+ if existing:
23
+ print(f"[pull_bucket] {dest}/ already has {len(existing)} file(s); skipping", flush=True)
24
+ return 0
25
+
26
+ targets = [
27
+ (it.path, str(dest / Path(it.path).name))
28
+ for it in list_bucket_tree(bucket, prefix=prefix, recursive=True)
29
+ if getattr(it, "type", None) == "file"
30
+ ]
31
+ if not targets:
32
+ print(f"[pull_bucket] FATAL: no files at hf://buckets/{bucket}/{prefix}", flush=True)
33
+ return 2
34
+
35
+ download_bucket_files(bucket, files=targets)
36
+ print(f"[pull_bucket] staged {len(targets)} file(s) from {bucket}/{prefix}", flush=True)
37
+ return 0
38
+
39
+
40
+ if __name__ == "__main__":
41
+ sys.exit(main())
tasks/0001_105_1105892_qa_5/tests/grader.py ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Shared three-tier grader.
2
+
3
+ Used by both runtimes:
4
+ * `env/server.py` — inline inside the `final_answer` ORS @tool method
5
+ * `tests/test.sh` — Harbor CLI path; this module is mounted at /tests/grader.py
6
+ and invoked with `python3 /tests/grader.py < /workdir/answer.txt`
7
+
8
+ Tiers (cheapest → most expensive):
9
+ 1. Exact (case-insensitive, whitespace-collapsed)
10
+ 2. Numeric (parse a float, accept abs/rel diff ≤ 1e-3)
11
+ 3. LLM-judge (gpt-4o-mini, A/B/C verdict, OpenAI simple-evals prompt)
12
+ — only invoked if OPENAI_API_KEY is set
13
+
14
+ CLI form (used by tests/test.sh):
15
+ EXPECTED_ANSWER='5' QUESTION='How many...' python3 grader.py
16
+ → reads predicted answer from stdin
17
+ → writes a single float ('1.0' or '0.0') to stdout
18
+ → exits 0 always; harbor reads stdout from /logs/verifier/reward.txt
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ import os
24
+ import re
25
+ import sys
26
+ from dataclasses import dataclass
27
+
28
+
29
+ _NUMERIC_RE = re.compile(r"-?\d+(?:[.,]\d+)?(?:[eE][-+]?\d+)?")
30
+
31
+ # Locked in PLAN.md §"Locked decisions" — adapted from
32
+ # https://github.com/openai/simple-evals/blob/main/simpleqa_eval.py
33
+ JUDGE_PROMPT = """You are grading short answers from a data-science agent.
34
+ Decide whether the predicted answer is semantically equivalent to the gold answer.
35
+
36
+ Rules:
37
+ - Case, punctuation, whitespace, articles ("the"), and trailing units don't matter.
38
+ - For numbers: predicted must match to the last significant figure of the gold
39
+ (gold "0.544341", predicted "0.544" -> CORRECT; "0.5" -> INCORRECT).
40
+ - Extra surrounding prose is fine if the gold value is clearly stated
41
+ (gold "5", predicted "There are 5 distinct categories" -> CORRECT).
42
+ - Common synonyms/abbreviations count (gold "Not Applicable", predicted "N/A" -> CORRECT).
43
+ - Parenthetical annotations in the gold are equivalence hints, not required
44
+ (gold "Gandalf (Ainur)", predicted "Gandalf" -> CORRECT;
45
+ gold "No (correlation coefficient = 0.02)", predicted "No" -> CORRECT).
46
+ - Percent + qualifier: if the gold is "X% in YEAR", a prediction of X or X%
47
+ is CORRECT as long as the core numeric value matches
48
+ (gold "21.334% in 2014", predicted "21.334" -> CORRECT;
49
+ gold "21.334% in 2014", predicted "21.334% in 2013" -> INCORRECT — year mismatch).
50
+ - Multi-part gold like "0.987 (XGBoost and LGBM)" — if the question asks for one
51
+ thing (e.g. "which model?"), predicting either listed value is CORRECT.
52
+ - If the predicted answer hedges without committing to the gold value -> NOT_ATTEMPTED.
53
+ - If it commits to a different value -> INCORRECT.
54
+
55
+ Question: {question}
56
+ Gold answer: {gold}
57
+ Predicted answer: {pred}
58
+
59
+ Reply with exactly one token: A (CORRECT), B (INCORRECT), or C (NOT_ATTEMPTED)."""
60
+
61
+
62
+ @dataclass
63
+ class GradeResult:
64
+ reward: float
65
+ method: str # "exact" | "numeric" | "llm" | "miss"
66
+
67
+
68
+ def _normalize(s: str) -> str:
69
+ return re.sub(r"\s+", " ", (s or "").strip().lower())
70
+
71
+
72
+ def _to_float(s: str) -> float | None:
73
+ if not s:
74
+ return None
75
+ m = _NUMERIC_RE.search(s.replace(",", ""))
76
+ if not m:
77
+ return None
78
+ try:
79
+ return float(m.group(0))
80
+ except ValueError:
81
+ return None
82
+
83
+
84
+ def _math_verify_match(gold: str, candidate: str) -> bool:
85
+ """Deterministic symbolic/numeric equivalence via HuggingFace Math-Verify.
86
+
87
+ Catches equivalences the naive float-parse misses: thousands separators,
88
+ fractions (3/4 == 0.75), percentages (50% == 0.5), and symbolic forms.
89
+ Fails CLOSED — any parse error / prose gold / timeout returns False (never a
90
+ false positive). No network, no LLM.
91
+ """
92
+ try:
93
+ from math_verify import parse, verify
94
+
95
+ return bool(verify(parse(gold), parse(candidate), timeout_seconds=5))
96
+ except Exception: # noqa: BLE001
97
+ return False
98
+
99
+
100
+ def _is_clean_number(s: str) -> bool:
101
+ """True iff the whole string IS a single number (allowing a leading/trailing
102
+ %, $, and thousands-commas) — e.g. '95293', '95,293', '0.5', '-3.16', '50%'.
103
+ A COMPOUND string like 'Y=3 with 95,293 instances' is NOT a clean number, so
104
+ the numeric tier must not fire on it (its `_to_float` would grab the leading
105
+ '3' and false-positive-match any answer starting with 3)."""
106
+ t = (s or "").strip().strip("%$").strip().replace(",", "")
107
+ return bool(_NUMERIC_RE.fullmatch(t))
108
+
109
+
110
+ def grade(
111
+ gold: str,
112
+ candidate: str,
113
+ *,
114
+ question: str = "",
115
+ reward_mode: str = "",
116
+ judge: bool = True, # noqa: ARG001 — kept for signature compat; LLM tier removed
117
+ judge_model: str | None = None, # noqa: ARG001
118
+ rel_tol: float = 1e-3,
119
+ abs_tol: float = 1e-3,
120
+ ) -> GradeResult:
121
+ """Deterministic three-tier match — NO LLM judge.
122
+
123
+ exact -> numeric (abs_tol/rel_tol, gated to clean-number golds) -> math_verify
124
+ -> miss. `judge`/`judge_model` accepted but ignored (LLM tier removed).
125
+ """
126
+
127
+ if not gold or candidate is None:
128
+ return GradeResult(0.0, "miss")
129
+
130
+ # ── Tier 1: exact (case-insensitive, whitespace-collapsed) ─��───────
131
+ if _normalize(gold) == _normalize(candidate):
132
+ return GradeResult(1.0, "exact")
133
+
134
+ # ── Tier 2: numeric — ONLY when the gold is a single clean number ──
135
+ # (compound golds like "Y=3 with 95,293 instances" would otherwise match on
136
+ # the leading number; those must go to exact/math_verify, which fail closed).
137
+ if reward_mode == "numeric" or _is_clean_number(gold):
138
+ g, c = _to_float(gold), _to_float(candidate)
139
+ if g is not None and c is not None:
140
+ if abs(g - c) <= abs_tol or abs(g - c) / max(abs(g), 1e-9) <= rel_tol:
141
+ return GradeResult(1.0, "numeric")
142
+
143
+ # ── Tier 3: math-verify (symbolic/numeric equivalence, deterministic) ──
144
+ if _math_verify_match(gold, candidate):
145
+ return GradeResult(1.0, "math_verify")
146
+
147
+ return GradeResult(0.0, "miss")
148
+
149
+
150
+ def _tool_calls() -> int | None:
151
+ """Number of agent tool calls this rollout, for the efficiency reward.
152
+
153
+ Written by the harness into the sandbox (`/workdir/.n_tool_calls`); falls
154
+ back to the `N_TOOL_CALLS` env var. Returns None if neither is present
155
+ (efficiency reward becomes null — the harness didn't report a count).
156
+ """
157
+ try:
158
+ with open("/workdir/.n_tool_calls") as fh:
159
+ return int(fh.read().strip())
160
+ except (OSError, ValueError):
161
+ pass
162
+ raw = os.environ.get("N_TOOL_CALLS")
163
+ if raw is not None:
164
+ try:
165
+ return int(str(raw).strip())
166
+ except ValueError:
167
+ return None
168
+ return None
169
+
170
+
171
+ def _tool_efficiency(n_calls: int | None) -> float | None:
172
+ """0..1 efficiency signal: fewer tool calls -> higher. None if unknown.
173
+
174
+ clip(1 - n_calls / TOOL_BUDGET, 0, 1). TOOL_BUDGET default 15 (solved-4B
175
+ median was ~9-10 calls). Raw signal — NOT gated on correctness here; the
176
+ RL reward combiner decides gating/weights.
177
+ """
178
+ if n_calls is None:
179
+ return None
180
+ budget = float(os.environ.get("TOOL_BUDGET", "15") or "15")
181
+ if budget <= 0:
182
+ return None
183
+ return max(0.0, min(1.0, 1.0 - n_calls / budget))
184
+
185
+
186
+ def _tols() -> tuple[float, float]:
187
+ """Per-task (abs_tol, rel_tol) from ATOL/RTOL in [verifier.env]; 1e-3 default."""
188
+ def _f(name: str) -> float:
189
+ try:
190
+ return float(os.environ.get(name, "") or 1e-3)
191
+ except ValueError:
192
+ return 1e-3
193
+ return _f("ATOL"), _f("RTOL")
194
+
195
+
196
+ def main_cli() -> int:
197
+ """CLI shim for `tests/test.sh` — env-driven, stdout-only.
198
+
199
+ Inputs (via env vars set by Harbor's [verifier.env]):
200
+ EXPECTED_ANSWER — the gold
201
+ QUESTION — the original question
202
+ ATOL / RTOL — per-task numeric tolerances (default 1e-3)
203
+
204
+ Predicted answer is read from stdin.
205
+ Single float written to stdout. Exit code is always 0.
206
+ """
207
+ gold = (os.environ.get("EXPECTED_ANSWER") or "").strip()
208
+ question = (os.environ.get("QUESTION") or "").strip()
209
+ candidate = sys.stdin.read().strip()
210
+ at, rt = _tols()
211
+ result = grade(gold, candidate, question=question, reward_mode=os.environ.get("REWARD_MODE","") or "", abs_tol=at, rel_tol=rt)
212
+ print(f"{result.reward:.1f}")
213
+ print(f"[grader] gold={gold!r} pred={candidate[:80]!r} reward={result.reward} method={result.method}",
214
+ file=sys.stderr)
215
+ return 0
216
+
217
+
218
+ def main_json() -> int:
219
+ """Multi-reward shim for `tests/test.sh` — writes a `reward.json` dict.
220
+
221
+ Three named rewards (Harbor's VerifierResult.rewards carries them all):
222
+ correctness — 1.0 iff graded answer matches gold, else 0.0
223
+ submission — 1.0 iff a non-empty answer was submitted, else 0.0
224
+ tool_efficiency — 0..1 (fewer tool calls higher); null if count unknown
225
+
226
+ No submission -> all three 0. Predicted answer on stdin; JSON to stdout.
227
+ """
228
+ import json
229
+
230
+ gold = (os.environ.get("EXPECTED_ANSWER") or "").strip()
231
+ question = (os.environ.get("QUESTION") or "").strip()
232
+ candidate = sys.stdin.read().strip()
233
+
234
+ if not candidate:
235
+ print(json.dumps({"correctness": 0.0, "submission": 0.0, "tool_efficiency": 0.0}))
236
+ print("[grader] no submission -> all rewards 0", file=sys.stderr)
237
+ return 0
238
+
239
+ at, rt = _tols()
240
+ result = grade(gold, candidate, question=question, reward_mode=os.environ.get("REWARD_MODE","") or "", abs_tol=at, rel_tol=rt)
241
+ n_calls = _tool_calls()
242
+ eff = _tool_efficiency(n_calls)
243
+ print(json.dumps({
244
+ "correctness": float(result.reward),
245
+ "submission": 1.0,
246
+ "tool_efficiency": eff,
247
+ }))
248
+ print(f"[grader] gold={gold!r} pred={candidate[:80]!r} "
249
+ f"correctness={result.reward} method={result.method} "
250
+ f"tool_calls={n_calls} tool_efficiency={eff}", file=sys.stderr)
251
+ return 0
252
+
253
+
254
+ if __name__ == "__main__":
255
+ if "--json" in sys.argv[1:]:
256
+ raise SystemExit(main_json())
257
+ raise SystemExit(main_cli())
tasks/0001_105_1105892_qa_5/tests/test.sh ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -u
3
+ mkdir -p /logs/verifier
4
+
5
+ answer_path="/workdir/answer.txt"
6
+ if [ ! -s "$answer_path" ]; then
7
+ echo "0.0" > /logs/verifier/reward.txt
8
+ echo "[grader] no answer at $answer_path" >&2
9
+ exit 0
10
+ fi
11
+
12
+ pip install --quiet math-verify >/dev/null 2>&1 || true
13
+ python3 /tests/grader.py < "$answer_path" > /logs/verifier/reward.txt
tasks/0001_261_1261978_qa_5/environment/Dockerfile ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ FROM docker.io/savatar101/env-data-agent-train:base
2
+ WORKDIR /workdir
tasks/0001_261_1261978_qa_5/environment/pull_bucket.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Pull this task's bucket prefix into /home/user/input/.
2
+
3
+ Invoked by Harbor's [environment.healthcheck] command (declared in task.toml)
4
+ — runs after container start, before the agent. Idempotent: skips work if
5
+ files are already present from a prior pull.
6
+ """
7
+
8
+ import os
9
+ import sys
10
+ from pathlib import Path
11
+
12
+ from huggingface_hub import download_bucket_files, list_bucket_tree
13
+
14
+
15
+ def main() -> int:
16
+ bucket = os.environ.get("HF_BUCKET") or "AdithyaSK/jupyter-agent-kaggle-all"
17
+ prefix = os.environ["BUCKET_PREFIX"].rstrip("/") + "/"
18
+ dest = Path("/home/user/input")
19
+ dest.mkdir(parents=True, exist_ok=True)
20
+
21
+ existing = [p for p in dest.iterdir() if p.is_file()]
22
+ if existing:
23
+ print(f"[pull_bucket] {dest}/ already has {len(existing)} file(s); skipping", flush=True)
24
+ return 0
25
+
26
+ targets = [
27
+ (it.path, str(dest / Path(it.path).name))
28
+ for it in list_bucket_tree(bucket, prefix=prefix, recursive=True)
29
+ if getattr(it, "type", None) == "file"
30
+ ]
31
+ if not targets:
32
+ print(f"[pull_bucket] FATAL: no files at hf://buckets/{bucket}/{prefix}", flush=True)
33
+ return 2
34
+
35
+ download_bucket_files(bucket, files=targets)
36
+ print(f"[pull_bucket] staged {len(targets)} file(s) from {bucket}/{prefix}", flush=True)
37
+ return 0
38
+
39
+
40
+ if __name__ == "__main__":
41
+ sys.exit(main())
tasks/0001_261_1261978_qa_5/tests/grader.py ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Shared three-tier grader.
2
+
3
+ Used by both runtimes:
4
+ * `env/server.py` — inline inside the `final_answer` ORS @tool method
5
+ * `tests/test.sh` — Harbor CLI path; this module is mounted at /tests/grader.py
6
+ and invoked with `python3 /tests/grader.py < /workdir/answer.txt`
7
+
8
+ Tiers (cheapest → most expensive):
9
+ 1. Exact (case-insensitive, whitespace-collapsed)
10
+ 2. Numeric (parse a float, accept abs/rel diff ≤ 1e-3)
11
+ 3. LLM-judge (gpt-4o-mini, A/B/C verdict, OpenAI simple-evals prompt)
12
+ — only invoked if OPENAI_API_KEY is set
13
+
14
+ CLI form (used by tests/test.sh):
15
+ EXPECTED_ANSWER='5' QUESTION='How many...' python3 grader.py
16
+ → reads predicted answer from stdin
17
+ → writes a single float ('1.0' or '0.0') to stdout
18
+ → exits 0 always; harbor reads stdout from /logs/verifier/reward.txt
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ import os
24
+ import re
25
+ import sys
26
+ from dataclasses import dataclass
27
+
28
+
29
+ _NUMERIC_RE = re.compile(r"-?\d+(?:[.,]\d+)?(?:[eE][-+]?\d+)?")
30
+
31
+ # Locked in PLAN.md §"Locked decisions" — adapted from
32
+ # https://github.com/openai/simple-evals/blob/main/simpleqa_eval.py
33
+ JUDGE_PROMPT = """You are grading short answers from a data-science agent.
34
+ Decide whether the predicted answer is semantically equivalent to the gold answer.
35
+
36
+ Rules:
37
+ - Case, punctuation, whitespace, articles ("the"), and trailing units don't matter.
38
+ - For numbers: predicted must match to the last significant figure of the gold
39
+ (gold "0.544341", predicted "0.544" -> CORRECT; "0.5" -> INCORRECT).
40
+ - Extra surrounding prose is fine if the gold value is clearly stated
41
+ (gold "5", predicted "There are 5 distinct categories" -> CORRECT).
42
+ - Common synonyms/abbreviations count (gold "Not Applicable", predicted "N/A" -> CORRECT).
43
+ - Parenthetical annotations in the gold are equivalence hints, not required
44
+ (gold "Gandalf (Ainur)", predicted "Gandalf" -> CORRECT;
45
+ gold "No (correlation coefficient = 0.02)", predicted "No" -> CORRECT).
46
+ - Percent + qualifier: if the gold is "X% in YEAR", a prediction of X or X%
47
+ is CORRECT as long as the core numeric value matches
48
+ (gold "21.334% in 2014", predicted "21.334" -> CORRECT;
49
+ gold "21.334% in 2014", predicted "21.334% in 2013" -> INCORRECT — year mismatch).
50
+ - Multi-part gold like "0.987 (XGBoost and LGBM)" — if the question asks for one
51
+ thing (e.g. "which model?"), predicting either listed value is CORRECT.
52
+ - If the predicted answer hedges without committing to the gold value -> NOT_ATTEMPTED.
53
+ - If it commits to a different value -> INCORRECT.
54
+
55
+ Question: {question}
56
+ Gold answer: {gold}
57
+ Predicted answer: {pred}
58
+
59
+ Reply with exactly one token: A (CORRECT), B (INCORRECT), or C (NOT_ATTEMPTED)."""
60
+
61
+
62
+ @dataclass
63
+ class GradeResult:
64
+ reward: float
65
+ method: str # "exact" | "numeric" | "llm" | "miss"
66
+
67
+
68
+ def _normalize(s: str) -> str:
69
+ return re.sub(r"\s+", " ", (s or "").strip().lower())
70
+
71
+
72
+ def _to_float(s: str) -> float | None:
73
+ if not s:
74
+ return None
75
+ m = _NUMERIC_RE.search(s.replace(",", ""))
76
+ if not m:
77
+ return None
78
+ try:
79
+ return float(m.group(0))
80
+ except ValueError:
81
+ return None
82
+
83
+
84
+ def _math_verify_match(gold: str, candidate: str) -> bool:
85
+ """Deterministic symbolic/numeric equivalence via HuggingFace Math-Verify.
86
+
87
+ Catches equivalences the naive float-parse misses: thousands separators,
88
+ fractions (3/4 == 0.75), percentages (50% == 0.5), and symbolic forms.
89
+ Fails CLOSED — any parse error / prose gold / timeout returns False (never a
90
+ false positive). No network, no LLM.
91
+ """
92
+ try:
93
+ from math_verify import parse, verify
94
+
95
+ return bool(verify(parse(gold), parse(candidate), timeout_seconds=5))
96
+ except Exception: # noqa: BLE001
97
+ return False
98
+
99
+
100
+ def _is_clean_number(s: str) -> bool:
101
+ """True iff the whole string IS a single number (allowing a leading/trailing
102
+ %, $, and thousands-commas) — e.g. '95293', '95,293', '0.5', '-3.16', '50%'.
103
+ A COMPOUND string like 'Y=3 with 95,293 instances' is NOT a clean number, so
104
+ the numeric tier must not fire on it (its `_to_float` would grab the leading
105
+ '3' and false-positive-match any answer starting with 3)."""
106
+ t = (s or "").strip().strip("%$").strip().replace(",", "")
107
+ return bool(_NUMERIC_RE.fullmatch(t))
108
+
109
+
110
+ def grade(
111
+ gold: str,
112
+ candidate: str,
113
+ *,
114
+ question: str = "",
115
+ reward_mode: str = "",
116
+ judge: bool = True, # noqa: ARG001 — kept for signature compat; LLM tier removed
117
+ judge_model: str | None = None, # noqa: ARG001
118
+ rel_tol: float = 1e-3,
119
+ abs_tol: float = 1e-3,
120
+ ) -> GradeResult:
121
+ """Deterministic three-tier match — NO LLM judge.
122
+
123
+ exact -> numeric (abs_tol/rel_tol, gated to clean-number golds) -> math_verify
124
+ -> miss. `judge`/`judge_model` accepted but ignored (LLM tier removed).
125
+ """
126
+
127
+ if not gold or candidate is None:
128
+ return GradeResult(0.0, "miss")
129
+
130
+ # ── Tier 1: exact (case-insensitive, whitespace-collapsed) ─��───────
131
+ if _normalize(gold) == _normalize(candidate):
132
+ return GradeResult(1.0, "exact")
133
+
134
+ # ── Tier 2: numeric — ONLY when the gold is a single clean number ──
135
+ # (compound golds like "Y=3 with 95,293 instances" would otherwise match on
136
+ # the leading number; those must go to exact/math_verify, which fail closed).
137
+ if reward_mode == "numeric" or _is_clean_number(gold):
138
+ g, c = _to_float(gold), _to_float(candidate)
139
+ if g is not None and c is not None:
140
+ if abs(g - c) <= abs_tol or abs(g - c) / max(abs(g), 1e-9) <= rel_tol:
141
+ return GradeResult(1.0, "numeric")
142
+
143
+ # ── Tier 3: math-verify (symbolic/numeric equivalence, deterministic) ──
144
+ if _math_verify_match(gold, candidate):
145
+ return GradeResult(1.0, "math_verify")
146
+
147
+ return GradeResult(0.0, "miss")
148
+
149
+
150
+ def _tool_calls() -> int | None:
151
+ """Number of agent tool calls this rollout, for the efficiency reward.
152
+
153
+ Written by the harness into the sandbox (`/workdir/.n_tool_calls`); falls
154
+ back to the `N_TOOL_CALLS` env var. Returns None if neither is present
155
+ (efficiency reward becomes null — the harness didn't report a count).
156
+ """
157
+ try:
158
+ with open("/workdir/.n_tool_calls") as fh:
159
+ return int(fh.read().strip())
160
+ except (OSError, ValueError):
161
+ pass
162
+ raw = os.environ.get("N_TOOL_CALLS")
163
+ if raw is not None:
164
+ try:
165
+ return int(str(raw).strip())
166
+ except ValueError:
167
+ return None
168
+ return None
169
+
170
+
171
+ def _tool_efficiency(n_calls: int | None) -> float | None:
172
+ """0..1 efficiency signal: fewer tool calls -> higher. None if unknown.
173
+
174
+ clip(1 - n_calls / TOOL_BUDGET, 0, 1). TOOL_BUDGET default 15 (solved-4B
175
+ median was ~9-10 calls). Raw signal — NOT gated on correctness here; the
176
+ RL reward combiner decides gating/weights.
177
+ """
178
+ if n_calls is None:
179
+ return None
180
+ budget = float(os.environ.get("TOOL_BUDGET", "15") or "15")
181
+ if budget <= 0:
182
+ return None
183
+ return max(0.0, min(1.0, 1.0 - n_calls / budget))
184
+
185
+
186
+ def _tols() -> tuple[float, float]:
187
+ """Per-task (abs_tol, rel_tol) from ATOL/RTOL in [verifier.env]; 1e-3 default."""
188
+ def _f(name: str) -> float:
189
+ try:
190
+ return float(os.environ.get(name, "") or 1e-3)
191
+ except ValueError:
192
+ return 1e-3
193
+ return _f("ATOL"), _f("RTOL")
194
+
195
+
196
+ def main_cli() -> int:
197
+ """CLI shim for `tests/test.sh` — env-driven, stdout-only.
198
+
199
+ Inputs (via env vars set by Harbor's [verifier.env]):
200
+ EXPECTED_ANSWER — the gold
201
+ QUESTION — the original question
202
+ ATOL / RTOL — per-task numeric tolerances (default 1e-3)
203
+
204
+ Predicted answer is read from stdin.
205
+ Single float written to stdout. Exit code is always 0.
206
+ """
207
+ gold = (os.environ.get("EXPECTED_ANSWER") or "").strip()
208
+ question = (os.environ.get("QUESTION") or "").strip()
209
+ candidate = sys.stdin.read().strip()
210
+ at, rt = _tols()
211
+ result = grade(gold, candidate, question=question, reward_mode=os.environ.get("REWARD_MODE","") or "", abs_tol=at, rel_tol=rt)
212
+ print(f"{result.reward:.1f}")
213
+ print(f"[grader] gold={gold!r} pred={candidate[:80]!r} reward={result.reward} method={result.method}",
214
+ file=sys.stderr)
215
+ return 0
216
+
217
+
218
+ def main_json() -> int:
219
+ """Multi-reward shim for `tests/test.sh` — writes a `reward.json` dict.
220
+
221
+ Three named rewards (Harbor's VerifierResult.rewards carries them all):
222
+ correctness — 1.0 iff graded answer matches gold, else 0.0
223
+ submission — 1.0 iff a non-empty answer was submitted, else 0.0
224
+ tool_efficiency — 0..1 (fewer tool calls higher); null if count unknown
225
+
226
+ No submission -> all three 0. Predicted answer on stdin; JSON to stdout.
227
+ """
228
+ import json
229
+
230
+ gold = (os.environ.get("EXPECTED_ANSWER") or "").strip()
231
+ question = (os.environ.get("QUESTION") or "").strip()
232
+ candidate = sys.stdin.read().strip()
233
+
234
+ if not candidate:
235
+ print(json.dumps({"correctness": 0.0, "submission": 0.0, "tool_efficiency": 0.0}))
236
+ print("[grader] no submission -> all rewards 0", file=sys.stderr)
237
+ return 0
238
+
239
+ at, rt = _tols()
240
+ result = grade(gold, candidate, question=question, reward_mode=os.environ.get("REWARD_MODE","") or "", abs_tol=at, rel_tol=rt)
241
+ n_calls = _tool_calls()
242
+ eff = _tool_efficiency(n_calls)
243
+ print(json.dumps({
244
+ "correctness": float(result.reward),
245
+ "submission": 1.0,
246
+ "tool_efficiency": eff,
247
+ }))
248
+ print(f"[grader] gold={gold!r} pred={candidate[:80]!r} "
249
+ f"correctness={result.reward} method={result.method} "
250
+ f"tool_calls={n_calls} tool_efficiency={eff}", file=sys.stderr)
251
+ return 0
252
+
253
+
254
+ if __name__ == "__main__":
255
+ if "--json" in sys.argv[1:]:
256
+ raise SystemExit(main_json())
257
+ raise SystemExit(main_cli())
tasks/0001_261_1261978_qa_5/tests/test.sh ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -u
3
+ mkdir -p /logs/verifier
4
+
5
+ answer_path="/workdir/answer.txt"
6
+ if [ ! -s "$answer_path" ]; then
7
+ echo "0.0" > /logs/verifier/reward.txt
8
+ echo "[grader] no answer at $answer_path" >&2
9
+ exit 0
10
+ fi
11
+
12
+ pip install --quiet math-verify >/dev/null 2>&1 || true
13
+ python3 /tests/grader.py < "$answer_path" > /logs/verifier/reward.txt
tasks/0001_439_1439907_qa_3/environment/Dockerfile ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ FROM docker.io/savatar101/env-data-agent-train:base
2
+ WORKDIR /workdir
tasks/0001_439_1439907_qa_3/environment/pull_bucket.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Pull this task's bucket prefix into /home/user/input/.
2
+
3
+ Invoked by Harbor's [environment.healthcheck] command (declared in task.toml)
4
+ — runs after container start, before the agent. Idempotent: skips work if
5
+ files are already present from a prior pull.
6
+ """
7
+
8
+ import os
9
+ import sys
10
+ from pathlib import Path
11
+
12
+ from huggingface_hub import download_bucket_files, list_bucket_tree
13
+
14
+
15
+ def main() -> int:
16
+ bucket = os.environ.get("HF_BUCKET") or "AdithyaSK/jupyter-agent-kaggle-all"
17
+ prefix = os.environ["BUCKET_PREFIX"].rstrip("/") + "/"
18
+ dest = Path("/home/user/input")
19
+ dest.mkdir(parents=True, exist_ok=True)
20
+
21
+ existing = [p for p in dest.iterdir() if p.is_file()]
22
+ if existing:
23
+ print(f"[pull_bucket] {dest}/ already has {len(existing)} file(s); skipping", flush=True)
24
+ return 0
25
+
26
+ targets = [
27
+ (it.path, str(dest / Path(it.path).name))
28
+ for it in list_bucket_tree(bucket, prefix=prefix, recursive=True)
29
+ if getattr(it, "type", None) == "file"
30
+ ]
31
+ if not targets:
32
+ print(f"[pull_bucket] FATAL: no files at hf://buckets/{bucket}/{prefix}", flush=True)
33
+ return 2
34
+
35
+ download_bucket_files(bucket, files=targets)
36
+ print(f"[pull_bucket] staged {len(targets)} file(s) from {bucket}/{prefix}", flush=True)
37
+ return 0
38
+
39
+
40
+ if __name__ == "__main__":
41
+ sys.exit(main())
tasks/0001_439_1439907_qa_3/tests/grader.py ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Shared three-tier grader.
2
+
3
+ Used by both runtimes:
4
+ * `env/server.py` — inline inside the `final_answer` ORS @tool method
5
+ * `tests/test.sh` — Harbor CLI path; this module is mounted at /tests/grader.py
6
+ and invoked with `python3 /tests/grader.py < /workdir/answer.txt`
7
+
8
+ Tiers (cheapest → most expensive):
9
+ 1. Exact (case-insensitive, whitespace-collapsed)
10
+ 2. Numeric (parse a float, accept abs/rel diff ≤ 1e-3)
11
+ 3. LLM-judge (gpt-4o-mini, A/B/C verdict, OpenAI simple-evals prompt)
12
+ — only invoked if OPENAI_API_KEY is set
13
+
14
+ CLI form (used by tests/test.sh):
15
+ EXPECTED_ANSWER='5' QUESTION='How many...' python3 grader.py
16
+ → reads predicted answer from stdin
17
+ → writes a single float ('1.0' or '0.0') to stdout
18
+ → exits 0 always; harbor reads stdout from /logs/verifier/reward.txt
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ import os
24
+ import re
25
+ import sys
26
+ from dataclasses import dataclass
27
+
28
+
29
+ _NUMERIC_RE = re.compile(r"-?\d+(?:[.,]\d+)?(?:[eE][-+]?\d+)?")
30
+
31
+ # Locked in PLAN.md §"Locked decisions" — adapted from
32
+ # https://github.com/openai/simple-evals/blob/main/simpleqa_eval.py
33
+ JUDGE_PROMPT = """You are grading short answers from a data-science agent.
34
+ Decide whether the predicted answer is semantically equivalent to the gold answer.
35
+
36
+ Rules:
37
+ - Case, punctuation, whitespace, articles ("the"), and trailing units don't matter.
38
+ - For numbers: predicted must match to the last significant figure of the gold
39
+ (gold "0.544341", predicted "0.544" -> CORRECT; "0.5" -> INCORRECT).
40
+ - Extra surrounding prose is fine if the gold value is clearly stated
41
+ (gold "5", predicted "There are 5 distinct categories" -> CORRECT).
42
+ - Common synonyms/abbreviations count (gold "Not Applicable", predicted "N/A" -> CORRECT).
43
+ - Parenthetical annotations in the gold are equivalence hints, not required
44
+ (gold "Gandalf (Ainur)", predicted "Gandalf" -> CORRECT;
45
+ gold "No (correlation coefficient = 0.02)", predicted "No" -> CORRECT).
46
+ - Percent + qualifier: if the gold is "X% in YEAR", a prediction of X or X%
47
+ is CORRECT as long as the core numeric value matches
48
+ (gold "21.334% in 2014", predicted "21.334" -> CORRECT;
49
+ gold "21.334% in 2014", predicted "21.334% in 2013" -> INCORRECT — year mismatch).
50
+ - Multi-part gold like "0.987 (XGBoost and LGBM)" — if the question asks for one
51
+ thing (e.g. "which model?"), predicting either listed value is CORRECT.
52
+ - If the predicted answer hedges without committing to the gold value -> NOT_ATTEMPTED.
53
+ - If it commits to a different value -> INCORRECT.
54
+
55
+ Question: {question}
56
+ Gold answer: {gold}
57
+ Predicted answer: {pred}
58
+
59
+ Reply with exactly one token: A (CORRECT), B (INCORRECT), or C (NOT_ATTEMPTED)."""
60
+
61
+
62
+ @dataclass
63
+ class GradeResult:
64
+ reward: float
65
+ method: str # "exact" | "numeric" | "llm" | "miss"
66
+
67
+
68
+ def _normalize(s: str) -> str:
69
+ return re.sub(r"\s+", " ", (s or "").strip().lower())
70
+
71
+
72
+ def _to_float(s: str) -> float | None:
73
+ if not s:
74
+ return None
75
+ m = _NUMERIC_RE.search(s.replace(",", ""))
76
+ if not m:
77
+ return None
78
+ try:
79
+ return float(m.group(0))
80
+ except ValueError:
81
+ return None
82
+
83
+
84
+ def _math_verify_match(gold: str, candidate: str) -> bool:
85
+ """Deterministic symbolic/numeric equivalence via HuggingFace Math-Verify.
86
+
87
+ Catches equivalences the naive float-parse misses: thousands separators,
88
+ fractions (3/4 == 0.75), percentages (50% == 0.5), and symbolic forms.
89
+ Fails CLOSED — any parse error / prose gold / timeout returns False (never a
90
+ false positive). No network, no LLM.
91
+ """
92
+ try:
93
+ from math_verify import parse, verify
94
+
95
+ return bool(verify(parse(gold), parse(candidate), timeout_seconds=5))
96
+ except Exception: # noqa: BLE001
97
+ return False
98
+
99
+
100
+ def _is_clean_number(s: str) -> bool:
101
+ """True iff the whole string IS a single number (allowing a leading/trailing
102
+ %, $, and thousands-commas) — e.g. '95293', '95,293', '0.5', '-3.16', '50%'.
103
+ A COMPOUND string like 'Y=3 with 95,293 instances' is NOT a clean number, so
104
+ the numeric tier must not fire on it (its `_to_float` would grab the leading
105
+ '3' and false-positive-match any answer starting with 3)."""
106
+ t = (s or "").strip().strip("%$").strip().replace(",", "")
107
+ return bool(_NUMERIC_RE.fullmatch(t))
108
+
109
+
110
+ def grade(
111
+ gold: str,
112
+ candidate: str,
113
+ *,
114
+ question: str = "",
115
+ reward_mode: str = "",
116
+ judge: bool = True, # noqa: ARG001 — kept for signature compat; LLM tier removed
117
+ judge_model: str | None = None, # noqa: ARG001
118
+ rel_tol: float = 1e-3,
119
+ abs_tol: float = 1e-3,
120
+ ) -> GradeResult:
121
+ """Deterministic three-tier match — NO LLM judge.
122
+
123
+ exact -> numeric (abs_tol/rel_tol, gated to clean-number golds) -> math_verify
124
+ -> miss. `judge`/`judge_model` accepted but ignored (LLM tier removed).
125
+ """
126
+
127
+ if not gold or candidate is None:
128
+ return GradeResult(0.0, "miss")
129
+
130
+ # ── Tier 1: exact (case-insensitive, whitespace-collapsed) ─��───────
131
+ if _normalize(gold) == _normalize(candidate):
132
+ return GradeResult(1.0, "exact")
133
+
134
+ # ── Tier 2: numeric — ONLY when the gold is a single clean number ──
135
+ # (compound golds like "Y=3 with 95,293 instances" would otherwise match on
136
+ # the leading number; those must go to exact/math_verify, which fail closed).
137
+ if reward_mode == "numeric" or _is_clean_number(gold):
138
+ g, c = _to_float(gold), _to_float(candidate)
139
+ if g is not None and c is not None:
140
+ if abs(g - c) <= abs_tol or abs(g - c) / max(abs(g), 1e-9) <= rel_tol:
141
+ return GradeResult(1.0, "numeric")
142
+
143
+ # ── Tier 3: math-verify (symbolic/numeric equivalence, deterministic) ──
144
+ if _math_verify_match(gold, candidate):
145
+ return GradeResult(1.0, "math_verify")
146
+
147
+ return GradeResult(0.0, "miss")
148
+
149
+
150
+ def _tool_calls() -> int | None:
151
+ """Number of agent tool calls this rollout, for the efficiency reward.
152
+
153
+ Written by the harness into the sandbox (`/workdir/.n_tool_calls`); falls
154
+ back to the `N_TOOL_CALLS` env var. Returns None if neither is present
155
+ (efficiency reward becomes null — the harness didn't report a count).
156
+ """
157
+ try:
158
+ with open("/workdir/.n_tool_calls") as fh:
159
+ return int(fh.read().strip())
160
+ except (OSError, ValueError):
161
+ pass
162
+ raw = os.environ.get("N_TOOL_CALLS")
163
+ if raw is not None:
164
+ try:
165
+ return int(str(raw).strip())
166
+ except ValueError:
167
+ return None
168
+ return None
169
+
170
+
171
+ def _tool_efficiency(n_calls: int | None) -> float | None:
172
+ """0..1 efficiency signal: fewer tool calls -> higher. None if unknown.
173
+
174
+ clip(1 - n_calls / TOOL_BUDGET, 0, 1). TOOL_BUDGET default 15 (solved-4B
175
+ median was ~9-10 calls). Raw signal — NOT gated on correctness here; the
176
+ RL reward combiner decides gating/weights.
177
+ """
178
+ if n_calls is None:
179
+ return None
180
+ budget = float(os.environ.get("TOOL_BUDGET", "15") or "15")
181
+ if budget <= 0:
182
+ return None
183
+ return max(0.0, min(1.0, 1.0 - n_calls / budget))
184
+
185
+
186
+ def _tols() -> tuple[float, float]:
187
+ """Per-task (abs_tol, rel_tol) from ATOL/RTOL in [verifier.env]; 1e-3 default."""
188
+ def _f(name: str) -> float:
189
+ try:
190
+ return float(os.environ.get(name, "") or 1e-3)
191
+ except ValueError:
192
+ return 1e-3
193
+ return _f("ATOL"), _f("RTOL")
194
+
195
+
196
+ def main_cli() -> int:
197
+ """CLI shim for `tests/test.sh` — env-driven, stdout-only.
198
+
199
+ Inputs (via env vars set by Harbor's [verifier.env]):
200
+ EXPECTED_ANSWER — the gold
201
+ QUESTION — the original question
202
+ ATOL / RTOL — per-task numeric tolerances (default 1e-3)
203
+
204
+ Predicted answer is read from stdin.
205
+ Single float written to stdout. Exit code is always 0.
206
+ """
207
+ gold = (os.environ.get("EXPECTED_ANSWER") or "").strip()
208
+ question = (os.environ.get("QUESTION") or "").strip()
209
+ candidate = sys.stdin.read().strip()
210
+ at, rt = _tols()
211
+ result = grade(gold, candidate, question=question, reward_mode=os.environ.get("REWARD_MODE","") or "", abs_tol=at, rel_tol=rt)
212
+ print(f"{result.reward:.1f}")
213
+ print(f"[grader] gold={gold!r} pred={candidate[:80]!r} reward={result.reward} method={result.method}",
214
+ file=sys.stderr)
215
+ return 0
216
+
217
+
218
+ def main_json() -> int:
219
+ """Multi-reward shim for `tests/test.sh` — writes a `reward.json` dict.
220
+
221
+ Three named rewards (Harbor's VerifierResult.rewards carries them all):
222
+ correctness — 1.0 iff graded answer matches gold, else 0.0
223
+ submission — 1.0 iff a non-empty answer was submitted, else 0.0
224
+ tool_efficiency — 0..1 (fewer tool calls higher); null if count unknown
225
+
226
+ No submission -> all three 0. Predicted answer on stdin; JSON to stdout.
227
+ """
228
+ import json
229
+
230
+ gold = (os.environ.get("EXPECTED_ANSWER") or "").strip()
231
+ question = (os.environ.get("QUESTION") or "").strip()
232
+ candidate = sys.stdin.read().strip()
233
+
234
+ if not candidate:
235
+ print(json.dumps({"correctness": 0.0, "submission": 0.0, "tool_efficiency": 0.0}))
236
+ print("[grader] no submission -> all rewards 0", file=sys.stderr)
237
+ return 0
238
+
239
+ at, rt = _tols()
240
+ result = grade(gold, candidate, question=question, reward_mode=os.environ.get("REWARD_MODE","") or "", abs_tol=at, rel_tol=rt)
241
+ n_calls = _tool_calls()
242
+ eff = _tool_efficiency(n_calls)
243
+ print(json.dumps({
244
+ "correctness": float(result.reward),
245
+ "submission": 1.0,
246
+ "tool_efficiency": eff,
247
+ }))
248
+ print(f"[grader] gold={gold!r} pred={candidate[:80]!r} "
249
+ f"correctness={result.reward} method={result.method} "
250
+ f"tool_calls={n_calls} tool_efficiency={eff}", file=sys.stderr)
251
+ return 0
252
+
253
+
254
+ if __name__ == "__main__":
255
+ if "--json" in sys.argv[1:]:
256
+ raise SystemExit(main_json())
257
+ raise SystemExit(main_cli())
tasks/0001_439_1439907_qa_3/tests/test.sh ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -u
3
+ mkdir -p /logs/verifier
4
+
5
+ answer_path="/workdir/answer.txt"
6
+ if [ ! -s "$answer_path" ]; then
7
+ echo "0.0" > /logs/verifier/reward.txt
8
+ echo "[grader] no answer at $answer_path" >&2
9
+ exit 0
10
+ fi
11
+
12
+ pip install --quiet math-verify >/dev/null 2>&1 || true
13
+ python3 /tests/grader.py < "$answer_path" > /logs/verifier/reward.txt
tasks/0001_487_1487950_qa_1/environment/Dockerfile ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ FROM docker.io/savatar101/env-data-agent-train:base
2
+ WORKDIR /workdir
tasks/0001_487_1487950_qa_1/environment/pull_bucket.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Pull this task's bucket prefix into /home/user/input/.
2
+
3
+ Invoked by Harbor's [environment.healthcheck] command (declared in task.toml)
4
+ — runs after container start, before the agent. Idempotent: skips work if
5
+ files are already present from a prior pull.
6
+ """
7
+
8
+ import os
9
+ import sys
10
+ from pathlib import Path
11
+
12
+ from huggingface_hub import download_bucket_files, list_bucket_tree
13
+
14
+
15
+ def main() -> int:
16
+ bucket = os.environ.get("HF_BUCKET") or "AdithyaSK/jupyter-agent-kaggle-all"
17
+ prefix = os.environ["BUCKET_PREFIX"].rstrip("/") + "/"
18
+ dest = Path("/home/user/input")
19
+ dest.mkdir(parents=True, exist_ok=True)
20
+
21
+ existing = [p for p in dest.iterdir() if p.is_file()]
22
+ if existing:
23
+ print(f"[pull_bucket] {dest}/ already has {len(existing)} file(s); skipping", flush=True)
24
+ return 0
25
+
26
+ targets = [
27
+ (it.path, str(dest / Path(it.path).name))
28
+ for it in list_bucket_tree(bucket, prefix=prefix, recursive=True)
29
+ if getattr(it, "type", None) == "file"
30
+ ]
31
+ if not targets:
32
+ print(f"[pull_bucket] FATAL: no files at hf://buckets/{bucket}/{prefix}", flush=True)
33
+ return 2
34
+
35
+ download_bucket_files(bucket, files=targets)
36
+ print(f"[pull_bucket] staged {len(targets)} file(s) from {bucket}/{prefix}", flush=True)
37
+ return 0
38
+
39
+
40
+ if __name__ == "__main__":
41
+ sys.exit(main())
tasks/0001_487_1487950_qa_1/tests/grader.py ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Shared three-tier grader.
2
+
3
+ Used by both runtimes:
4
+ * `env/server.py` — inline inside the `final_answer` ORS @tool method
5
+ * `tests/test.sh` — Harbor CLI path; this module is mounted at /tests/grader.py
6
+ and invoked with `python3 /tests/grader.py < /workdir/answer.txt`
7
+
8
+ Tiers (cheapest → most expensive):
9
+ 1. Exact (case-insensitive, whitespace-collapsed)
10
+ 2. Numeric (parse a float, accept abs/rel diff ≤ 1e-3)
11
+ 3. LLM-judge (gpt-4o-mini, A/B/C verdict, OpenAI simple-evals prompt)
12
+ — only invoked if OPENAI_API_KEY is set
13
+
14
+ CLI form (used by tests/test.sh):
15
+ EXPECTED_ANSWER='5' QUESTION='How many...' python3 grader.py
16
+ → reads predicted answer from stdin
17
+ → writes a single float ('1.0' or '0.0') to stdout
18
+ → exits 0 always; harbor reads stdout from /logs/verifier/reward.txt
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ import os
24
+ import re
25
+ import sys
26
+ from dataclasses import dataclass
27
+
28
+
29
+ _NUMERIC_RE = re.compile(r"-?\d+(?:[.,]\d+)?(?:[eE][-+]?\d+)?")
30
+
31
+ # Locked in PLAN.md §"Locked decisions" — adapted from
32
+ # https://github.com/openai/simple-evals/blob/main/simpleqa_eval.py
33
+ JUDGE_PROMPT = """You are grading short answers from a data-science agent.
34
+ Decide whether the predicted answer is semantically equivalent to the gold answer.
35
+
36
+ Rules:
37
+ - Case, punctuation, whitespace, articles ("the"), and trailing units don't matter.
38
+ - For numbers: predicted must match to the last significant figure of the gold
39
+ (gold "0.544341", predicted "0.544" -> CORRECT; "0.5" -> INCORRECT).
40
+ - Extra surrounding prose is fine if the gold value is clearly stated
41
+ (gold "5", predicted "There are 5 distinct categories" -> CORRECT).
42
+ - Common synonyms/abbreviations count (gold "Not Applicable", predicted "N/A" -> CORRECT).
43
+ - Parenthetical annotations in the gold are equivalence hints, not required
44
+ (gold "Gandalf (Ainur)", predicted "Gandalf" -> CORRECT;
45
+ gold "No (correlation coefficient = 0.02)", predicted "No" -> CORRECT).
46
+ - Percent + qualifier: if the gold is "X% in YEAR", a prediction of X or X%
47
+ is CORRECT as long as the core numeric value matches
48
+ (gold "21.334% in 2014", predicted "21.334" -> CORRECT;
49
+ gold "21.334% in 2014", predicted "21.334% in 2013" -> INCORRECT — year mismatch).
50
+ - Multi-part gold like "0.987 (XGBoost and LGBM)" — if the question asks for one
51
+ thing (e.g. "which model?"), predicting either listed value is CORRECT.
52
+ - If the predicted answer hedges without committing to the gold value -> NOT_ATTEMPTED.
53
+ - If it commits to a different value -> INCORRECT.
54
+
55
+ Question: {question}
56
+ Gold answer: {gold}
57
+ Predicted answer: {pred}
58
+
59
+ Reply with exactly one token: A (CORRECT), B (INCORRECT), or C (NOT_ATTEMPTED)."""
60
+
61
+
62
+ @dataclass
63
+ class GradeResult:
64
+ reward: float
65
+ method: str # "exact" | "numeric" | "llm" | "miss"
66
+
67
+
68
+ def _normalize(s: str) -> str:
69
+ return re.sub(r"\s+", " ", (s or "").strip().lower())
70
+
71
+
72
+ def _to_float(s: str) -> float | None:
73
+ if not s:
74
+ return None
75
+ m = _NUMERIC_RE.search(s.replace(",", ""))
76
+ if not m:
77
+ return None
78
+ try:
79
+ return float(m.group(0))
80
+ except ValueError:
81
+ return None
82
+
83
+
84
+ def _math_verify_match(gold: str, candidate: str) -> bool:
85
+ """Deterministic symbolic/numeric equivalence via HuggingFace Math-Verify.
86
+
87
+ Catches equivalences the naive float-parse misses: thousands separators,
88
+ fractions (3/4 == 0.75), percentages (50% == 0.5), and symbolic forms.
89
+ Fails CLOSED — any parse error / prose gold / timeout returns False (never a
90
+ false positive). No network, no LLM.
91
+ """
92
+ try:
93
+ from math_verify import parse, verify
94
+
95
+ return bool(verify(parse(gold), parse(candidate), timeout_seconds=5))
96
+ except Exception: # noqa: BLE001
97
+ return False
98
+
99
+
100
+ def _is_clean_number(s: str) -> bool:
101
+ """True iff the whole string IS a single number (allowing a leading/trailing
102
+ %, $, and thousands-commas) — e.g. '95293', '95,293', '0.5', '-3.16', '50%'.
103
+ A COMPOUND string like 'Y=3 with 95,293 instances' is NOT a clean number, so
104
+ the numeric tier must not fire on it (its `_to_float` would grab the leading
105
+ '3' and false-positive-match any answer starting with 3)."""
106
+ t = (s or "").strip().strip("%$").strip().replace(",", "")
107
+ return bool(_NUMERIC_RE.fullmatch(t))
108
+
109
+
110
+ def grade(
111
+ gold: str,
112
+ candidate: str,
113
+ *,
114
+ question: str = "",
115
+ reward_mode: str = "",
116
+ judge: bool = True, # noqa: ARG001 — kept for signature compat; LLM tier removed
117
+ judge_model: str | None = None, # noqa: ARG001
118
+ rel_tol: float = 1e-3,
119
+ abs_tol: float = 1e-3,
120
+ ) -> GradeResult:
121
+ """Deterministic three-tier match — NO LLM judge.
122
+
123
+ exact -> numeric (abs_tol/rel_tol, gated to clean-number golds) -> math_verify
124
+ -> miss. `judge`/`judge_model` accepted but ignored (LLM tier removed).
125
+ """
126
+
127
+ if not gold or candidate is None:
128
+ return GradeResult(0.0, "miss")
129
+
130
+ # ── Tier 1: exact (case-insensitive, whitespace-collapsed) ─��───────
131
+ if _normalize(gold) == _normalize(candidate):
132
+ return GradeResult(1.0, "exact")
133
+
134
+ # ── Tier 2: numeric — ONLY when the gold is a single clean number ──
135
+ # (compound golds like "Y=3 with 95,293 instances" would otherwise match on
136
+ # the leading number; those must go to exact/math_verify, which fail closed).
137
+ if reward_mode == "numeric" or _is_clean_number(gold):
138
+ g, c = _to_float(gold), _to_float(candidate)
139
+ if g is not None and c is not None:
140
+ if abs(g - c) <= abs_tol or abs(g - c) / max(abs(g), 1e-9) <= rel_tol:
141
+ return GradeResult(1.0, "numeric")
142
+
143
+ # ── Tier 3: math-verify (symbolic/numeric equivalence, deterministic) ──
144
+ if _math_verify_match(gold, candidate):
145
+ return GradeResult(1.0, "math_verify")
146
+
147
+ return GradeResult(0.0, "miss")
148
+
149
+
150
+ def _tool_calls() -> int | None:
151
+ """Number of agent tool calls this rollout, for the efficiency reward.
152
+
153
+ Written by the harness into the sandbox (`/workdir/.n_tool_calls`); falls
154
+ back to the `N_TOOL_CALLS` env var. Returns None if neither is present
155
+ (efficiency reward becomes null — the harness didn't report a count).
156
+ """
157
+ try:
158
+ with open("/workdir/.n_tool_calls") as fh:
159
+ return int(fh.read().strip())
160
+ except (OSError, ValueError):
161
+ pass
162
+ raw = os.environ.get("N_TOOL_CALLS")
163
+ if raw is not None:
164
+ try:
165
+ return int(str(raw).strip())
166
+ except ValueError:
167
+ return None
168
+ return None
169
+
170
+
171
+ def _tool_efficiency(n_calls: int | None) -> float | None:
172
+ """0..1 efficiency signal: fewer tool calls -> higher. None if unknown.
173
+
174
+ clip(1 - n_calls / TOOL_BUDGET, 0, 1). TOOL_BUDGET default 15 (solved-4B
175
+ median was ~9-10 calls). Raw signal — NOT gated on correctness here; the
176
+ RL reward combiner decides gating/weights.
177
+ """
178
+ if n_calls is None:
179
+ return None
180
+ budget = float(os.environ.get("TOOL_BUDGET", "15") or "15")
181
+ if budget <= 0:
182
+ return None
183
+ return max(0.0, min(1.0, 1.0 - n_calls / budget))
184
+
185
+
186
+ def _tols() -> tuple[float, float]:
187
+ """Per-task (abs_tol, rel_tol) from ATOL/RTOL in [verifier.env]; 1e-3 default."""
188
+ def _f(name: str) -> float:
189
+ try:
190
+ return float(os.environ.get(name, "") or 1e-3)
191
+ except ValueError:
192
+ return 1e-3
193
+ return _f("ATOL"), _f("RTOL")
194
+
195
+
196
+ def main_cli() -> int:
197
+ """CLI shim for `tests/test.sh` — env-driven, stdout-only.
198
+
199
+ Inputs (via env vars set by Harbor's [verifier.env]):
200
+ EXPECTED_ANSWER — the gold
201
+ QUESTION — the original question
202
+ ATOL / RTOL — per-task numeric tolerances (default 1e-3)
203
+
204
+ Predicted answer is read from stdin.
205
+ Single float written to stdout. Exit code is always 0.
206
+ """
207
+ gold = (os.environ.get("EXPECTED_ANSWER") or "").strip()
208
+ question = (os.environ.get("QUESTION") or "").strip()
209
+ candidate = sys.stdin.read().strip()
210
+ at, rt = _tols()
211
+ result = grade(gold, candidate, question=question, reward_mode=os.environ.get("REWARD_MODE","") or "", abs_tol=at, rel_tol=rt)
212
+ print(f"{result.reward:.1f}")
213
+ print(f"[grader] gold={gold!r} pred={candidate[:80]!r} reward={result.reward} method={result.method}",
214
+ file=sys.stderr)
215
+ return 0
216
+
217
+
218
+ def main_json() -> int:
219
+ """Multi-reward shim for `tests/test.sh` — writes a `reward.json` dict.
220
+
221
+ Three named rewards (Harbor's VerifierResult.rewards carries them all):
222
+ correctness — 1.0 iff graded answer matches gold, else 0.0
223
+ submission — 1.0 iff a non-empty answer was submitted, else 0.0
224
+ tool_efficiency — 0..1 (fewer tool calls higher); null if count unknown
225
+
226
+ No submission -> all three 0. Predicted answer on stdin; JSON to stdout.
227
+ """
228
+ import json
229
+
230
+ gold = (os.environ.get("EXPECTED_ANSWER") or "").strip()
231
+ question = (os.environ.get("QUESTION") or "").strip()
232
+ candidate = sys.stdin.read().strip()
233
+
234
+ if not candidate:
235
+ print(json.dumps({"correctness": 0.0, "submission": 0.0, "tool_efficiency": 0.0}))
236
+ print("[grader] no submission -> all rewards 0", file=sys.stderr)
237
+ return 0
238
+
239
+ at, rt = _tols()
240
+ result = grade(gold, candidate, question=question, reward_mode=os.environ.get("REWARD_MODE","") or "", abs_tol=at, rel_tol=rt)
241
+ n_calls = _tool_calls()
242
+ eff = _tool_efficiency(n_calls)
243
+ print(json.dumps({
244
+ "correctness": float(result.reward),
245
+ "submission": 1.0,
246
+ "tool_efficiency": eff,
247
+ }))
248
+ print(f"[grader] gold={gold!r} pred={candidate[:80]!r} "
249
+ f"correctness={result.reward} method={result.method} "
250
+ f"tool_calls={n_calls} tool_efficiency={eff}", file=sys.stderr)
251
+ return 0
252
+
253
+
254
+ if __name__ == "__main__":
255
+ if "--json" in sys.argv[1:]:
256
+ raise SystemExit(main_json())
257
+ raise SystemExit(main_cli())
tasks/0001_487_1487950_qa_1/tests/test.sh ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -u
3
+ mkdir -p /logs/verifier
4
+
5
+ answer_path="/workdir/answer.txt"
6
+ if [ ! -s "$answer_path" ]; then
7
+ echo "0.0" > /logs/verifier/reward.txt
8
+ echo "[grader] no answer at $answer_path" >&2
9
+ exit 0
10
+ fi
11
+
12
+ pip install --quiet math-verify >/dev/null 2>&1 || true
13
+ python3 /tests/grader.py < "$answer_path" > /logs/verifier/reward.txt
tasks/0001_533_1533644_qa_3/environment/Dockerfile ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ FROM docker.io/savatar101/env-data-agent-train:base
2
+ WORKDIR /workdir
tasks/0001_533_1533644_qa_3/environment/pull_bucket.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Pull this task's bucket prefix into /home/user/input/.
2
+
3
+ Invoked by Harbor's [environment.healthcheck] command (declared in task.toml)
4
+ — runs after container start, before the agent. Idempotent: skips work if
5
+ files are already present from a prior pull.
6
+ """
7
+
8
+ import os
9
+ import sys
10
+ from pathlib import Path
11
+
12
+ from huggingface_hub import download_bucket_files, list_bucket_tree
13
+
14
+
15
+ def main() -> int:
16
+ bucket = os.environ.get("HF_BUCKET") or "AdithyaSK/jupyter-agent-kaggle-all"
17
+ prefix = os.environ["BUCKET_PREFIX"].rstrip("/") + "/"
18
+ dest = Path("/home/user/input")
19
+ dest.mkdir(parents=True, exist_ok=True)
20
+
21
+ existing = [p for p in dest.iterdir() if p.is_file()]
22
+ if existing:
23
+ print(f"[pull_bucket] {dest}/ already has {len(existing)} file(s); skipping", flush=True)
24
+ return 0
25
+
26
+ targets = [
27
+ (it.path, str(dest / Path(it.path).name))
28
+ for it in list_bucket_tree(bucket, prefix=prefix, recursive=True)
29
+ if getattr(it, "type", None) == "file"
30
+ ]
31
+ if not targets:
32
+ print(f"[pull_bucket] FATAL: no files at hf://buckets/{bucket}/{prefix}", flush=True)
33
+ return 2
34
+
35
+ download_bucket_files(bucket, files=targets)
36
+ print(f"[pull_bucket] staged {len(targets)} file(s) from {bucket}/{prefix}", flush=True)
37
+ return 0
38
+
39
+
40
+ if __name__ == "__main__":
41
+ sys.exit(main())
tasks/0001_533_1533644_qa_3/tests/grader.py ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Shared three-tier grader.
2
+
3
+ Used by both runtimes:
4
+ * `env/server.py` — inline inside the `final_answer` ORS @tool method
5
+ * `tests/test.sh` — Harbor CLI path; this module is mounted at /tests/grader.py
6
+ and invoked with `python3 /tests/grader.py < /workdir/answer.txt`
7
+
8
+ Tiers (cheapest → most expensive):
9
+ 1. Exact (case-insensitive, whitespace-collapsed)
10
+ 2. Numeric (parse a float, accept abs/rel diff ≤ 1e-3)
11
+ 3. LLM-judge (gpt-4o-mini, A/B/C verdict, OpenAI simple-evals prompt)
12
+ — only invoked if OPENAI_API_KEY is set
13
+
14
+ CLI form (used by tests/test.sh):
15
+ EXPECTED_ANSWER='5' QUESTION='How many...' python3 grader.py
16
+ → reads predicted answer from stdin
17
+ → writes a single float ('1.0' or '0.0') to stdout
18
+ → exits 0 always; harbor reads stdout from /logs/verifier/reward.txt
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ import os
24
+ import re
25
+ import sys
26
+ from dataclasses import dataclass
27
+
28
+
29
+ _NUMERIC_RE = re.compile(r"-?\d+(?:[.,]\d+)?(?:[eE][-+]?\d+)?")
30
+
31
+ # Locked in PLAN.md §"Locked decisions" — adapted from
32
+ # https://github.com/openai/simple-evals/blob/main/simpleqa_eval.py
33
+ JUDGE_PROMPT = """You are grading short answers from a data-science agent.
34
+ Decide whether the predicted answer is semantically equivalent to the gold answer.
35
+
36
+ Rules:
37
+ - Case, punctuation, whitespace, articles ("the"), and trailing units don't matter.
38
+ - For numbers: predicted must match to the last significant figure of the gold
39
+ (gold "0.544341", predicted "0.544" -> CORRECT; "0.5" -> INCORRECT).
40
+ - Extra surrounding prose is fine if the gold value is clearly stated
41
+ (gold "5", predicted "There are 5 distinct categories" -> CORRECT).
42
+ - Common synonyms/abbreviations count (gold "Not Applicable", predicted "N/A" -> CORRECT).
43
+ - Parenthetical annotations in the gold are equivalence hints, not required
44
+ (gold "Gandalf (Ainur)", predicted "Gandalf" -> CORRECT;
45
+ gold "No (correlation coefficient = 0.02)", predicted "No" -> CORRECT).
46
+ - Percent + qualifier: if the gold is "X% in YEAR", a prediction of X or X%
47
+ is CORRECT as long as the core numeric value matches
48
+ (gold "21.334% in 2014", predicted "21.334" -> CORRECT;
49
+ gold "21.334% in 2014", predicted "21.334% in 2013" -> INCORRECT — year mismatch).
50
+ - Multi-part gold like "0.987 (XGBoost and LGBM)" — if the question asks for one
51
+ thing (e.g. "which model?"), predicting either listed value is CORRECT.
52
+ - If the predicted answer hedges without committing to the gold value -> NOT_ATTEMPTED.
53
+ - If it commits to a different value -> INCORRECT.
54
+
55
+ Question: {question}
56
+ Gold answer: {gold}
57
+ Predicted answer: {pred}
58
+
59
+ Reply with exactly one token: A (CORRECT), B (INCORRECT), or C (NOT_ATTEMPTED)."""
60
+
61
+
62
+ @dataclass
63
+ class GradeResult:
64
+ reward: float
65
+ method: str # "exact" | "numeric" | "llm" | "miss"
66
+
67
+
68
+ def _normalize(s: str) -> str:
69
+ return re.sub(r"\s+", " ", (s or "").strip().lower())
70
+
71
+
72
+ def _to_float(s: str) -> float | None:
73
+ if not s:
74
+ return None
75
+ m = _NUMERIC_RE.search(s.replace(",", ""))
76
+ if not m:
77
+ return None
78
+ try:
79
+ return float(m.group(0))
80
+ except ValueError:
81
+ return None
82
+
83
+
84
+ def _math_verify_match(gold: str, candidate: str) -> bool:
85
+ """Deterministic symbolic/numeric equivalence via HuggingFace Math-Verify.
86
+
87
+ Catches equivalences the naive float-parse misses: thousands separators,
88
+ fractions (3/4 == 0.75), percentages (50% == 0.5), and symbolic forms.
89
+ Fails CLOSED — any parse error / prose gold / timeout returns False (never a
90
+ false positive). No network, no LLM.
91
+ """
92
+ try:
93
+ from math_verify import parse, verify
94
+
95
+ return bool(verify(parse(gold), parse(candidate), timeout_seconds=5))
96
+ except Exception: # noqa: BLE001
97
+ return False
98
+
99
+
100
+ def _is_clean_number(s: str) -> bool:
101
+ """True iff the whole string IS a single number (allowing a leading/trailing
102
+ %, $, and thousands-commas) — e.g. '95293', '95,293', '0.5', '-3.16', '50%'.
103
+ A COMPOUND string like 'Y=3 with 95,293 instances' is NOT a clean number, so
104
+ the numeric tier must not fire on it (its `_to_float` would grab the leading
105
+ '3' and false-positive-match any answer starting with 3)."""
106
+ t = (s or "").strip().strip("%$").strip().replace(",", "")
107
+ return bool(_NUMERIC_RE.fullmatch(t))
108
+
109
+
110
+ def grade(
111
+ gold: str,
112
+ candidate: str,
113
+ *,
114
+ question: str = "",
115
+ reward_mode: str = "",
116
+ judge: bool = True, # noqa: ARG001 — kept for signature compat; LLM tier removed
117
+ judge_model: str | None = None, # noqa: ARG001
118
+ rel_tol: float = 1e-3,
119
+ abs_tol: float = 1e-3,
120
+ ) -> GradeResult:
121
+ """Deterministic three-tier match — NO LLM judge.
122
+
123
+ exact -> numeric (abs_tol/rel_tol, gated to clean-number golds) -> math_verify
124
+ -> miss. `judge`/`judge_model` accepted but ignored (LLM tier removed).
125
+ """
126
+
127
+ if not gold or candidate is None:
128
+ return GradeResult(0.0, "miss")
129
+
130
+ # ── Tier 1: exact (case-insensitive, whitespace-collapsed) ─��───────
131
+ if _normalize(gold) == _normalize(candidate):
132
+ return GradeResult(1.0, "exact")
133
+
134
+ # ── Tier 2: numeric — ONLY when the gold is a single clean number ──
135
+ # (compound golds like "Y=3 with 95,293 instances" would otherwise match on
136
+ # the leading number; those must go to exact/math_verify, which fail closed).
137
+ if reward_mode == "numeric" or _is_clean_number(gold):
138
+ g, c = _to_float(gold), _to_float(candidate)
139
+ if g is not None and c is not None:
140
+ if abs(g - c) <= abs_tol or abs(g - c) / max(abs(g), 1e-9) <= rel_tol:
141
+ return GradeResult(1.0, "numeric")
142
+
143
+ # ── Tier 3: math-verify (symbolic/numeric equivalence, deterministic) ──
144
+ if _math_verify_match(gold, candidate):
145
+ return GradeResult(1.0, "math_verify")
146
+
147
+ return GradeResult(0.0, "miss")
148
+
149
+
150
+ def _tool_calls() -> int | None:
151
+ """Number of agent tool calls this rollout, for the efficiency reward.
152
+
153
+ Written by the harness into the sandbox (`/workdir/.n_tool_calls`); falls
154
+ back to the `N_TOOL_CALLS` env var. Returns None if neither is present
155
+ (efficiency reward becomes null — the harness didn't report a count).
156
+ """
157
+ try:
158
+ with open("/workdir/.n_tool_calls") as fh:
159
+ return int(fh.read().strip())
160
+ except (OSError, ValueError):
161
+ pass
162
+ raw = os.environ.get("N_TOOL_CALLS")
163
+ if raw is not None:
164
+ try:
165
+ return int(str(raw).strip())
166
+ except ValueError:
167
+ return None
168
+ return None
169
+
170
+
171
+ def _tool_efficiency(n_calls: int | None) -> float | None:
172
+ """0..1 efficiency signal: fewer tool calls -> higher. None if unknown.
173
+
174
+ clip(1 - n_calls / TOOL_BUDGET, 0, 1). TOOL_BUDGET default 15 (solved-4B
175
+ median was ~9-10 calls). Raw signal — NOT gated on correctness here; the
176
+ RL reward combiner decides gating/weights.
177
+ """
178
+ if n_calls is None:
179
+ return None
180
+ budget = float(os.environ.get("TOOL_BUDGET", "15") or "15")
181
+ if budget <= 0:
182
+ return None
183
+ return max(0.0, min(1.0, 1.0 - n_calls / budget))
184
+
185
+
186
+ def _tols() -> tuple[float, float]:
187
+ """Per-task (abs_tol, rel_tol) from ATOL/RTOL in [verifier.env]; 1e-3 default."""
188
+ def _f(name: str) -> float:
189
+ try:
190
+ return float(os.environ.get(name, "") or 1e-3)
191
+ except ValueError:
192
+ return 1e-3
193
+ return _f("ATOL"), _f("RTOL")
194
+
195
+
196
+ def main_cli() -> int:
197
+ """CLI shim for `tests/test.sh` — env-driven, stdout-only.
198
+
199
+ Inputs (via env vars set by Harbor's [verifier.env]):
200
+ EXPECTED_ANSWER — the gold
201
+ QUESTION — the original question
202
+ ATOL / RTOL — per-task numeric tolerances (default 1e-3)
203
+
204
+ Predicted answer is read from stdin.
205
+ Single float written to stdout. Exit code is always 0.
206
+ """
207
+ gold = (os.environ.get("EXPECTED_ANSWER") or "").strip()
208
+ question = (os.environ.get("QUESTION") or "").strip()
209
+ candidate = sys.stdin.read().strip()
210
+ at, rt = _tols()
211
+ result = grade(gold, candidate, question=question, reward_mode=os.environ.get("REWARD_MODE","") or "", abs_tol=at, rel_tol=rt)
212
+ print(f"{result.reward:.1f}")
213
+ print(f"[grader] gold={gold!r} pred={candidate[:80]!r} reward={result.reward} method={result.method}",
214
+ file=sys.stderr)
215
+ return 0
216
+
217
+
218
+ def main_json() -> int:
219
+ """Multi-reward shim for `tests/test.sh` — writes a `reward.json` dict.
220
+
221
+ Three named rewards (Harbor's VerifierResult.rewards carries them all):
222
+ correctness — 1.0 iff graded answer matches gold, else 0.0
223
+ submission — 1.0 iff a non-empty answer was submitted, else 0.0
224
+ tool_efficiency — 0..1 (fewer tool calls higher); null if count unknown
225
+
226
+ No submission -> all three 0. Predicted answer on stdin; JSON to stdout.
227
+ """
228
+ import json
229
+
230
+ gold = (os.environ.get("EXPECTED_ANSWER") or "").strip()
231
+ question = (os.environ.get("QUESTION") or "").strip()
232
+ candidate = sys.stdin.read().strip()
233
+
234
+ if not candidate:
235
+ print(json.dumps({"correctness": 0.0, "submission": 0.0, "tool_efficiency": 0.0}))
236
+ print("[grader] no submission -> all rewards 0", file=sys.stderr)
237
+ return 0
238
+
239
+ at, rt = _tols()
240
+ result = grade(gold, candidate, question=question, reward_mode=os.environ.get("REWARD_MODE","") or "", abs_tol=at, rel_tol=rt)
241
+ n_calls = _tool_calls()
242
+ eff = _tool_efficiency(n_calls)
243
+ print(json.dumps({
244
+ "correctness": float(result.reward),
245
+ "submission": 1.0,
246
+ "tool_efficiency": eff,
247
+ }))
248
+ print(f"[grader] gold={gold!r} pred={candidate[:80]!r} "
249
+ f"correctness={result.reward} method={result.method} "
250
+ f"tool_calls={n_calls} tool_efficiency={eff}", file=sys.stderr)
251
+ return 0
252
+
253
+
254
+ if __name__ == "__main__":
255
+ if "--json" in sys.argv[1:]:
256
+ raise SystemExit(main_json())
257
+ raise SystemExit(main_cli())
tasks/0001_533_1533644_qa_3/tests/test.sh ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -u
3
+ mkdir -p /logs/verifier
4
+
5
+ answer_path="/workdir/answer.txt"
6
+ if [ ! -s "$answer_path" ]; then
7
+ echo "0.0" > /logs/verifier/reward.txt
8
+ echo "[grader] no answer at $answer_path" >&2
9
+ exit 0
10
+ fi
11
+
12
+ pip install --quiet math-verify >/dev/null 2>&1 || true
13
+ python3 /tests/grader.py < "$answer_path" > /logs/verifier/reward.txt
tasks/0001_683_1683832_qa_5/environment/Dockerfile ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ FROM docker.io/savatar101/env-data-agent-train:base
2
+ WORKDIR /workdir
tasks/0001_683_1683832_qa_5/environment/pull_bucket.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Pull this task's bucket prefix into /home/user/input/.
2
+
3
+ Invoked by Harbor's [environment.healthcheck] command (declared in task.toml)
4
+ — runs after container start, before the agent. Idempotent: skips work if
5
+ files are already present from a prior pull.
6
+ """
7
+
8
+ import os
9
+ import sys
10
+ from pathlib import Path
11
+
12
+ from huggingface_hub import download_bucket_files, list_bucket_tree
13
+
14
+
15
+ def main() -> int:
16
+ bucket = os.environ.get("HF_BUCKET") or "AdithyaSK/jupyter-agent-kaggle-all"
17
+ prefix = os.environ["BUCKET_PREFIX"].rstrip("/") + "/"
18
+ dest = Path("/home/user/input")
19
+ dest.mkdir(parents=True, exist_ok=True)
20
+
21
+ existing = [p for p in dest.iterdir() if p.is_file()]
22
+ if existing:
23
+ print(f"[pull_bucket] {dest}/ already has {len(existing)} file(s); skipping", flush=True)
24
+ return 0
25
+
26
+ targets = [
27
+ (it.path, str(dest / Path(it.path).name))
28
+ for it in list_bucket_tree(bucket, prefix=prefix, recursive=True)
29
+ if getattr(it, "type", None) == "file"
30
+ ]
31
+ if not targets:
32
+ print(f"[pull_bucket] FATAL: no files at hf://buckets/{bucket}/{prefix}", flush=True)
33
+ return 2
34
+
35
+ download_bucket_files(bucket, files=targets)
36
+ print(f"[pull_bucket] staged {len(targets)} file(s) from {bucket}/{prefix}", flush=True)
37
+ return 0
38
+
39
+
40
+ if __name__ == "__main__":
41
+ sys.exit(main())
tasks/0001_683_1683832_qa_5/tests/grader.py ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Shared three-tier grader.
2
+
3
+ Used by both runtimes:
4
+ * `env/server.py` — inline inside the `final_answer` ORS @tool method
5
+ * `tests/test.sh` — Harbor CLI path; this module is mounted at /tests/grader.py
6
+ and invoked with `python3 /tests/grader.py < /workdir/answer.txt`
7
+
8
+ Tiers (cheapest → most expensive):
9
+ 1. Exact (case-insensitive, whitespace-collapsed)
10
+ 2. Numeric (parse a float, accept abs/rel diff ≤ 1e-3)
11
+ 3. LLM-judge (gpt-4o-mini, A/B/C verdict, OpenAI simple-evals prompt)
12
+ — only invoked if OPENAI_API_KEY is set
13
+
14
+ CLI form (used by tests/test.sh):
15
+ EXPECTED_ANSWER='5' QUESTION='How many...' python3 grader.py
16
+ → reads predicted answer from stdin
17
+ → writes a single float ('1.0' or '0.0') to stdout
18
+ → exits 0 always; harbor reads stdout from /logs/verifier/reward.txt
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ import os
24
+ import re
25
+ import sys
26
+ from dataclasses import dataclass
27
+
28
+
29
+ _NUMERIC_RE = re.compile(r"-?\d+(?:[.,]\d+)?(?:[eE][-+]?\d+)?")
30
+
31
+ # Locked in PLAN.md §"Locked decisions" — adapted from
32
+ # https://github.com/openai/simple-evals/blob/main/simpleqa_eval.py
33
+ JUDGE_PROMPT = """You are grading short answers from a data-science agent.
34
+ Decide whether the predicted answer is semantically equivalent to the gold answer.
35
+
36
+ Rules:
37
+ - Case, punctuation, whitespace, articles ("the"), and trailing units don't matter.
38
+ - For numbers: predicted must match to the last significant figure of the gold
39
+ (gold "0.544341", predicted "0.544" -> CORRECT; "0.5" -> INCORRECT).
40
+ - Extra surrounding prose is fine if the gold value is clearly stated
41
+ (gold "5", predicted "There are 5 distinct categories" -> CORRECT).
42
+ - Common synonyms/abbreviations count (gold "Not Applicable", predicted "N/A" -> CORRECT).
43
+ - Parenthetical annotations in the gold are equivalence hints, not required
44
+ (gold "Gandalf (Ainur)", predicted "Gandalf" -> CORRECT;
45
+ gold "No (correlation coefficient = 0.02)", predicted "No" -> CORRECT).
46
+ - Percent + qualifier: if the gold is "X% in YEAR", a prediction of X or X%
47
+ is CORRECT as long as the core numeric value matches
48
+ (gold "21.334% in 2014", predicted "21.334" -> CORRECT;
49
+ gold "21.334% in 2014", predicted "21.334% in 2013" -> INCORRECT — year mismatch).
50
+ - Multi-part gold like "0.987 (XGBoost and LGBM)" — if the question asks for one
51
+ thing (e.g. "which model?"), predicting either listed value is CORRECT.
52
+ - If the predicted answer hedges without committing to the gold value -> NOT_ATTEMPTED.
53
+ - If it commits to a different value -> INCORRECT.
54
+
55
+ Question: {question}
56
+ Gold answer: {gold}
57
+ Predicted answer: {pred}
58
+
59
+ Reply with exactly one token: A (CORRECT), B (INCORRECT), or C (NOT_ATTEMPTED)."""
60
+
61
+
62
+ @dataclass
63
+ class GradeResult:
64
+ reward: float
65
+ method: str # "exact" | "numeric" | "llm" | "miss"
66
+
67
+
68
+ def _normalize(s: str) -> str:
69
+ return re.sub(r"\s+", " ", (s or "").strip().lower())
70
+
71
+
72
+ def _to_float(s: str) -> float | None:
73
+ if not s:
74
+ return None
75
+ m = _NUMERIC_RE.search(s.replace(",", ""))
76
+ if not m:
77
+ return None
78
+ try:
79
+ return float(m.group(0))
80
+ except ValueError:
81
+ return None
82
+
83
+
84
+ def _math_verify_match(gold: str, candidate: str) -> bool:
85
+ """Deterministic symbolic/numeric equivalence via HuggingFace Math-Verify.
86
+
87
+ Catches equivalences the naive float-parse misses: thousands separators,
88
+ fractions (3/4 == 0.75), percentages (50% == 0.5), and symbolic forms.
89
+ Fails CLOSED — any parse error / prose gold / timeout returns False (never a
90
+ false positive). No network, no LLM.
91
+ """
92
+ try:
93
+ from math_verify import parse, verify
94
+
95
+ return bool(verify(parse(gold), parse(candidate), timeout_seconds=5))
96
+ except Exception: # noqa: BLE001
97
+ return False
98
+
99
+
100
+ def _is_clean_number(s: str) -> bool:
101
+ """True iff the whole string IS a single number (allowing a leading/trailing
102
+ %, $, and thousands-commas) — e.g. '95293', '95,293', '0.5', '-3.16', '50%'.
103
+ A COMPOUND string like 'Y=3 with 95,293 instances' is NOT a clean number, so
104
+ the numeric tier must not fire on it (its `_to_float` would grab the leading
105
+ '3' and false-positive-match any answer starting with 3)."""
106
+ t = (s or "").strip().strip("%$").strip().replace(",", "")
107
+ return bool(_NUMERIC_RE.fullmatch(t))
108
+
109
+
110
+ def grade(
111
+ gold: str,
112
+ candidate: str,
113
+ *,
114
+ question: str = "",
115
+ reward_mode: str = "",
116
+ judge: bool = True, # noqa: ARG001 — kept for signature compat; LLM tier removed
117
+ judge_model: str | None = None, # noqa: ARG001
118
+ rel_tol: float = 1e-3,
119
+ abs_tol: float = 1e-3,
120
+ ) -> GradeResult:
121
+ """Deterministic three-tier match — NO LLM judge.
122
+
123
+ exact -> numeric (abs_tol/rel_tol, gated to clean-number golds) -> math_verify
124
+ -> miss. `judge`/`judge_model` accepted but ignored (LLM tier removed).
125
+ """
126
+
127
+ if not gold or candidate is None:
128
+ return GradeResult(0.0, "miss")
129
+
130
+ # ── Tier 1: exact (case-insensitive, whitespace-collapsed) ─��───────
131
+ if _normalize(gold) == _normalize(candidate):
132
+ return GradeResult(1.0, "exact")
133
+
134
+ # ── Tier 2: numeric — ONLY when the gold is a single clean number ──
135
+ # (compound golds like "Y=3 with 95,293 instances" would otherwise match on
136
+ # the leading number; those must go to exact/math_verify, which fail closed).
137
+ if reward_mode == "numeric" or _is_clean_number(gold):
138
+ g, c = _to_float(gold), _to_float(candidate)
139
+ if g is not None and c is not None:
140
+ if abs(g - c) <= abs_tol or abs(g - c) / max(abs(g), 1e-9) <= rel_tol:
141
+ return GradeResult(1.0, "numeric")
142
+
143
+ # ── Tier 3: math-verify (symbolic/numeric equivalence, deterministic) ──
144
+ if _math_verify_match(gold, candidate):
145
+ return GradeResult(1.0, "math_verify")
146
+
147
+ return GradeResult(0.0, "miss")
148
+
149
+
150
+ def _tool_calls() -> int | None:
151
+ """Number of agent tool calls this rollout, for the efficiency reward.
152
+
153
+ Written by the harness into the sandbox (`/workdir/.n_tool_calls`); falls
154
+ back to the `N_TOOL_CALLS` env var. Returns None if neither is present
155
+ (efficiency reward becomes null — the harness didn't report a count).
156
+ """
157
+ try:
158
+ with open("/workdir/.n_tool_calls") as fh:
159
+ return int(fh.read().strip())
160
+ except (OSError, ValueError):
161
+ pass
162
+ raw = os.environ.get("N_TOOL_CALLS")
163
+ if raw is not None:
164
+ try:
165
+ return int(str(raw).strip())
166
+ except ValueError:
167
+ return None
168
+ return None
169
+
170
+
171
+ def _tool_efficiency(n_calls: int | None) -> float | None:
172
+ """0..1 efficiency signal: fewer tool calls -> higher. None if unknown.
173
+
174
+ clip(1 - n_calls / TOOL_BUDGET, 0, 1). TOOL_BUDGET default 15 (solved-4B
175
+ median was ~9-10 calls). Raw signal — NOT gated on correctness here; the
176
+ RL reward combiner decides gating/weights.
177
+ """
178
+ if n_calls is None:
179
+ return None
180
+ budget = float(os.environ.get("TOOL_BUDGET", "15") or "15")
181
+ if budget <= 0:
182
+ return None
183
+ return max(0.0, min(1.0, 1.0 - n_calls / budget))
184
+
185
+
186
+ def _tols() -> tuple[float, float]:
187
+ """Per-task (abs_tol, rel_tol) from ATOL/RTOL in [verifier.env]; 1e-3 default."""
188
+ def _f(name: str) -> float:
189
+ try:
190
+ return float(os.environ.get(name, "") or 1e-3)
191
+ except ValueError:
192
+ return 1e-3
193
+ return _f("ATOL"), _f("RTOL")
194
+
195
+
196
+ def main_cli() -> int:
197
+ """CLI shim for `tests/test.sh` — env-driven, stdout-only.
198
+
199
+ Inputs (via env vars set by Harbor's [verifier.env]):
200
+ EXPECTED_ANSWER — the gold
201
+ QUESTION — the original question
202
+ ATOL / RTOL — per-task numeric tolerances (default 1e-3)
203
+
204
+ Predicted answer is read from stdin.
205
+ Single float written to stdout. Exit code is always 0.
206
+ """
207
+ gold = (os.environ.get("EXPECTED_ANSWER") or "").strip()
208
+ question = (os.environ.get("QUESTION") or "").strip()
209
+ candidate = sys.stdin.read().strip()
210
+ at, rt = _tols()
211
+ result = grade(gold, candidate, question=question, reward_mode=os.environ.get("REWARD_MODE","") or "", abs_tol=at, rel_tol=rt)
212
+ print(f"{result.reward:.1f}")
213
+ print(f"[grader] gold={gold!r} pred={candidate[:80]!r} reward={result.reward} method={result.method}",
214
+ file=sys.stderr)
215
+ return 0
216
+
217
+
218
+ def main_json() -> int:
219
+ """Multi-reward shim for `tests/test.sh` — writes a `reward.json` dict.
220
+
221
+ Three named rewards (Harbor's VerifierResult.rewards carries them all):
222
+ correctness — 1.0 iff graded answer matches gold, else 0.0
223
+ submission — 1.0 iff a non-empty answer was submitted, else 0.0
224
+ tool_efficiency — 0..1 (fewer tool calls higher); null if count unknown
225
+
226
+ No submission -> all three 0. Predicted answer on stdin; JSON to stdout.
227
+ """
228
+ import json
229
+
230
+ gold = (os.environ.get("EXPECTED_ANSWER") or "").strip()
231
+ question = (os.environ.get("QUESTION") or "").strip()
232
+ candidate = sys.stdin.read().strip()
233
+
234
+ if not candidate:
235
+ print(json.dumps({"correctness": 0.0, "submission": 0.0, "tool_efficiency": 0.0}))
236
+ print("[grader] no submission -> all rewards 0", file=sys.stderr)
237
+ return 0
238
+
239
+ at, rt = _tols()
240
+ result = grade(gold, candidate, question=question, reward_mode=os.environ.get("REWARD_MODE","") or "", abs_tol=at, rel_tol=rt)
241
+ n_calls = _tool_calls()
242
+ eff = _tool_efficiency(n_calls)
243
+ print(json.dumps({
244
+ "correctness": float(result.reward),
245
+ "submission": 1.0,
246
+ "tool_efficiency": eff,
247
+ }))
248
+ print(f"[grader] gold={gold!r} pred={candidate[:80]!r} "
249
+ f"correctness={result.reward} method={result.method} "
250
+ f"tool_calls={n_calls} tool_efficiency={eff}", file=sys.stderr)
251
+ return 0
252
+
253
+
254
+ if __name__ == "__main__":
255
+ if "--json" in sys.argv[1:]:
256
+ raise SystemExit(main_json())
257
+ raise SystemExit(main_cli())
tasks/0001_683_1683832_qa_5/tests/test.sh ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -u
3
+ mkdir -p /logs/verifier
4
+
5
+ answer_path="/workdir/answer.txt"
6
+ if [ ! -s "$answer_path" ]; then
7
+ echo "0.0" > /logs/verifier/reward.txt
8
+ echo "[grader] no answer at $answer_path" >&2
9
+ exit 0
10
+ fi
11
+
12
+ pip install --quiet math-verify >/dev/null 2>&1 || true
13
+ python3 /tests/grader.py < "$answer_path" > /logs/verifier/reward.txt
tasks/0001_727_1727043_qa_4/environment/Dockerfile ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ FROM docker.io/savatar101/env-data-agent-train:base
2
+ WORKDIR /workdir
tasks/0001_727_1727043_qa_4/environment/pull_bucket.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Pull this task's bucket prefix into /home/user/input/.
2
+
3
+ Invoked by Harbor's [environment.healthcheck] command (declared in task.toml)
4
+ — runs after container start, before the agent. Idempotent: skips work if
5
+ files are already present from a prior pull.
6
+ """
7
+
8
+ import os
9
+ import sys
10
+ from pathlib import Path
11
+
12
+ from huggingface_hub import download_bucket_files, list_bucket_tree
13
+
14
+
15
+ def main() -> int:
16
+ bucket = os.environ.get("HF_BUCKET") or "AdithyaSK/jupyter-agent-kaggle-all"
17
+ prefix = os.environ["BUCKET_PREFIX"].rstrip("/") + "/"
18
+ dest = Path("/home/user/input")
19
+ dest.mkdir(parents=True, exist_ok=True)
20
+
21
+ existing = [p for p in dest.iterdir() if p.is_file()]
22
+ if existing:
23
+ print(f"[pull_bucket] {dest}/ already has {len(existing)} file(s); skipping", flush=True)
24
+ return 0
25
+
26
+ targets = [
27
+ (it.path, str(dest / Path(it.path).name))
28
+ for it in list_bucket_tree(bucket, prefix=prefix, recursive=True)
29
+ if getattr(it, "type", None) == "file"
30
+ ]
31
+ if not targets:
32
+ print(f"[pull_bucket] FATAL: no files at hf://buckets/{bucket}/{prefix}", flush=True)
33
+ return 2
34
+
35
+ download_bucket_files(bucket, files=targets)
36
+ print(f"[pull_bucket] staged {len(targets)} file(s) from {bucket}/{prefix}", flush=True)
37
+ return 0
38
+
39
+
40
+ if __name__ == "__main__":
41
+ sys.exit(main())
tasks/0001_727_1727043_qa_4/tests/grader.py ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Shared three-tier grader.
2
+
3
+ Used by both runtimes:
4
+ * `env/server.py` — inline inside the `final_answer` ORS @tool method
5
+ * `tests/test.sh` — Harbor CLI path; this module is mounted at /tests/grader.py
6
+ and invoked with `python3 /tests/grader.py < /workdir/answer.txt`
7
+
8
+ Tiers (cheapest → most expensive):
9
+ 1. Exact (case-insensitive, whitespace-collapsed)
10
+ 2. Numeric (parse a float, accept abs/rel diff ≤ 1e-3)
11
+ 3. LLM-judge (gpt-4o-mini, A/B/C verdict, OpenAI simple-evals prompt)
12
+ — only invoked if OPENAI_API_KEY is set
13
+
14
+ CLI form (used by tests/test.sh):
15
+ EXPECTED_ANSWER='5' QUESTION='How many...' python3 grader.py
16
+ → reads predicted answer from stdin
17
+ → writes a single float ('1.0' or '0.0') to stdout
18
+ → exits 0 always; harbor reads stdout from /logs/verifier/reward.txt
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ import os
24
+ import re
25
+ import sys
26
+ from dataclasses import dataclass
27
+
28
+
29
+ _NUMERIC_RE = re.compile(r"-?\d+(?:[.,]\d+)?(?:[eE][-+]?\d+)?")
30
+
31
+ # Locked in PLAN.md §"Locked decisions" — adapted from
32
+ # https://github.com/openai/simple-evals/blob/main/simpleqa_eval.py
33
+ JUDGE_PROMPT = """You are grading short answers from a data-science agent.
34
+ Decide whether the predicted answer is semantically equivalent to the gold answer.
35
+
36
+ Rules:
37
+ - Case, punctuation, whitespace, articles ("the"), and trailing units don't matter.
38
+ - For numbers: predicted must match to the last significant figure of the gold
39
+ (gold "0.544341", predicted "0.544" -> CORRECT; "0.5" -> INCORRECT).
40
+ - Extra surrounding prose is fine if the gold value is clearly stated
41
+ (gold "5", predicted "There are 5 distinct categories" -> CORRECT).
42
+ - Common synonyms/abbreviations count (gold "Not Applicable", predicted "N/A" -> CORRECT).
43
+ - Parenthetical annotations in the gold are equivalence hints, not required
44
+ (gold "Gandalf (Ainur)", predicted "Gandalf" -> CORRECT;
45
+ gold "No (correlation coefficient = 0.02)", predicted "No" -> CORRECT).
46
+ - Percent + qualifier: if the gold is "X% in YEAR", a prediction of X or X%
47
+ is CORRECT as long as the core numeric value matches
48
+ (gold "21.334% in 2014", predicted "21.334" -> CORRECT;
49
+ gold "21.334% in 2014", predicted "21.334% in 2013" -> INCORRECT — year mismatch).
50
+ - Multi-part gold like "0.987 (XGBoost and LGBM)" — if the question asks for one
51
+ thing (e.g. "which model?"), predicting either listed value is CORRECT.
52
+ - If the predicted answer hedges without committing to the gold value -> NOT_ATTEMPTED.
53
+ - If it commits to a different value -> INCORRECT.
54
+
55
+ Question: {question}
56
+ Gold answer: {gold}
57
+ Predicted answer: {pred}
58
+
59
+ Reply with exactly one token: A (CORRECT), B (INCORRECT), or C (NOT_ATTEMPTED)."""
60
+
61
+
62
+ @dataclass
63
+ class GradeResult:
64
+ reward: float
65
+ method: str # "exact" | "numeric" | "llm" | "miss"
66
+
67
+
68
+ def _normalize(s: str) -> str:
69
+ return re.sub(r"\s+", " ", (s or "").strip().lower())
70
+
71
+
72
+ def _to_float(s: str) -> float | None:
73
+ if not s:
74
+ return None
75
+ m = _NUMERIC_RE.search(s.replace(",", ""))
76
+ if not m:
77
+ return None
78
+ try:
79
+ return float(m.group(0))
80
+ except ValueError:
81
+ return None
82
+
83
+
84
+ def _math_verify_match(gold: str, candidate: str) -> bool:
85
+ """Deterministic symbolic/numeric equivalence via HuggingFace Math-Verify.
86
+
87
+ Catches equivalences the naive float-parse misses: thousands separators,
88
+ fractions (3/4 == 0.75), percentages (50% == 0.5), and symbolic forms.
89
+ Fails CLOSED — any parse error / prose gold / timeout returns False (never a
90
+ false positive). No network, no LLM.
91
+ """
92
+ try:
93
+ from math_verify import parse, verify
94
+
95
+ return bool(verify(parse(gold), parse(candidate), timeout_seconds=5))
96
+ except Exception: # noqa: BLE001
97
+ return False
98
+
99
+
100
+ def _is_clean_number(s: str) -> bool:
101
+ """True iff the whole string IS a single number (allowing a leading/trailing
102
+ %, $, and thousands-commas) — e.g. '95293', '95,293', '0.5', '-3.16', '50%'.
103
+ A COMPOUND string like 'Y=3 with 95,293 instances' is NOT a clean number, so
104
+ the numeric tier must not fire on it (its `_to_float` would grab the leading
105
+ '3' and false-positive-match any answer starting with 3)."""
106
+ t = (s or "").strip().strip("%$").strip().replace(",", "")
107
+ return bool(_NUMERIC_RE.fullmatch(t))
108
+
109
+
110
+ def grade(
111
+ gold: str,
112
+ candidate: str,
113
+ *,
114
+ question: str = "",
115
+ reward_mode: str = "",
116
+ judge: bool = True, # noqa: ARG001 — kept for signature compat; LLM tier removed
117
+ judge_model: str | None = None, # noqa: ARG001
118
+ rel_tol: float = 1e-3,
119
+ abs_tol: float = 1e-3,
120
+ ) -> GradeResult:
121
+ """Deterministic three-tier match — NO LLM judge.
122
+
123
+ exact -> numeric (abs_tol/rel_tol, gated to clean-number golds) -> math_verify
124
+ -> miss. `judge`/`judge_model` accepted but ignored (LLM tier removed).
125
+ """
126
+
127
+ if not gold or candidate is None:
128
+ return GradeResult(0.0, "miss")
129
+
130
+ # ── Tier 1: exact (case-insensitive, whitespace-collapsed) ─��───────
131
+ if _normalize(gold) == _normalize(candidate):
132
+ return GradeResult(1.0, "exact")
133
+
134
+ # ── Tier 2: numeric — ONLY when the gold is a single clean number ──
135
+ # (compound golds like "Y=3 with 95,293 instances" would otherwise match on
136
+ # the leading number; those must go to exact/math_verify, which fail closed).
137
+ if reward_mode == "numeric" or _is_clean_number(gold):
138
+ g, c = _to_float(gold), _to_float(candidate)
139
+ if g is not None and c is not None:
140
+ if abs(g - c) <= abs_tol or abs(g - c) / max(abs(g), 1e-9) <= rel_tol:
141
+ return GradeResult(1.0, "numeric")
142
+
143
+ # ── Tier 3: math-verify (symbolic/numeric equivalence, deterministic) ──
144
+ if _math_verify_match(gold, candidate):
145
+ return GradeResult(1.0, "math_verify")
146
+
147
+ return GradeResult(0.0, "miss")
148
+
149
+
150
+ def _tool_calls() -> int | None:
151
+ """Number of agent tool calls this rollout, for the efficiency reward.
152
+
153
+ Written by the harness into the sandbox (`/workdir/.n_tool_calls`); falls
154
+ back to the `N_TOOL_CALLS` env var. Returns None if neither is present
155
+ (efficiency reward becomes null — the harness didn't report a count).
156
+ """
157
+ try:
158
+ with open("/workdir/.n_tool_calls") as fh:
159
+ return int(fh.read().strip())
160
+ except (OSError, ValueError):
161
+ pass
162
+ raw = os.environ.get("N_TOOL_CALLS")
163
+ if raw is not None:
164
+ try:
165
+ return int(str(raw).strip())
166
+ except ValueError:
167
+ return None
168
+ return None
169
+
170
+
171
+ def _tool_efficiency(n_calls: int | None) -> float | None:
172
+ """0..1 efficiency signal: fewer tool calls -> higher. None if unknown.
173
+
174
+ clip(1 - n_calls / TOOL_BUDGET, 0, 1). TOOL_BUDGET default 15 (solved-4B
175
+ median was ~9-10 calls). Raw signal — NOT gated on correctness here; the
176
+ RL reward combiner decides gating/weights.
177
+ """
178
+ if n_calls is None:
179
+ return None
180
+ budget = float(os.environ.get("TOOL_BUDGET", "15") or "15")
181
+ if budget <= 0:
182
+ return None
183
+ return max(0.0, min(1.0, 1.0 - n_calls / budget))
184
+
185
+
186
+ def _tols() -> tuple[float, float]:
187
+ """Per-task (abs_tol, rel_tol) from ATOL/RTOL in [verifier.env]; 1e-3 default."""
188
+ def _f(name: str) -> float:
189
+ try:
190
+ return float(os.environ.get(name, "") or 1e-3)
191
+ except ValueError:
192
+ return 1e-3
193
+ return _f("ATOL"), _f("RTOL")
194
+
195
+
196
+ def main_cli() -> int:
197
+ """CLI shim for `tests/test.sh` — env-driven, stdout-only.
198
+
199
+ Inputs (via env vars set by Harbor's [verifier.env]):
200
+ EXPECTED_ANSWER — the gold
201
+ QUESTION — the original question
202
+ ATOL / RTOL — per-task numeric tolerances (default 1e-3)
203
+
204
+ Predicted answer is read from stdin.
205
+ Single float written to stdout. Exit code is always 0.
206
+ """
207
+ gold = (os.environ.get("EXPECTED_ANSWER") or "").strip()
208
+ question = (os.environ.get("QUESTION") or "").strip()
209
+ candidate = sys.stdin.read().strip()
210
+ at, rt = _tols()
211
+ result = grade(gold, candidate, question=question, reward_mode=os.environ.get("REWARD_MODE","") or "", abs_tol=at, rel_tol=rt)
212
+ print(f"{result.reward:.1f}")
213
+ print(f"[grader] gold={gold!r} pred={candidate[:80]!r} reward={result.reward} method={result.method}",
214
+ file=sys.stderr)
215
+ return 0
216
+
217
+
218
+ def main_json() -> int:
219
+ """Multi-reward shim for `tests/test.sh` — writes a `reward.json` dict.
220
+
221
+ Three named rewards (Harbor's VerifierResult.rewards carries them all):
222
+ correctness — 1.0 iff graded answer matches gold, else 0.0
223
+ submission — 1.0 iff a non-empty answer was submitted, else 0.0
224
+ tool_efficiency — 0..1 (fewer tool calls higher); null if count unknown
225
+
226
+ No submission -> all three 0. Predicted answer on stdin; JSON to stdout.
227
+ """
228
+ import json
229
+
230
+ gold = (os.environ.get("EXPECTED_ANSWER") or "").strip()
231
+ question = (os.environ.get("QUESTION") or "").strip()
232
+ candidate = sys.stdin.read().strip()
233
+
234
+ if not candidate:
235
+ print(json.dumps({"correctness": 0.0, "submission": 0.0, "tool_efficiency": 0.0}))
236
+ print("[grader] no submission -> all rewards 0", file=sys.stderr)
237
+ return 0
238
+
239
+ at, rt = _tols()
240
+ result = grade(gold, candidate, question=question, reward_mode=os.environ.get("REWARD_MODE","") or "", abs_tol=at, rel_tol=rt)
241
+ n_calls = _tool_calls()
242
+ eff = _tool_efficiency(n_calls)
243
+ print(json.dumps({
244
+ "correctness": float(result.reward),
245
+ "submission": 1.0,
246
+ "tool_efficiency": eff,
247
+ }))
248
+ print(f"[grader] gold={gold!r} pred={candidate[:80]!r} "
249
+ f"correctness={result.reward} method={result.method} "
250
+ f"tool_calls={n_calls} tool_efficiency={eff}", file=sys.stderr)
251
+ return 0
252
+
253
+
254
+ if __name__ == "__main__":
255
+ if "--json" in sys.argv[1:]:
256
+ raise SystemExit(main_json())
257
+ raise SystemExit(main_cli())
tasks/0001_727_1727043_qa_4/tests/test.sh ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -u
3
+ mkdir -p /logs/verifier
4
+
5
+ answer_path="/workdir/answer.txt"
6
+ if [ ! -s "$answer_path" ]; then
7
+ echo "0.0" > /logs/verifier/reward.txt
8
+ echo "[grader] no answer at $answer_path" >&2
9
+ exit 0
10
+ fi
11
+
12
+ pip install --quiet math-verify >/dev/null 2>&1 || true
13
+ python3 /tests/grader.py < "$answer_path" > /logs/verifier/reward.txt
tasks/0001_735_1735855_qa_3/environment/Dockerfile ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ FROM docker.io/savatar101/env-data-agent-train:base
2
+ WORKDIR /workdir
tasks/0001_735_1735855_qa_3/environment/pull_bucket.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Pull this task's bucket prefix into /home/user/input/.
2
+
3
+ Invoked by Harbor's [environment.healthcheck] command (declared in task.toml)
4
+ — runs after container start, before the agent. Idempotent: skips work if
5
+ files are already present from a prior pull.
6
+ """
7
+
8
+ import os
9
+ import sys
10
+ from pathlib import Path
11
+
12
+ from huggingface_hub import download_bucket_files, list_bucket_tree
13
+
14
+
15
+ def main() -> int:
16
+ bucket = os.environ.get("HF_BUCKET") or "AdithyaSK/jupyter-agent-kaggle-all"
17
+ prefix = os.environ["BUCKET_PREFIX"].rstrip("/") + "/"
18
+ dest = Path("/home/user/input")
19
+ dest.mkdir(parents=True, exist_ok=True)
20
+
21
+ existing = [p for p in dest.iterdir() if p.is_file()]
22
+ if existing:
23
+ print(f"[pull_bucket] {dest}/ already has {len(existing)} file(s); skipping", flush=True)
24
+ return 0
25
+
26
+ targets = [
27
+ (it.path, str(dest / Path(it.path).name))
28
+ for it in list_bucket_tree(bucket, prefix=prefix, recursive=True)
29
+ if getattr(it, "type", None) == "file"
30
+ ]
31
+ if not targets:
32
+ print(f"[pull_bucket] FATAL: no files at hf://buckets/{bucket}/{prefix}", flush=True)
33
+ return 2
34
+
35
+ download_bucket_files(bucket, files=targets)
36
+ print(f"[pull_bucket] staged {len(targets)} file(s) from {bucket}/{prefix}", flush=True)
37
+ return 0
38
+
39
+
40
+ if __name__ == "__main__":
41
+ sys.exit(main())
tasks/0001_735_1735855_qa_3/tests/grader.py ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Shared three-tier grader.
2
+
3
+ Used by both runtimes:
4
+ * `env/server.py` — inline inside the `final_answer` ORS @tool method
5
+ * `tests/test.sh` — Harbor CLI path; this module is mounted at /tests/grader.py
6
+ and invoked with `python3 /tests/grader.py < /workdir/answer.txt`
7
+
8
+ Tiers (cheapest → most expensive):
9
+ 1. Exact (case-insensitive, whitespace-collapsed)
10
+ 2. Numeric (parse a float, accept abs/rel diff ≤ 1e-3)
11
+ 3. LLM-judge (gpt-4o-mini, A/B/C verdict, OpenAI simple-evals prompt)
12
+ — only invoked if OPENAI_API_KEY is set
13
+
14
+ CLI form (used by tests/test.sh):
15
+ EXPECTED_ANSWER='5' QUESTION='How many...' python3 grader.py
16
+ → reads predicted answer from stdin
17
+ → writes a single float ('1.0' or '0.0') to stdout
18
+ → exits 0 always; harbor reads stdout from /logs/verifier/reward.txt
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ import os
24
+ import re
25
+ import sys
26
+ from dataclasses import dataclass
27
+
28
+
29
+ _NUMERIC_RE = re.compile(r"-?\d+(?:[.,]\d+)?(?:[eE][-+]?\d+)?")
30
+
31
+ # Locked in PLAN.md §"Locked decisions" — adapted from
32
+ # https://github.com/openai/simple-evals/blob/main/simpleqa_eval.py
33
+ JUDGE_PROMPT = """You are grading short answers from a data-science agent.
34
+ Decide whether the predicted answer is semantically equivalent to the gold answer.
35
+
36
+ Rules:
37
+ - Case, punctuation, whitespace, articles ("the"), and trailing units don't matter.
38
+ - For numbers: predicted must match to the last significant figure of the gold
39
+ (gold "0.544341", predicted "0.544" -> CORRECT; "0.5" -> INCORRECT).
40
+ - Extra surrounding prose is fine if the gold value is clearly stated
41
+ (gold "5", predicted "There are 5 distinct categories" -> CORRECT).
42
+ - Common synonyms/abbreviations count (gold "Not Applicable", predicted "N/A" -> CORRECT).
43
+ - Parenthetical annotations in the gold are equivalence hints, not required
44
+ (gold "Gandalf (Ainur)", predicted "Gandalf" -> CORRECT;
45
+ gold "No (correlation coefficient = 0.02)", predicted "No" -> CORRECT).
46
+ - Percent + qualifier: if the gold is "X% in YEAR", a prediction of X or X%
47
+ is CORRECT as long as the core numeric value matches
48
+ (gold "21.334% in 2014", predicted "21.334" -> CORRECT;
49
+ gold "21.334% in 2014", predicted "21.334% in 2013" -> INCORRECT — year mismatch).
50
+ - Multi-part gold like "0.987 (XGBoost and LGBM)" — if the question asks for one
51
+ thing (e.g. "which model?"), predicting either listed value is CORRECT.
52
+ - If the predicted answer hedges without committing to the gold value -> NOT_ATTEMPTED.
53
+ - If it commits to a different value -> INCORRECT.
54
+
55
+ Question: {question}
56
+ Gold answer: {gold}
57
+ Predicted answer: {pred}
58
+
59
+ Reply with exactly one token: A (CORRECT), B (INCORRECT), or C (NOT_ATTEMPTED)."""
60
+
61
+
62
+ @dataclass
63
+ class GradeResult:
64
+ reward: float
65
+ method: str # "exact" | "numeric" | "llm" | "miss"
66
+
67
+
68
+ def _normalize(s: str) -> str:
69
+ return re.sub(r"\s+", " ", (s or "").strip().lower())
70
+
71
+
72
+ def _to_float(s: str) -> float | None:
73
+ if not s:
74
+ return None
75
+ m = _NUMERIC_RE.search(s.replace(",", ""))
76
+ if not m:
77
+ return None
78
+ try:
79
+ return float(m.group(0))
80
+ except ValueError:
81
+ return None
82
+
83
+
84
+ def _math_verify_match(gold: str, candidate: str) -> bool:
85
+ """Deterministic symbolic/numeric equivalence via HuggingFace Math-Verify.
86
+
87
+ Catches equivalences the naive float-parse misses: thousands separators,
88
+ fractions (3/4 == 0.75), percentages (50% == 0.5), and symbolic forms.
89
+ Fails CLOSED — any parse error / prose gold / timeout returns False (never a
90
+ false positive). No network, no LLM.
91
+ """
92
+ try:
93
+ from math_verify import parse, verify
94
+
95
+ return bool(verify(parse(gold), parse(candidate), timeout_seconds=5))
96
+ except Exception: # noqa: BLE001
97
+ return False
98
+
99
+
100
+ def _is_clean_number(s: str) -> bool:
101
+ """True iff the whole string IS a single number (allowing a leading/trailing
102
+ %, $, and thousands-commas) — e.g. '95293', '95,293', '0.5', '-3.16', '50%'.
103
+ A COMPOUND string like 'Y=3 with 95,293 instances' is NOT a clean number, so
104
+ the numeric tier must not fire on it (its `_to_float` would grab the leading
105
+ '3' and false-positive-match any answer starting with 3)."""
106
+ t = (s or "").strip().strip("%$").strip().replace(",", "")
107
+ return bool(_NUMERIC_RE.fullmatch(t))
108
+
109
+
110
+ def grade(
111
+ gold: str,
112
+ candidate: str,
113
+ *,
114
+ question: str = "",
115
+ reward_mode: str = "",
116
+ judge: bool = True, # noqa: ARG001 — kept for signature compat; LLM tier removed
117
+ judge_model: str | None = None, # noqa: ARG001
118
+ rel_tol: float = 1e-3,
119
+ abs_tol: float = 1e-3,
120
+ ) -> GradeResult:
121
+ """Deterministic three-tier match — NO LLM judge.
122
+
123
+ exact -> numeric (abs_tol/rel_tol, gated to clean-number golds) -> math_verify
124
+ -> miss. `judge`/`judge_model` accepted but ignored (LLM tier removed).
125
+ """
126
+
127
+ if not gold or candidate is None:
128
+ return GradeResult(0.0, "miss")
129
+
130
+ # ── Tier 1: exact (case-insensitive, whitespace-collapsed) ─��───────
131
+ if _normalize(gold) == _normalize(candidate):
132
+ return GradeResult(1.0, "exact")
133
+
134
+ # ── Tier 2: numeric — ONLY when the gold is a single clean number ──
135
+ # (compound golds like "Y=3 with 95,293 instances" would otherwise match on
136
+ # the leading number; those must go to exact/math_verify, which fail closed).
137
+ if reward_mode == "numeric" or _is_clean_number(gold):
138
+ g, c = _to_float(gold), _to_float(candidate)
139
+ if g is not None and c is not None:
140
+ if abs(g - c) <= abs_tol or abs(g - c) / max(abs(g), 1e-9) <= rel_tol:
141
+ return GradeResult(1.0, "numeric")
142
+
143
+ # ── Tier 3: math-verify (symbolic/numeric equivalence, deterministic) ──
144
+ if _math_verify_match(gold, candidate):
145
+ return GradeResult(1.0, "math_verify")
146
+
147
+ return GradeResult(0.0, "miss")
148
+
149
+
150
+ def _tool_calls() -> int | None:
151
+ """Number of agent tool calls this rollout, for the efficiency reward.
152
+
153
+ Written by the harness into the sandbox (`/workdir/.n_tool_calls`); falls
154
+ back to the `N_TOOL_CALLS` env var. Returns None if neither is present
155
+ (efficiency reward becomes null — the harness didn't report a count).
156
+ """
157
+ try:
158
+ with open("/workdir/.n_tool_calls") as fh:
159
+ return int(fh.read().strip())
160
+ except (OSError, ValueError):
161
+ pass
162
+ raw = os.environ.get("N_TOOL_CALLS")
163
+ if raw is not None:
164
+ try:
165
+ return int(str(raw).strip())
166
+ except ValueError:
167
+ return None
168
+ return None
169
+
170
+
171
+ def _tool_efficiency(n_calls: int | None) -> float | None:
172
+ """0..1 efficiency signal: fewer tool calls -> higher. None if unknown.
173
+
174
+ clip(1 - n_calls / TOOL_BUDGET, 0, 1). TOOL_BUDGET default 15 (solved-4B
175
+ median was ~9-10 calls). Raw signal — NOT gated on correctness here; the
176
+ RL reward combiner decides gating/weights.
177
+ """
178
+ if n_calls is None:
179
+ return None
180
+ budget = float(os.environ.get("TOOL_BUDGET", "15") or "15")
181
+ if budget <= 0:
182
+ return None
183
+ return max(0.0, min(1.0, 1.0 - n_calls / budget))
184
+
185
+
186
+ def _tols() -> tuple[float, float]:
187
+ """Per-task (abs_tol, rel_tol) from ATOL/RTOL in [verifier.env]; 1e-3 default."""
188
+ def _f(name: str) -> float:
189
+ try:
190
+ return float(os.environ.get(name, "") or 1e-3)
191
+ except ValueError:
192
+ return 1e-3
193
+ return _f("ATOL"), _f("RTOL")
194
+
195
+
196
+ def main_cli() -> int:
197
+ """CLI shim for `tests/test.sh` — env-driven, stdout-only.
198
+
199
+ Inputs (via env vars set by Harbor's [verifier.env]):
200
+ EXPECTED_ANSWER — the gold
201
+ QUESTION — the original question
202
+ ATOL / RTOL — per-task numeric tolerances (default 1e-3)
203
+
204
+ Predicted answer is read from stdin.
205
+ Single float written to stdout. Exit code is always 0.
206
+ """
207
+ gold = (os.environ.get("EXPECTED_ANSWER") or "").strip()
208
+ question = (os.environ.get("QUESTION") or "").strip()
209
+ candidate = sys.stdin.read().strip()
210
+ at, rt = _tols()
211
+ result = grade(gold, candidate, question=question, reward_mode=os.environ.get("REWARD_MODE","") or "", abs_tol=at, rel_tol=rt)
212
+ print(f"{result.reward:.1f}")
213
+ print(f"[grader] gold={gold!r} pred={candidate[:80]!r} reward={result.reward} method={result.method}",
214
+ file=sys.stderr)
215
+ return 0
216
+
217
+
218
+ def main_json() -> int:
219
+ """Multi-reward shim for `tests/test.sh` — writes a `reward.json` dict.
220
+
221
+ Three named rewards (Harbor's VerifierResult.rewards carries them all):
222
+ correctness — 1.0 iff graded answer matches gold, else 0.0
223
+ submission — 1.0 iff a non-empty answer was submitted, else 0.0
224
+ tool_efficiency — 0..1 (fewer tool calls higher); null if count unknown
225
+
226
+ No submission -> all three 0. Predicted answer on stdin; JSON to stdout.
227
+ """
228
+ import json
229
+
230
+ gold = (os.environ.get("EXPECTED_ANSWER") or "").strip()
231
+ question = (os.environ.get("QUESTION") or "").strip()
232
+ candidate = sys.stdin.read().strip()
233
+
234
+ if not candidate:
235
+ print(json.dumps({"correctness": 0.0, "submission": 0.0, "tool_efficiency": 0.0}))
236
+ print("[grader] no submission -> all rewards 0", file=sys.stderr)
237
+ return 0
238
+
239
+ at, rt = _tols()
240
+ result = grade(gold, candidate, question=question, reward_mode=os.environ.get("REWARD_MODE","") or "", abs_tol=at, rel_tol=rt)
241
+ n_calls = _tool_calls()
242
+ eff = _tool_efficiency(n_calls)
243
+ print(json.dumps({
244
+ "correctness": float(result.reward),
245
+ "submission": 1.0,
246
+ "tool_efficiency": eff,
247
+ }))
248
+ print(f"[grader] gold={gold!r} pred={candidate[:80]!r} "
249
+ f"correctness={result.reward} method={result.method} "
250
+ f"tool_calls={n_calls} tool_efficiency={eff}", file=sys.stderr)
251
+ return 0
252
+
253
+
254
+ if __name__ == "__main__":
255
+ if "--json" in sys.argv[1:]:
256
+ raise SystemExit(main_json())
257
+ raise SystemExit(main_cli())
tasks/0001_735_1735855_qa_3/tests/test.sh ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -u
3
+ mkdir -p /logs/verifier
4
+
5
+ answer_path="/workdir/answer.txt"
6
+ if [ ! -s "$answer_path" ]; then
7
+ echo "0.0" > /logs/verifier/reward.txt
8
+ echo "[grader] no answer at $answer_path" >&2
9
+ exit 0
10
+ fi
11
+
12
+ pip install --quiet math-verify >/dev/null 2>&1 || true
13
+ python3 /tests/grader.py < "$answer_path" > /logs/verifier/reward.txt
tasks/0002_092_2092240_qa_5/environment/Dockerfile ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ FROM docker.io/savatar101/env-data-agent-train:base
2
+ WORKDIR /workdir
tasks/0002_092_2092240_qa_5/environment/pull_bucket.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Pull this task's bucket prefix into /home/user/input/.
2
+
3
+ Invoked by Harbor's [environment.healthcheck] command (declared in task.toml)
4
+ — runs after container start, before the agent. Idempotent: skips work if
5
+ files are already present from a prior pull.
6
+ """
7
+
8
+ import os
9
+ import sys
10
+ from pathlib import Path
11
+
12
+ from huggingface_hub import download_bucket_files, list_bucket_tree
13
+
14
+
15
+ def main() -> int:
16
+ bucket = os.environ.get("HF_BUCKET") or "AdithyaSK/jupyter-agent-kaggle-all"
17
+ prefix = os.environ["BUCKET_PREFIX"].rstrip("/") + "/"
18
+ dest = Path("/home/user/input")
19
+ dest.mkdir(parents=True, exist_ok=True)
20
+
21
+ existing = [p for p in dest.iterdir() if p.is_file()]
22
+ if existing:
23
+ print(f"[pull_bucket] {dest}/ already has {len(existing)} file(s); skipping", flush=True)
24
+ return 0
25
+
26
+ targets = [
27
+ (it.path, str(dest / Path(it.path).name))
28
+ for it in list_bucket_tree(bucket, prefix=prefix, recursive=True)
29
+ if getattr(it, "type", None) == "file"
30
+ ]
31
+ if not targets:
32
+ print(f"[pull_bucket] FATAL: no files at hf://buckets/{bucket}/{prefix}", flush=True)
33
+ return 2
34
+
35
+ download_bucket_files(bucket, files=targets)
36
+ print(f"[pull_bucket] staged {len(targets)} file(s) from {bucket}/{prefix}", flush=True)
37
+ return 0
38
+
39
+
40
+ if __name__ == "__main__":
41
+ sys.exit(main())
tasks/0002_092_2092240_qa_5/tests/grader.py ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Shared three-tier grader.
2
+
3
+ Used by both runtimes:
4
+ * `env/server.py` — inline inside the `final_answer` ORS @tool method
5
+ * `tests/test.sh` — Harbor CLI path; this module is mounted at /tests/grader.py
6
+ and invoked with `python3 /tests/grader.py < /workdir/answer.txt`
7
+
8
+ Tiers (cheapest → most expensive):
9
+ 1. Exact (case-insensitive, whitespace-collapsed)
10
+ 2. Numeric (parse a float, accept abs/rel diff ≤ 1e-3)
11
+ 3. LLM-judge (gpt-4o-mini, A/B/C verdict, OpenAI simple-evals prompt)
12
+ — only invoked if OPENAI_API_KEY is set
13
+
14
+ CLI form (used by tests/test.sh):
15
+ EXPECTED_ANSWER='5' QUESTION='How many...' python3 grader.py
16
+ → reads predicted answer from stdin
17
+ → writes a single float ('1.0' or '0.0') to stdout
18
+ → exits 0 always; harbor reads stdout from /logs/verifier/reward.txt
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ import os
24
+ import re
25
+ import sys
26
+ from dataclasses import dataclass
27
+
28
+
29
+ _NUMERIC_RE = re.compile(r"-?\d+(?:[.,]\d+)?(?:[eE][-+]?\d+)?")
30
+
31
+ # Locked in PLAN.md §"Locked decisions" — adapted from
32
+ # https://github.com/openai/simple-evals/blob/main/simpleqa_eval.py
33
+ JUDGE_PROMPT = """You are grading short answers from a data-science agent.
34
+ Decide whether the predicted answer is semantically equivalent to the gold answer.
35
+
36
+ Rules:
37
+ - Case, punctuation, whitespace, articles ("the"), and trailing units don't matter.
38
+ - For numbers: predicted must match to the last significant figure of the gold
39
+ (gold "0.544341", predicted "0.544" -> CORRECT; "0.5" -> INCORRECT).
40
+ - Extra surrounding prose is fine if the gold value is clearly stated
41
+ (gold "5", predicted "There are 5 distinct categories" -> CORRECT).
42
+ - Common synonyms/abbreviations count (gold "Not Applicable", predicted "N/A" -> CORRECT).
43
+ - Parenthetical annotations in the gold are equivalence hints, not required
44
+ (gold "Gandalf (Ainur)", predicted "Gandalf" -> CORRECT;
45
+ gold "No (correlation coefficient = 0.02)", predicted "No" -> CORRECT).
46
+ - Percent + qualifier: if the gold is "X% in YEAR", a prediction of X or X%
47
+ is CORRECT as long as the core numeric value matches
48
+ (gold "21.334% in 2014", predicted "21.334" -> CORRECT;
49
+ gold "21.334% in 2014", predicted "21.334% in 2013" -> INCORRECT — year mismatch).
50
+ - Multi-part gold like "0.987 (XGBoost and LGBM)" — if the question asks for one
51
+ thing (e.g. "which model?"), predicting either listed value is CORRECT.
52
+ - If the predicted answer hedges without committing to the gold value -> NOT_ATTEMPTED.
53
+ - If it commits to a different value -> INCORRECT.
54
+
55
+ Question: {question}
56
+ Gold answer: {gold}
57
+ Predicted answer: {pred}
58
+
59
+ Reply with exactly one token: A (CORRECT), B (INCORRECT), or C (NOT_ATTEMPTED)."""
60
+
61
+
62
+ @dataclass
63
+ class GradeResult:
64
+ reward: float
65
+ method: str # "exact" | "numeric" | "llm" | "miss"
66
+
67
+
68
+ def _normalize(s: str) -> str:
69
+ return re.sub(r"\s+", " ", (s or "").strip().lower())
70
+
71
+
72
+ def _to_float(s: str) -> float | None:
73
+ if not s:
74
+ return None
75
+ m = _NUMERIC_RE.search(s.replace(",", ""))
76
+ if not m:
77
+ return None
78
+ try:
79
+ return float(m.group(0))
80
+ except ValueError:
81
+ return None
82
+
83
+
84
+ def _math_verify_match(gold: str, candidate: str) -> bool:
85
+ """Deterministic symbolic/numeric equivalence via HuggingFace Math-Verify.
86
+
87
+ Catches equivalences the naive float-parse misses: thousands separators,
88
+ fractions (3/4 == 0.75), percentages (50% == 0.5), and symbolic forms.
89
+ Fails CLOSED — any parse error / prose gold / timeout returns False (never a
90
+ false positive). No network, no LLM.
91
+ """
92
+ try:
93
+ from math_verify import parse, verify
94
+
95
+ return bool(verify(parse(gold), parse(candidate), timeout_seconds=5))
96
+ except Exception: # noqa: BLE001
97
+ return False
98
+
99
+
100
+ def _is_clean_number(s: str) -> bool:
101
+ """True iff the whole string IS a single number (allowing a leading/trailing
102
+ %, $, and thousands-commas) — e.g. '95293', '95,293', '0.5', '-3.16', '50%'.
103
+ A COMPOUND string like 'Y=3 with 95,293 instances' is NOT a clean number, so
104
+ the numeric tier must not fire on it (its `_to_float` would grab the leading
105
+ '3' and false-positive-match any answer starting with 3)."""
106
+ t = (s or "").strip().strip("%$").strip().replace(",", "")
107
+ return bool(_NUMERIC_RE.fullmatch(t))
108
+
109
+
110
+ def grade(
111
+ gold: str,
112
+ candidate: str,
113
+ *,
114
+ question: str = "",
115
+ reward_mode: str = "",
116
+ judge: bool = True, # noqa: ARG001 — kept for signature compat; LLM tier removed
117
+ judge_model: str | None = None, # noqa: ARG001
118
+ rel_tol: float = 1e-3,
119
+ abs_tol: float = 1e-3,
120
+ ) -> GradeResult:
121
+ """Deterministic three-tier match — NO LLM judge.
122
+
123
+ exact -> numeric (abs_tol/rel_tol, gated to clean-number golds) -> math_verify
124
+ -> miss. `judge`/`judge_model` accepted but ignored (LLM tier removed).
125
+ """
126
+
127
+ if not gold or candidate is None:
128
+ return GradeResult(0.0, "miss")
129
+
130
+ # ── Tier 1: exact (case-insensitive, whitespace-collapsed) ─��───────
131
+ if _normalize(gold) == _normalize(candidate):
132
+ return GradeResult(1.0, "exact")
133
+
134
+ # ── Tier 2: numeric — ONLY when the gold is a single clean number ──
135
+ # (compound golds like "Y=3 with 95,293 instances" would otherwise match on
136
+ # the leading number; those must go to exact/math_verify, which fail closed).
137
+ if reward_mode == "numeric" or _is_clean_number(gold):
138
+ g, c = _to_float(gold), _to_float(candidate)
139
+ if g is not None and c is not None:
140
+ if abs(g - c) <= abs_tol or abs(g - c) / max(abs(g), 1e-9) <= rel_tol:
141
+ return GradeResult(1.0, "numeric")
142
+
143
+ # ── Tier 3: math-verify (symbolic/numeric equivalence, deterministic) ──
144
+ if _math_verify_match(gold, candidate):
145
+ return GradeResult(1.0, "math_verify")
146
+
147
+ return GradeResult(0.0, "miss")
148
+
149
+
150
+ def _tool_calls() -> int | None:
151
+ """Number of agent tool calls this rollout, for the efficiency reward.
152
+
153
+ Written by the harness into the sandbox (`/workdir/.n_tool_calls`); falls
154
+ back to the `N_TOOL_CALLS` env var. Returns None if neither is present
155
+ (efficiency reward becomes null — the harness didn't report a count).
156
+ """
157
+ try:
158
+ with open("/workdir/.n_tool_calls") as fh:
159
+ return int(fh.read().strip())
160
+ except (OSError, ValueError):
161
+ pass
162
+ raw = os.environ.get("N_TOOL_CALLS")
163
+ if raw is not None:
164
+ try:
165
+ return int(str(raw).strip())
166
+ except ValueError:
167
+ return None
168
+ return None
169
+
170
+
171
+ def _tool_efficiency(n_calls: int | None) -> float | None:
172
+ """0..1 efficiency signal: fewer tool calls -> higher. None if unknown.
173
+
174
+ clip(1 - n_calls / TOOL_BUDGET, 0, 1). TOOL_BUDGET default 15 (solved-4B
175
+ median was ~9-10 calls). Raw signal — NOT gated on correctness here; the
176
+ RL reward combiner decides gating/weights.
177
+ """
178
+ if n_calls is None:
179
+ return None
180
+ budget = float(os.environ.get("TOOL_BUDGET", "15") or "15")
181
+ if budget <= 0:
182
+ return None
183
+ return max(0.0, min(1.0, 1.0 - n_calls / budget))
184
+
185
+
186
+ def _tols() -> tuple[float, float]:
187
+ """Per-task (abs_tol, rel_tol) from ATOL/RTOL in [verifier.env]; 1e-3 default."""
188
+ def _f(name: str) -> float:
189
+ try:
190
+ return float(os.environ.get(name, "") or 1e-3)
191
+ except ValueError:
192
+ return 1e-3
193
+ return _f("ATOL"), _f("RTOL")
194
+
195
+
196
+ def main_cli() -> int:
197
+ """CLI shim for `tests/test.sh` — env-driven, stdout-only.
198
+
199
+ Inputs (via env vars set by Harbor's [verifier.env]):
200
+ EXPECTED_ANSWER — the gold
201
+ QUESTION — the original question
202
+ ATOL / RTOL — per-task numeric tolerances (default 1e-3)
203
+
204
+ Predicted answer is read from stdin.
205
+ Single float written to stdout. Exit code is always 0.
206
+ """
207
+ gold = (os.environ.get("EXPECTED_ANSWER") or "").strip()
208
+ question = (os.environ.get("QUESTION") or "").strip()
209
+ candidate = sys.stdin.read().strip()
210
+ at, rt = _tols()
211
+ result = grade(gold, candidate, question=question, reward_mode=os.environ.get("REWARD_MODE","") or "", abs_tol=at, rel_tol=rt)
212
+ print(f"{result.reward:.1f}")
213
+ print(f"[grader] gold={gold!r} pred={candidate[:80]!r} reward={result.reward} method={result.method}",
214
+ file=sys.stderr)
215
+ return 0
216
+
217
+
218
+ def main_json() -> int:
219
+ """Multi-reward shim for `tests/test.sh` — writes a `reward.json` dict.
220
+
221
+ Three named rewards (Harbor's VerifierResult.rewards carries them all):
222
+ correctness — 1.0 iff graded answer matches gold, else 0.0
223
+ submission — 1.0 iff a non-empty answer was submitted, else 0.0
224
+ tool_efficiency — 0..1 (fewer tool calls higher); null if count unknown
225
+
226
+ No submission -> all three 0. Predicted answer on stdin; JSON to stdout.
227
+ """
228
+ import json
229
+
230
+ gold = (os.environ.get("EXPECTED_ANSWER") or "").strip()
231
+ question = (os.environ.get("QUESTION") or "").strip()
232
+ candidate = sys.stdin.read().strip()
233
+
234
+ if not candidate:
235
+ print(json.dumps({"correctness": 0.0, "submission": 0.0, "tool_efficiency": 0.0}))
236
+ print("[grader] no submission -> all rewards 0", file=sys.stderr)
237
+ return 0
238
+
239
+ at, rt = _tols()
240
+ result = grade(gold, candidate, question=question, reward_mode=os.environ.get("REWARD_MODE","") or "", abs_tol=at, rel_tol=rt)
241
+ n_calls = _tool_calls()
242
+ eff = _tool_efficiency(n_calls)
243
+ print(json.dumps({
244
+ "correctness": float(result.reward),
245
+ "submission": 1.0,
246
+ "tool_efficiency": eff,
247
+ }))
248
+ print(f"[grader] gold={gold!r} pred={candidate[:80]!r} "
249
+ f"correctness={result.reward} method={result.method} "
250
+ f"tool_calls={n_calls} tool_efficiency={eff}", file=sys.stderr)
251
+ return 0
252
+
253
+
254
+ if __name__ == "__main__":
255
+ if "--json" in sys.argv[1:]:
256
+ raise SystemExit(main_json())
257
+ raise SystemExit(main_cli())
tasks/0002_092_2092240_qa_5/tests/test.sh ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -u
3
+ mkdir -p /logs/verifier
4
+
5
+ answer_path="/workdir/answer.txt"
6
+ if [ ! -s "$answer_path" ]; then
7
+ echo "0.0" > /logs/verifier/reward.txt
8
+ echo "[grader] no answer at $answer_path" >&2
9
+ exit 0
10
+ fi
11
+
12
+ pip install --quiet math-verify >/dev/null 2>&1 || true
13
+ python3 /tests/grader.py < "$answer_path" > /logs/verifier/reward.txt
tasks/0021_135_21135636_qa_3/environment/Dockerfile ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ FROM docker.io/savatar101/env-data-agent-train:base
2
+ WORKDIR /workdir
tasks/0021_135_21135636_qa_3/environment/pull_bucket.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Pull this task's bucket prefix into /home/user/input/.
2
+
3
+ Invoked by Harbor's [environment.healthcheck] command (declared in task.toml)
4
+ — runs after container start, before the agent. Idempotent: skips work if
5
+ files are already present from a prior pull.
6
+ """
7
+
8
+ import os
9
+ import sys
10
+ from pathlib import Path
11
+
12
+ from huggingface_hub import download_bucket_files, list_bucket_tree
13
+
14
+
15
+ def main() -> int:
16
+ bucket = os.environ.get("HF_BUCKET") or "AdithyaSK/jupyter-agent-kaggle-all"
17
+ prefix = os.environ["BUCKET_PREFIX"].rstrip("/") + "/"
18
+ dest = Path("/home/user/input")
19
+ dest.mkdir(parents=True, exist_ok=True)
20
+
21
+ existing = [p for p in dest.iterdir() if p.is_file()]
22
+ if existing:
23
+ print(f"[pull_bucket] {dest}/ already has {len(existing)} file(s); skipping", flush=True)
24
+ return 0
25
+
26
+ targets = [
27
+ (it.path, str(dest / Path(it.path).name))
28
+ for it in list_bucket_tree(bucket, prefix=prefix, recursive=True)
29
+ if getattr(it, "type", None) == "file"
30
+ ]
31
+ if not targets:
32
+ print(f"[pull_bucket] FATAL: no files at hf://buckets/{bucket}/{prefix}", flush=True)
33
+ return 2
34
+
35
+ download_bucket_files(bucket, files=targets)
36
+ print(f"[pull_bucket] staged {len(targets)} file(s) from {bucket}/{prefix}", flush=True)
37
+ return 0
38
+
39
+
40
+ if __name__ == "__main__":
41
+ sys.exit(main())
tasks/0021_135_21135636_qa_3/tests/grader.py ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Shared three-tier grader.
2
+
3
+ Used by both runtimes:
4
+ * `env/server.py` — inline inside the `final_answer` ORS @tool method
5
+ * `tests/test.sh` — Harbor CLI path; this module is mounted at /tests/grader.py
6
+ and invoked with `python3 /tests/grader.py < /workdir/answer.txt`
7
+
8
+ Tiers (cheapest → most expensive):
9
+ 1. Exact (case-insensitive, whitespace-collapsed)
10
+ 2. Numeric (parse a float, accept abs/rel diff ≤ 1e-3)
11
+ 3. LLM-judge (gpt-4o-mini, A/B/C verdict, OpenAI simple-evals prompt)
12
+ — only invoked if OPENAI_API_KEY is set
13
+
14
+ CLI form (used by tests/test.sh):
15
+ EXPECTED_ANSWER='5' QUESTION='How many...' python3 grader.py
16
+ → reads predicted answer from stdin
17
+ → writes a single float ('1.0' or '0.0') to stdout
18
+ → exits 0 always; harbor reads stdout from /logs/verifier/reward.txt
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ import os
24
+ import re
25
+ import sys
26
+ from dataclasses import dataclass
27
+
28
+
29
+ _NUMERIC_RE = re.compile(r"-?\d+(?:[.,]\d+)?(?:[eE][-+]?\d+)?")
30
+
31
+ # Locked in PLAN.md §"Locked decisions" — adapted from
32
+ # https://github.com/openai/simple-evals/blob/main/simpleqa_eval.py
33
+ JUDGE_PROMPT = """You are grading short answers from a data-science agent.
34
+ Decide whether the predicted answer is semantically equivalent to the gold answer.
35
+
36
+ Rules:
37
+ - Case, punctuation, whitespace, articles ("the"), and trailing units don't matter.
38
+ - For numbers: predicted must match to the last significant figure of the gold
39
+ (gold "0.544341", predicted "0.544" -> CORRECT; "0.5" -> INCORRECT).
40
+ - Extra surrounding prose is fine if the gold value is clearly stated
41
+ (gold "5", predicted "There are 5 distinct categories" -> CORRECT).
42
+ - Common synonyms/abbreviations count (gold "Not Applicable", predicted "N/A" -> CORRECT).
43
+ - Parenthetical annotations in the gold are equivalence hints, not required
44
+ (gold "Gandalf (Ainur)", predicted "Gandalf" -> CORRECT;
45
+ gold "No (correlation coefficient = 0.02)", predicted "No" -> CORRECT).
46
+ - Percent + qualifier: if the gold is "X% in YEAR", a prediction of X or X%
47
+ is CORRECT as long as the core numeric value matches
48
+ (gold "21.334% in 2014", predicted "21.334" -> CORRECT;
49
+ gold "21.334% in 2014", predicted "21.334% in 2013" -> INCORRECT — year mismatch).
50
+ - Multi-part gold like "0.987 (XGBoost and LGBM)" — if the question asks for one
51
+ thing (e.g. "which model?"), predicting either listed value is CORRECT.
52
+ - If the predicted answer hedges without committing to the gold value -> NOT_ATTEMPTED.
53
+ - If it commits to a different value -> INCORRECT.
54
+
55
+ Question: {question}
56
+ Gold answer: {gold}
57
+ Predicted answer: {pred}
58
+
59
+ Reply with exactly one token: A (CORRECT), B (INCORRECT), or C (NOT_ATTEMPTED)."""
60
+
61
+
62
+ @dataclass
63
+ class GradeResult:
64
+ reward: float
65
+ method: str # "exact" | "numeric" | "llm" | "miss"
66
+
67
+
68
+ def _normalize(s: str) -> str:
69
+ return re.sub(r"\s+", " ", (s or "").strip().lower())
70
+
71
+
72
+ def _to_float(s: str) -> float | None:
73
+ if not s:
74
+ return None
75
+ m = _NUMERIC_RE.search(s.replace(",", ""))
76
+ if not m:
77
+ return None
78
+ try:
79
+ return float(m.group(0))
80
+ except ValueError:
81
+ return None
82
+
83
+
84
+ def _math_verify_match(gold: str, candidate: str) -> bool:
85
+ """Deterministic symbolic/numeric equivalence via HuggingFace Math-Verify.
86
+
87
+ Catches equivalences the naive float-parse misses: thousands separators,
88
+ fractions (3/4 == 0.75), percentages (50% == 0.5), and symbolic forms.
89
+ Fails CLOSED — any parse error / prose gold / timeout returns False (never a
90
+ false positive). No network, no LLM.
91
+ """
92
+ try:
93
+ from math_verify import parse, verify
94
+
95
+ return bool(verify(parse(gold), parse(candidate), timeout_seconds=5))
96
+ except Exception: # noqa: BLE001
97
+ return False
98
+
99
+
100
+ def _is_clean_number(s: str) -> bool:
101
+ """True iff the whole string IS a single number (allowing a leading/trailing
102
+ %, $, and thousands-commas) — e.g. '95293', '95,293', '0.5', '-3.16', '50%'.
103
+ A COMPOUND string like 'Y=3 with 95,293 instances' is NOT a clean number, so
104
+ the numeric tier must not fire on it (its `_to_float` would grab the leading
105
+ '3' and false-positive-match any answer starting with 3)."""
106
+ t = (s or "").strip().strip("%$").strip().replace(",", "")
107
+ return bool(_NUMERIC_RE.fullmatch(t))
108
+
109
+
110
+ def grade(
111
+ gold: str,
112
+ candidate: str,
113
+ *,
114
+ question: str = "",
115
+ reward_mode: str = "",
116
+ judge: bool = True, # noqa: ARG001 — kept for signature compat; LLM tier removed
117
+ judge_model: str | None = None, # noqa: ARG001
118
+ rel_tol: float = 1e-3,
119
+ abs_tol: float = 1e-3,
120
+ ) -> GradeResult:
121
+ """Deterministic three-tier match — NO LLM judge.
122
+
123
+ exact -> numeric (abs_tol/rel_tol, gated to clean-number golds) -> math_verify
124
+ -> miss. `judge`/`judge_model` accepted but ignored (LLM tier removed).
125
+ """
126
+
127
+ if not gold or candidate is None:
128
+ return GradeResult(0.0, "miss")
129
+
130
+ # ── Tier 1: exact (case-insensitive, whitespace-collapsed) ─��───────
131
+ if _normalize(gold) == _normalize(candidate):
132
+ return GradeResult(1.0, "exact")
133
+
134
+ # ── Tier 2: numeric — ONLY when the gold is a single clean number ──
135
+ # (compound golds like "Y=3 with 95,293 instances" would otherwise match on
136
+ # the leading number; those must go to exact/math_verify, which fail closed).
137
+ if reward_mode == "numeric" or _is_clean_number(gold):
138
+ g, c = _to_float(gold), _to_float(candidate)
139
+ if g is not None and c is not None:
140
+ if abs(g - c) <= abs_tol or abs(g - c) / max(abs(g), 1e-9) <= rel_tol:
141
+ return GradeResult(1.0, "numeric")
142
+
143
+ # ── Tier 3: math-verify (symbolic/numeric equivalence, deterministic) ──
144
+ if _math_verify_match(gold, candidate):
145
+ return GradeResult(1.0, "math_verify")
146
+
147
+ return GradeResult(0.0, "miss")
148
+
149
+
150
+ def _tool_calls() -> int | None:
151
+ """Number of agent tool calls this rollout, for the efficiency reward.
152
+
153
+ Written by the harness into the sandbox (`/workdir/.n_tool_calls`); falls
154
+ back to the `N_TOOL_CALLS` env var. Returns None if neither is present
155
+ (efficiency reward becomes null — the harness didn't report a count).
156
+ """
157
+ try:
158
+ with open("/workdir/.n_tool_calls") as fh:
159
+ return int(fh.read().strip())
160
+ except (OSError, ValueError):
161
+ pass
162
+ raw = os.environ.get("N_TOOL_CALLS")
163
+ if raw is not None:
164
+ try:
165
+ return int(str(raw).strip())
166
+ except ValueError:
167
+ return None
168
+ return None
169
+
170
+
171
+ def _tool_efficiency(n_calls: int | None) -> float | None:
172
+ """0..1 efficiency signal: fewer tool calls -> higher. None if unknown.
173
+
174
+ clip(1 - n_calls / TOOL_BUDGET, 0, 1). TOOL_BUDGET default 15 (solved-4B
175
+ median was ~9-10 calls). Raw signal — NOT gated on correctness here; the
176
+ RL reward combiner decides gating/weights.
177
+ """
178
+ if n_calls is None:
179
+ return None
180
+ budget = float(os.environ.get("TOOL_BUDGET", "15") or "15")
181
+ if budget <= 0:
182
+ return None
183
+ return max(0.0, min(1.0, 1.0 - n_calls / budget))
184
+
185
+
186
+ def _tols() -> tuple[float, float]:
187
+ """Per-task (abs_tol, rel_tol) from ATOL/RTOL in [verifier.env]; 1e-3 default."""
188
+ def _f(name: str) -> float:
189
+ try:
190
+ return float(os.environ.get(name, "") or 1e-3)
191
+ except ValueError:
192
+ return 1e-3
193
+ return _f("ATOL"), _f("RTOL")
194
+
195
+
196
+ def main_cli() -> int:
197
+ """CLI shim for `tests/test.sh` — env-driven, stdout-only.
198
+
199
+ Inputs (via env vars set by Harbor's [verifier.env]):
200
+ EXPECTED_ANSWER — the gold
201
+ QUESTION — the original question
202
+ ATOL / RTOL — per-task numeric tolerances (default 1e-3)
203
+
204
+ Predicted answer is read from stdin.
205
+ Single float written to stdout. Exit code is always 0.
206
+ """
207
+ gold = (os.environ.get("EXPECTED_ANSWER") or "").strip()
208
+ question = (os.environ.get("QUESTION") or "").strip()
209
+ candidate = sys.stdin.read().strip()
210
+ at, rt = _tols()
211
+ result = grade(gold, candidate, question=question, reward_mode=os.environ.get("REWARD_MODE","") or "", abs_tol=at, rel_tol=rt)
212
+ print(f"{result.reward:.1f}")
213
+ print(f"[grader] gold={gold!r} pred={candidate[:80]!r} reward={result.reward} method={result.method}",
214
+ file=sys.stderr)
215
+ return 0
216
+
217
+
218
+ def main_json() -> int:
219
+ """Multi-reward shim for `tests/test.sh` — writes a `reward.json` dict.
220
+
221
+ Three named rewards (Harbor's VerifierResult.rewards carries them all):
222
+ correctness — 1.0 iff graded answer matches gold, else 0.0
223
+ submission — 1.0 iff a non-empty answer was submitted, else 0.0
224
+ tool_efficiency — 0..1 (fewer tool calls higher); null if count unknown
225
+
226
+ No submission -> all three 0. Predicted answer on stdin; JSON to stdout.
227
+ """
228
+ import json
229
+
230
+ gold = (os.environ.get("EXPECTED_ANSWER") or "").strip()
231
+ question = (os.environ.get("QUESTION") or "").strip()
232
+ candidate = sys.stdin.read().strip()
233
+
234
+ if not candidate:
235
+ print(json.dumps({"correctness": 0.0, "submission": 0.0, "tool_efficiency": 0.0}))
236
+ print("[grader] no submission -> all rewards 0", file=sys.stderr)
237
+ return 0
238
+
239
+ at, rt = _tols()
240
+ result = grade(gold, candidate, question=question, reward_mode=os.environ.get("REWARD_MODE","") or "", abs_tol=at, rel_tol=rt)
241
+ n_calls = _tool_calls()
242
+ eff = _tool_efficiency(n_calls)
243
+ print(json.dumps({
244
+ "correctness": float(result.reward),
245
+ "submission": 1.0,
246
+ "tool_efficiency": eff,
247
+ }))
248
+ print(f"[grader] gold={gold!r} pred={candidate[:80]!r} "
249
+ f"correctness={result.reward} method={result.method} "
250
+ f"tool_calls={n_calls} tool_efficiency={eff}", file=sys.stderr)
251
+ return 0
252
+
253
+
254
+ if __name__ == "__main__":
255
+ if "--json" in sys.argv[1:]:
256
+ raise SystemExit(main_json())
257
+ raise SystemExit(main_cli())
tasks/0021_135_21135636_qa_3/tests/test.sh ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -u
3
+ mkdir -p /logs/verifier
4
+
5
+ answer_path="/workdir/answer.txt"
6
+ if [ ! -s "$answer_path" ]; then
7
+ echo "0.0" > /logs/verifier/reward.txt
8
+ echo "[grader] no answer at $answer_path" >&2
9
+ exit 0
10
+ fi
11
+
12
+ pip install --quiet math-verify >/dev/null 2>&1 || true
13
+ python3 /tests/grader.py < "$answer_path" > /logs/verifier/reward.txt
tasks/0021_656_21656365_qa_5/environment/Dockerfile ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ FROM docker.io/savatar101/env-data-agent-train:base
2
+ WORKDIR /workdir
tasks/0021_656_21656365_qa_5/environment/pull_bucket.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Pull this task's bucket prefix into /home/user/input/.
2
+
3
+ Invoked by Harbor's [environment.healthcheck] command (declared in task.toml)
4
+ — runs after container start, before the agent. Idempotent: skips work if
5
+ files are already present from a prior pull.
6
+ """
7
+
8
+ import os
9
+ import sys
10
+ from pathlib import Path
11
+
12
+ from huggingface_hub import download_bucket_files, list_bucket_tree
13
+
14
+
15
+ def main() -> int:
16
+ bucket = os.environ.get("HF_BUCKET") or "AdithyaSK/jupyter-agent-kaggle-all"
17
+ prefix = os.environ["BUCKET_PREFIX"].rstrip("/") + "/"
18
+ dest = Path("/home/user/input")
19
+ dest.mkdir(parents=True, exist_ok=True)
20
+
21
+ existing = [p for p in dest.iterdir() if p.is_file()]
22
+ if existing:
23
+ print(f"[pull_bucket] {dest}/ already has {len(existing)} file(s); skipping", flush=True)
24
+ return 0
25
+
26
+ targets = [
27
+ (it.path, str(dest / Path(it.path).name))
28
+ for it in list_bucket_tree(bucket, prefix=prefix, recursive=True)
29
+ if getattr(it, "type", None) == "file"
30
+ ]
31
+ if not targets:
32
+ print(f"[pull_bucket] FATAL: no files at hf://buckets/{bucket}/{prefix}", flush=True)
33
+ return 2
34
+
35
+ download_bucket_files(bucket, files=targets)
36
+ print(f"[pull_bucket] staged {len(targets)} file(s) from {bucket}/{prefix}", flush=True)
37
+ return 0
38
+
39
+
40
+ if __name__ == "__main__":
41
+ sys.exit(main())
tasks/0021_656_21656365_qa_5/tests/grader.py ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Shared three-tier grader.
2
+
3
+ Used by both runtimes:
4
+ * `env/server.py` — inline inside the `final_answer` ORS @tool method
5
+ * `tests/test.sh` — Harbor CLI path; this module is mounted at /tests/grader.py
6
+ and invoked with `python3 /tests/grader.py < /workdir/answer.txt`
7
+
8
+ Tiers (cheapest → most expensive):
9
+ 1. Exact (case-insensitive, whitespace-collapsed)
10
+ 2. Numeric (parse a float, accept abs/rel diff ≤ 1e-3)
11
+ 3. LLM-judge (gpt-4o-mini, A/B/C verdict, OpenAI simple-evals prompt)
12
+ — only invoked if OPENAI_API_KEY is set
13
+
14
+ CLI form (used by tests/test.sh):
15
+ EXPECTED_ANSWER='5' QUESTION='How many...' python3 grader.py
16
+ → reads predicted answer from stdin
17
+ → writes a single float ('1.0' or '0.0') to stdout
18
+ → exits 0 always; harbor reads stdout from /logs/verifier/reward.txt
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ import os
24
+ import re
25
+ import sys
26
+ from dataclasses import dataclass
27
+
28
+
29
+ _NUMERIC_RE = re.compile(r"-?\d+(?:[.,]\d+)?(?:[eE][-+]?\d+)?")
30
+
31
+ # Locked in PLAN.md §"Locked decisions" — adapted from
32
+ # https://github.com/openai/simple-evals/blob/main/simpleqa_eval.py
33
+ JUDGE_PROMPT = """You are grading short answers from a data-science agent.
34
+ Decide whether the predicted answer is semantically equivalent to the gold answer.
35
+
36
+ Rules:
37
+ - Case, punctuation, whitespace, articles ("the"), and trailing units don't matter.
38
+ - For numbers: predicted must match to the last significant figure of the gold
39
+ (gold "0.544341", predicted "0.544" -> CORRECT; "0.5" -> INCORRECT).
40
+ - Extra surrounding prose is fine if the gold value is clearly stated
41
+ (gold "5", predicted "There are 5 distinct categories" -> CORRECT).
42
+ - Common synonyms/abbreviations count (gold "Not Applicable", predicted "N/A" -> CORRECT).
43
+ - Parenthetical annotations in the gold are equivalence hints, not required
44
+ (gold "Gandalf (Ainur)", predicted "Gandalf" -> CORRECT;
45
+ gold "No (correlation coefficient = 0.02)", predicted "No" -> CORRECT).
46
+ - Percent + qualifier: if the gold is "X% in YEAR", a prediction of X or X%
47
+ is CORRECT as long as the core numeric value matches
48
+ (gold "21.334% in 2014", predicted "21.334" -> CORRECT;
49
+ gold "21.334% in 2014", predicted "21.334% in 2013" -> INCORRECT — year mismatch).
50
+ - Multi-part gold like "0.987 (XGBoost and LGBM)" — if the question asks for one
51
+ thing (e.g. "which model?"), predicting either listed value is CORRECT.
52
+ - If the predicted answer hedges without committing to the gold value -> NOT_ATTEMPTED.
53
+ - If it commits to a different value -> INCORRECT.
54
+
55
+ Question: {question}
56
+ Gold answer: {gold}
57
+ Predicted answer: {pred}
58
+
59
+ Reply with exactly one token: A (CORRECT), B (INCORRECT), or C (NOT_ATTEMPTED)."""
60
+
61
+
62
+ @dataclass
63
+ class GradeResult:
64
+ reward: float
65
+ method: str # "exact" | "numeric" | "llm" | "miss"
66
+
67
+
68
+ def _normalize(s: str) -> str:
69
+ return re.sub(r"\s+", " ", (s or "").strip().lower())
70
+
71
+
72
+ def _to_float(s: str) -> float | None:
73
+ if not s:
74
+ return None
75
+ m = _NUMERIC_RE.search(s.replace(",", ""))
76
+ if not m:
77
+ return None
78
+ try:
79
+ return float(m.group(0))
80
+ except ValueError:
81
+ return None
82
+
83
+
84
+ def _math_verify_match(gold: str, candidate: str) -> bool:
85
+ """Deterministic symbolic/numeric equivalence via HuggingFace Math-Verify.
86
+
87
+ Catches equivalences the naive float-parse misses: thousands separators,
88
+ fractions (3/4 == 0.75), percentages (50% == 0.5), and symbolic forms.
89
+ Fails CLOSED — any parse error / prose gold / timeout returns False (never a
90
+ false positive). No network, no LLM.
91
+ """
92
+ try:
93
+ from math_verify import parse, verify
94
+
95
+ return bool(verify(parse(gold), parse(candidate), timeout_seconds=5))
96
+ except Exception: # noqa: BLE001
97
+ return False
98
+
99
+
100
+ def _is_clean_number(s: str) -> bool:
101
+ """True iff the whole string IS a single number (allowing a leading/trailing
102
+ %, $, and thousands-commas) — e.g. '95293', '95,293', '0.5', '-3.16', '50%'.
103
+ A COMPOUND string like 'Y=3 with 95,293 instances' is NOT a clean number, so
104
+ the numeric tier must not fire on it (its `_to_float` would grab the leading
105
+ '3' and false-positive-match any answer starting with 3)."""
106
+ t = (s or "").strip().strip("%$").strip().replace(",", "")
107
+ return bool(_NUMERIC_RE.fullmatch(t))
108
+
109
+
110
+ def grade(
111
+ gold: str,
112
+ candidate: str,
113
+ *,
114
+ question: str = "",
115
+ reward_mode: str = "",
116
+ judge: bool = True, # noqa: ARG001 — kept for signature compat; LLM tier removed
117
+ judge_model: str | None = None, # noqa: ARG001
118
+ rel_tol: float = 1e-3,
119
+ abs_tol: float = 1e-3,
120
+ ) -> GradeResult:
121
+ """Deterministic three-tier match — NO LLM judge.
122
+
123
+ exact -> numeric (abs_tol/rel_tol, gated to clean-number golds) -> math_verify
124
+ -> miss. `judge`/`judge_model` accepted but ignored (LLM tier removed).
125
+ """
126
+
127
+ if not gold or candidate is None:
128
+ return GradeResult(0.0, "miss")
129
+
130
+ # ── Tier 1: exact (case-insensitive, whitespace-collapsed) ─��───────
131
+ if _normalize(gold) == _normalize(candidate):
132
+ return GradeResult(1.0, "exact")
133
+
134
+ # ── Tier 2: numeric — ONLY when the gold is a single clean number ──
135
+ # (compound golds like "Y=3 with 95,293 instances" would otherwise match on
136
+ # the leading number; those must go to exact/math_verify, which fail closed).
137
+ if reward_mode == "numeric" or _is_clean_number(gold):
138
+ g, c = _to_float(gold), _to_float(candidate)
139
+ if g is not None and c is not None:
140
+ if abs(g - c) <= abs_tol or abs(g - c) / max(abs(g), 1e-9) <= rel_tol:
141
+ return GradeResult(1.0, "numeric")
142
+
143
+ # ── Tier 3: math-verify (symbolic/numeric equivalence, deterministic) ──
144
+ if _math_verify_match(gold, candidate):
145
+ return GradeResult(1.0, "math_verify")
146
+
147
+ return GradeResult(0.0, "miss")
148
+
149
+
150
+ def _tool_calls() -> int | None:
151
+ """Number of agent tool calls this rollout, for the efficiency reward.
152
+
153
+ Written by the harness into the sandbox (`/workdir/.n_tool_calls`); falls
154
+ back to the `N_TOOL_CALLS` env var. Returns None if neither is present
155
+ (efficiency reward becomes null — the harness didn't report a count).
156
+ """
157
+ try:
158
+ with open("/workdir/.n_tool_calls") as fh:
159
+ return int(fh.read().strip())
160
+ except (OSError, ValueError):
161
+ pass
162
+ raw = os.environ.get("N_TOOL_CALLS")
163
+ if raw is not None:
164
+ try:
165
+ return int(str(raw).strip())
166
+ except ValueError:
167
+ return None
168
+ return None
169
+
170
+
171
+ def _tool_efficiency(n_calls: int | None) -> float | None:
172
+ """0..1 efficiency signal: fewer tool calls -> higher. None if unknown.
173
+
174
+ clip(1 - n_calls / TOOL_BUDGET, 0, 1). TOOL_BUDGET default 15 (solved-4B
175
+ median was ~9-10 calls). Raw signal — NOT gated on correctness here; the
176
+ RL reward combiner decides gating/weights.
177
+ """
178
+ if n_calls is None:
179
+ return None
180
+ budget = float(os.environ.get("TOOL_BUDGET", "15") or "15")
181
+ if budget <= 0:
182
+ return None
183
+ return max(0.0, min(1.0, 1.0 - n_calls / budget))
184
+
185
+
186
+ def _tols() -> tuple[float, float]:
187
+ """Per-task (abs_tol, rel_tol) from ATOL/RTOL in [verifier.env]; 1e-3 default."""
188
+ def _f(name: str) -> float:
189
+ try:
190
+ return float(os.environ.get(name, "") or 1e-3)
191
+ except ValueError:
192
+ return 1e-3
193
+ return _f("ATOL"), _f("RTOL")
194
+
195
+
196
+ def main_cli() -> int:
197
+ """CLI shim for `tests/test.sh` — env-driven, stdout-only.
198
+
199
+ Inputs (via env vars set by Harbor's [verifier.env]):
200
+ EXPECTED_ANSWER — the gold
201
+ QUESTION — the original question
202
+ ATOL / RTOL — per-task numeric tolerances (default 1e-3)
203
+
204
+ Predicted answer is read from stdin.
205
+ Single float written to stdout. Exit code is always 0.
206
+ """
207
+ gold = (os.environ.get("EXPECTED_ANSWER") or "").strip()
208
+ question = (os.environ.get("QUESTION") or "").strip()
209
+ candidate = sys.stdin.read().strip()
210
+ at, rt = _tols()
211
+ result = grade(gold, candidate, question=question, reward_mode=os.environ.get("REWARD_MODE","") or "", abs_tol=at, rel_tol=rt)
212
+ print(f"{result.reward:.1f}")
213
+ print(f"[grader] gold={gold!r} pred={candidate[:80]!r} reward={result.reward} method={result.method}",
214
+ file=sys.stderr)
215
+ return 0
216
+
217
+
218
+ def main_json() -> int:
219
+ """Multi-reward shim for `tests/test.sh` — writes a `reward.json` dict.
220
+
221
+ Three named rewards (Harbor's VerifierResult.rewards carries them all):
222
+ correctness — 1.0 iff graded answer matches gold, else 0.0
223
+ submission — 1.0 iff a non-empty answer was submitted, else 0.0
224
+ tool_efficiency — 0..1 (fewer tool calls higher); null if count unknown
225
+
226
+ No submission -> all three 0. Predicted answer on stdin; JSON to stdout.
227
+ """
228
+ import json
229
+
230
+ gold = (os.environ.get("EXPECTED_ANSWER") or "").strip()
231
+ question = (os.environ.get("QUESTION") or "").strip()
232
+ candidate = sys.stdin.read().strip()
233
+
234
+ if not candidate:
235
+ print(json.dumps({"correctness": 0.0, "submission": 0.0, "tool_efficiency": 0.0}))
236
+ print("[grader] no submission -> all rewards 0", file=sys.stderr)
237
+ return 0
238
+
239
+ at, rt = _tols()
240
+ result = grade(gold, candidate, question=question, reward_mode=os.environ.get("REWARD_MODE","") or "", abs_tol=at, rel_tol=rt)
241
+ n_calls = _tool_calls()
242
+ eff = _tool_efficiency(n_calls)
243
+ print(json.dumps({
244
+ "correctness": float(result.reward),
245
+ "submission": 1.0,
246
+ "tool_efficiency": eff,
247
+ }))
248
+ print(f"[grader] gold={gold!r} pred={candidate[:80]!r} "
249
+ f"correctness={result.reward} method={result.method} "
250
+ f"tool_calls={n_calls} tool_efficiency={eff}", file=sys.stderr)
251
+ return 0
252
+
253
+
254
+ if __name__ == "__main__":
255
+ if "--json" in sys.argv[1:]:
256
+ raise SystemExit(main_json())
257
+ raise SystemExit(main_cli())
tasks/0021_656_21656365_qa_5/tests/test.sh ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -u
3
+ mkdir -p /logs/verifier
4
+
5
+ answer_path="/workdir/answer.txt"
6
+ if [ ! -s "$answer_path" ]; then
7
+ echo "0.0" > /logs/verifier/reward.txt
8
+ echo "[grader] no answer at $answer_path" >&2
9
+ exit 0
10
+ fi
11
+
12
+ pip install --quiet math-verify >/dev/null 2>&1 || true
13
+ python3 /tests/grader.py < "$answer_path" > /logs/verifier/reward.txt
tasks/0023_757_23757075_qa_3/environment/pull_bucket.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Pull this task's bucket prefix into /home/user/input/.
2
+
3
+ Invoked by Harbor's [environment.healthcheck] command (declared in task.toml)
4
+ — runs after container start, before the agent. Idempotent: skips work if
5
+ files are already present from a prior pull.
6
+ """
7
+
8
+ import os
9
+ import sys
10
+ from pathlib import Path
11
+
12
+ from huggingface_hub import download_bucket_files, list_bucket_tree
13
+
14
+
15
+ def main() -> int:
16
+ bucket = os.environ.get("HF_BUCKET") or "AdithyaSK/jupyter-agent-kaggle-all"
17
+ prefix = os.environ["BUCKET_PREFIX"].rstrip("/") + "/"
18
+ dest = Path("/home/user/input")
19
+ dest.mkdir(parents=True, exist_ok=True)
20
+
21
+ existing = [p for p in dest.iterdir() if p.is_file()]
22
+ if existing:
23
+ print(f"[pull_bucket] {dest}/ already has {len(existing)} file(s); skipping", flush=True)
24
+ return 0
25
+
26
+ targets = [
27
+ (it.path, str(dest / Path(it.path).name))
28
+ for it in list_bucket_tree(bucket, prefix=prefix, recursive=True)
29
+ if getattr(it, "type", None) == "file"
30
+ ]
31
+ if not targets:
32
+ print(f"[pull_bucket] FATAL: no files at hf://buckets/{bucket}/{prefix}", flush=True)
33
+ return 2
34
+
35
+ download_bucket_files(bucket, files=targets)
36
+ print(f"[pull_bucket] staged {len(targets)} file(s) from {bucket}/{prefix}", flush=True)
37
+ return 0
38
+
39
+
40
+ if __name__ == "__main__":
41
+ sys.exit(main())
tasks/0033_308_33308132_qa_3/environment/Dockerfile ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ FROM docker.io/savatar101/env-data-agent-train:base
2
+ WORKDIR /workdir