Files
agent-maxim/bridge/core/state_store.py
T
Anton 052591281d Initial clean version - Agent Maxim
- Complete agent system with planning and execution
- Bridge API with FastAPI server
- WhatsApp-style mobile dashboard
- Enhanced web search with query improvement
- Security guards and policy checks
- Comprehensive documentation
2026-04-09 18:07:43 +03:00

31 lines
942 B
Python

"""Persist and load run state to/from bridge/runs/<run_id>/state.json."""
from __future__ import annotations
import json
from pathlib import Path
from typing import Any
class StateStore:
"""Read/write run state as JSON under runs/<run_id>/state.json."""
def __init__(self, runs_dir: Path) -> None:
self._runs_dir = runs_dir
def _path(self, run_id: str) -> Path:
return self._runs_dir / run_id / "state.json"
def save(self, run_id: str, state: dict[str, Any]) -> None:
p = self._path(run_id)
p.parent.mkdir(parents=True, exist_ok=True)
p.write_text(json.dumps(state, indent=2), encoding="utf-8")
def load(self, run_id: str) -> dict[str, Any] | None:
p = self._path(run_id)
if not p.exists():
return None
return json.loads(p.read_text(encoding="utf-8"))
def exists(self, run_id: str) -> bool:
return self._path(run_id).exists()