Agent-test / progress.py
Effina-byte's picture
Update progress.py
42ab630 verified
Raw History Blame Contribute Delete
1.04 kB
"""Tiny on-disk store of solved answers, so a run can resume.
Every successfully solved question is saved here immediately; the next run skips those and only
retries the ones that failed. Delete progress.json (or use the "Clear saved
progress" button) to start over.
"""
from __future__ import annotations
import json
import os
from pathlib import Path
PROGRESS_FILE = Path(os.getenv("PROGRESS_FILE", "progress.json"))
def is_error(answer: str | None) -> bool:
return not answer or str(answer).startswith("AGENT_ERROR")
def load() -> dict[str, str]:
try:
return json.loads(PROGRESS_FILE.read_text(encoding="utf-8"))
except Exception:
return {}
def save_answer(task_id: str, answer: str) -> None:
if is_error(answer):
return
data = load()
data[str(task_id)] = answer
PROGRESS_FILE.write_text(
json.dumps(data, indent=2, ensure_ascii=False), encoding="utf-8"
)
def clear() -> None:
try:
PROGRESS_FILE.unlink()
except FileNotFoundError:
pass