Datasets:
Download runner/agentgridworld/check.py from bytkim/AgentGridWorld-Hard: direct link, hf CLI and curl.
- Browser
- Download file 3.06 kB
-
https://huggingface.co/datasets/bytkim/AgentGridWorld-Hard/resolve/main/runner/agentgridworld/check.py
- Command line
-
hf download hf://datasets/bytkim/AgentGridWorld-Hard/runner/agentgridworld/check.py
-
curl -L -o check.py https://huggingface.co/datasets/bytkim/AgentGridWorld-Hard/resolve/main/runner/agentgridworld/check.py
3.06 kB
| """Local package check through the real HTTP owner and packaged verifier; no API calls.""" | |
| import argparse | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| import subprocess | |
| import sys | |
| SCRIPT = '''import json,sys,threading,urllib.request | |
| from pathlib import Path | |
| from service import make_server | |
| config=json.loads(Path('../task-config.json').read_text()) | |
| out=Path(sys.argv[1]); actions=json.loads(Path(sys.argv[2]).read_text())['actions'] | |
| server=make_server(config,out/'episode.json',('127.0.0.1',0)) | |
| thread=threading.Thread(target=server.serve_forever); thread.start() | |
| transitions=[] | |
| try: | |
| for action in actions: | |
| req=urllib.request.Request(f'http://127.0.0.1:{server.server_port}/action',data=json.dumps({'action':action}).encode()) | |
| with urllib.request.urlopen(req,timeout=5) as response: observation=json.load(response) | |
| transitions.append({'action':action,'observation':observation}) | |
| finally: | |
| server.shutdown();server.server_close();thread.join() | |
| (out/'transitions.json').write_text(json.dumps(transitions,indent=2)+'\\n') | |
| ''' | |
| def check(task, output): | |
| task = Path(task).resolve(); output = Path(output).resolve() | |
| manifest = json.loads((task/'manifest.json').read_text()) | |
| for name, expected in manifest['files_sha256'].items(): | |
| if hashlib.sha256((task/name).read_bytes()).hexdigest() != expected: | |
| raise ValueError('Package hash mismatch: ' + name) | |
| output.mkdir(parents=True, exist_ok=False) | |
| runtime = task/'environment/runtime' | |
| with (output/'execution.log').open('x') as log: | |
| subprocess.run([sys.executable,'-c',SCRIPT,str(output),str(task/'witness.json')],cwd=runtime,stdout=log,stderr=subprocess.STDOUT,check=True,timeout=60) | |
| subprocess.run([sys.executable,'verify.py','--config','../task-config.json','--receipt',str(output/'episode.json'),'--output',str(output/'verifier')],cwd=runtime,stdout=log,stderr=subprocess.STDOUT,check=True,timeout=60) | |
| outcome = json.loads((output/'verifier/outcome.json').read_text()) | |
| expected = json.loads((task/'witness.json').read_text())['outcome'] | |
| if outcome != expected: | |
| raise ValueError('Packaged verifier differs from qualified witness') | |
| reward = json.loads((output/'verifier/reward.json').read_text()) | |
| if reward != {'reward':outcome['reported_reward']}: | |
| raise ValueError('Reward policy mismatch') | |
| result = {'package_manifest_sha256':hashlib.sha256((task/'manifest.json').read_bytes()).hexdigest(), | |
| 'classification':json.loads((task/'qualification.json').read_text())['classification'], | |
| 'local_service_and_replay_verified':True,'outcome':outcome, | |
| 'scope':'Local packaged runtime only; no remote isolation or model qualification'} | |
| (output/'check.json').write_text(json.dumps(result,indent=2)+'\n') | |
| return result | |
| if __name__ == '__main__': | |
| p=argparse.ArgumentParser();p.add_argument('--task',type=Path,required=True);p.add_argument('--output',type=Path,required=True) | |
| args=p.parse_args();print(json.dumps(check(args.task,args.output),indent=2)) | |