MCPcopy Create free account
hub / github.com/CommonstackAI/UncommonRoute / save_state

Function save_state

uncommon_route/persistence.py:28–40  ·  view source on GitHub ↗
(state: LearnedState, directory: Path)

Source from the content-addressed store, hash-verified

26
27
28def save_state(state: LearnedState, directory: Path) -> None:
29 directory.mkdir(parents=True, exist_ok=True)
30 data = asdict(state)
31 data["schema_version"] = SCHEMA_VERSION
32 target = directory / STATE_FILENAME
33 fd, tmp_path = tempfile.mkstemp(dir=directory, suffix=".tmp")
34 try:
35 with open(fd, "w", encoding="utf-8") as f:
36 json.dump(data, f, indent=2)
37 Path(tmp_path).replace(target)
38 except Exception:
39 Path(tmp_path).unlink(missing_ok=True)
40 raise
41
42
43def load_state(directory: Path) -> LearnedState:

Callers 5

test_save_load_roundtripFunction · 0.90
test_reset_stateFunction · 0.90
on_shutdownFunction · 0.90
reset_stateFunction · 0.85

Calls 1

openFunction · 0.85

Tested by 3

test_save_load_roundtripFunction · 0.72
test_reset_stateFunction · 0.72