feat(orchestration): nightly runner, rollover budgets, incremental checkpoints
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016DvdRZkyCy9NJpHYDdPqmS
This commit is contained in:
1 parent
b2ae3d6ced
commit
aa1ae0c95e
4 files changed
+161
No files matched your search
@@ -0,0 +1,32 @@
|
||||
"""Incremental, crash-safe JSON output. Each agent's output is (over)written atomically
|
||||
after every research round and again at finalize, so a hang or power loss mid-run still
|
||||
leaves the best-so-far result on disk under state/output/<trade_date>/<persona>.json.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from agents.schemas import AgentOutput, RunManifest
|
||||
|
||||
|
||||
def _atomic_write(path: Path, text: str) -> None:
|
||||
tmp = path.with_suffix(path.suffix + ".tmp")
|
||||
tmp.write_text(text)
|
||||
os.replace(tmp, path) # atomic on the same filesystem
|
||||
|
||||
|
||||
class Checkpointer:
|
||||
def __init__(self, output_dir: Path, trade_date: str):
|
||||
self.dir = Path(output_dir) / trade_date
|
||||
self.dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
def agent_path(self, persona_id: str) -> Path:
|
||||
return self.dir / f"{persona_id}.json"
|
||||
|
||||
def write(self, output: AgentOutput) -> None:
|
||||
_atomic_write(self.agent_path(output.persona_id), output.model_dump_json(indent=2))
|
||||
|
||||
def write_manifest(self, manifest: RunManifest) -> None:
|
||||
_atomic_write(self.dir / "_manifest.json", manifest.model_dump_json(indent=2))
|
||||
Reference in new issue
Block a user