Datasets:
Download runner/agentgridworld/run.py from bytkim/AgentGridWorld-Hard: direct link, hf CLI and curl.
- Browser
- Download file 4.64 kB
-
https://huggingface.co/datasets/bytkim/AgentGridWorld-Hard/resolve/main/runner/agentgridworld/run.py
- Command line
-
hf download hf://datasets/bytkim/AgentGridWorld-Hard/runner/agentgridworld/run.py
-
curl -L -o run.py https://huggingface.co/datasets/bytkim/AgentGridWorld-Hard/resolve/main/runner/agentgridworld/run.py
4.64 kB
| """One bounded Harbor evaluation over exact pool membership; host credentials only.""" | |
| import argparse | |
| import json | |
| import os | |
| from pathlib import Path | |
| import re | |
| import subprocess | |
| import sys | |
| from dotenv import dotenv_values | |
| from openai import OpenAI | |
| from .pool import verify_pool, sha | |
| from .presentation import PROFILES as PRESENTATIONS, profile_sha256 | |
| from .model import MODEL, PROFILES, settings, save | |
| from .participant import ACTION_REVISION | |
| ROOT = Path(__file__).resolve().parent | |
| def main(): | |
| p=argparse.ArgumentParser() | |
| p.add_argument('--pool',type=Path,required=True) | |
| p.add_argument('--model', choices=list(PROFILES), default=MODEL) | |
| p.add_argument('--mode',choices=['oracle','model'],required=True) | |
| p.add_argument('--job-name',required=True) | |
| p.add_argument('--jobs-dir',type=Path,default=Path('artifacts/jobs')) | |
| p.add_argument('--env-file',type=Path) | |
| p.add_argument('--modal-profile',default=None) | |
| p.add_argument('--temperature',type=float,default=0) | |
| p.add_argument('--presentation',choices=PRESENTATIONS,default=ACTION_REVISION) | |
| p.add_argument('--plan-only',action='store_true') | |
| args=p.parse_args() | |
| model_settings=settings(args.model,args.temperature,action_only=args.presentation==ACTION_REVISION) | |
| if not re.fullmatch('[A-Za-z0-9_-]+',args.job_name):raise SystemExit('Invalid job name') | |
| pool=args.pool.resolve();manifest=verify_pool(pool) | |
| jobs=args.jobs_dir.resolve();jobs.mkdir(parents=True,exist_ok=True) | |
| prefix=jobs/args.job_name | |
| if any(jobs.glob(args.job_name+'.*')) or prefix.exists(): | |
| raise SystemExit('Use a fresh job name; attempts are immutable') | |
| env=os.environ.copy();env['PYTHONHASHSEED']='0' | |
| if args.modal_profile:env['MODAL_PROFILE']=args.modal_profile | |
| env['PYTHONPATH']=str(ROOT.parent)+(os.pathsep+env['PYTHONPATH'] if env.get('PYTHONPATH') else '') | |
| if args.mode=='model': | |
| values=dotenv_values(args.env_file) if args.env_file else {} | |
| key=env.get('OPENAI_API_KEY') or env.get('OPENAI_KEY') or values.get('OPENAI_API_KEY') or values.get('OPENAI_KEY') | |
| if not key:raise SystemExit('No configured OpenAI credential') | |
| env['OPENAI_API_KEY']=key | |
| if not args.plan_only: | |
| with OpenAI(api_key=key,base_url='https://api.openai.com/v1',max_retries=0,timeout=20) as client: | |
| model=client.models.retrieve(args.model) | |
| if model.id!=args.model:raise SystemExit('Exact model snapshot unavailable') | |
| save(jobs/(args.job_name+'.model-access.json'),{'requested':args.model,'returned':model.id}) | |
| command=[str(Path(sys.executable).parent/'harbor'),'run','--path',str(pool), | |
| '--agent','oracle' if args.mode=='oracle' else 'agentgridworld.agent:ScenarioAgent', | |
| '--env','modal','--n-concurrent','1','--n-attempts','1','--max-retries','0','--delete', | |
| '--environment-kwarg','app_name=agentgridworld-v0-1', | |
| '--environment-kwarg','sandbox_timeout_secs=900', | |
| '--environment-kwarg','sandbox_idle_timeout_secs=120', | |
| '--jobs-dir',str(jobs),'--job-name',args.job_name] | |
| if args.mode=='model': | |
| command+=['--model','openai/'+args.model] | |
| if args.temperature!=0:command+=['--agent-kwarg','temperature='+str(args.temperature)] | |
| command+=['--agent-kwarg','presentation='+args.presentation] | |
| plan=subprocess.run(command+['--print-config'],env=env,cwd=ROOT.parent,capture_output=True,text=True,check=True) | |
| data=json.loads(plan.stdout) | |
| # Preserve the exact selected membership before any trial starts. | |
| save(jobs/(args.job_name+'.plan.json'),data) | |
| save(jobs/(args.job_name+'.pool-binding.json'),{ | |
| 'pool_manifest_sha256':sha(pool/'pool.json'), 'pool':manifest, | |
| 'source_sha256':{p.name:sha(p) for p in sorted(ROOT.glob('*.py'))}, | |
| 'model_call_cap':manifest['maximum_model_calls_per_attempt'] if args.mode=='model' else 0, | |
| 'model': args.model if args.mode=='model' else None, | |
| 'settings': model_settings if args.mode=='model' else None, | |
| 'mode':args.mode, 'n_attempts':1, 'max_retries':0, | |
| **({'presentation':args.presentation,'presentation_profile_sha256':profile_sha256(args.presentation)} if args.presentation!='base' else {})}) | |
| if args.plan_only:print('Plan saved:',jobs);return | |
| with (jobs/(args.job_name+'.launch.log')).open('x') as log: | |
| result=subprocess.run(command,env=env,cwd=ROOT.parent,stdout=log,stderr=subprocess.STDOUT) | |
| print('Harbor exit:',result.returncode,'; evidence:',prefix) | |
| raise SystemExit(result.returncode) | |
| if __name__=='__main__':main() | |