Datasets:
Download artifacts/runtime-source/compaction_task.py from suunny/terminal-agent-rl: direct link, hf CLI and curl.
- Browser
- Download file 2.1 kB
-
https://huggingface.co/datasets/suunny/terminal-agent-rl/resolve/main/artifacts/runtime-source/compaction_task.py
- Command line
-
hf download hf://datasets/suunny/terminal-agent-rl/artifacts/runtime-source/compaction_task.py
-
curl -L -o compaction_task.py https://huggingface.co/datasets/suunny/terminal-agent-rl/resolve/main/artifacts/runtime-source/compaction_task.py
2.1 kB
| """Retain the original task alongside the official Verifiers compaction summary.""" | |
| import ast | |
| import hashlib | |
| import importlib.metadata | |
| import importlib.util | |
| import py_compile | |
| from pathlib import Path | |
| UPSTREAM_SHA256 = "0de63a0982c4b2fefebc99b6eac4f699168f1eedd6db2c22661bc5affa62e878" | |
| ORIGINAL = ' rebuilt = [*system, {"role": "user", "content": framed}]' | |
| REPLACEMENT = ''' # Keep the exact task through every compaction, not just its summary. | |
| original_task = next( | |
| (message for message in messages if message.get("role") == "user"), | |
| None, | |
| ) | |
| rebuilt = [ | |
| *system, | |
| *([original_task] if original_task is not None else []), | |
| {"role": "user", "content": framed}, | |
| ]''' | |
| def patch_source(source: str) -> str: | |
| upstream = source.replace(REPLACEMENT, ORIGINAL) | |
| if hashlib.sha256(upstream.encode()).hexdigest() != UPSTREAM_SHA256: | |
| raise RuntimeError("Upstream compactor changed; refusing an unreviewed patch") | |
| if upstream.count(ORIGINAL) != 1: | |
| raise RuntimeError("Expected exactly one compaction rebuild") | |
| updated = upstream.replace(ORIGINAL, REPLACEMENT) | |
| ast.parse(updated) | |
| return updated | |
| def install(): | |
| if importlib.metadata.version("verifiers") != "0.4.1.dev12": | |
| raise RuntimeError("Task-retention patch requires reviewed Verifiers 0.4.1.dev12") | |
| package = importlib.util.find_spec("verifiers") | |
| path = Path(package.origin).parent / "v1/harnesses/utils/compaction.py" | |
| source = path.read_text() | |
| updated = patch_source(source) | |
| if source != updated: | |
| path.write_text(updated) | |
| for cached in (path.parent / "__pycache__").glob("compaction.*.pyc"): | |
| cached.unlink() | |
| py_compile.compile(str(path), doraise=True, | |
| invalidation_mode=py_compile.PycInvalidationMode.CHECKED_HASH) | |
| print("Installed compaction task retention (original task + native summary)") | |
| if __name__ == "__main__": | |
| install() | |