All courses · Course overview · Lesson sequence
Skip to lesson textproject/advanced_demo.py
"""Checkpoint/review rehearsal with deterministic tools and no external actions."""
from engine import Checkpoints, Engine, SimulatedCrash
from workflow import Request
def main():
print("SYNTHETIC ONLY: deterministic planner; RAM SQLite; no real approvals or writes")
store = Checkpoints()
engine = Engine(store)
engine.start(Request("CHECK-001", "EX-001", 1927, "Untrusted note stays outside planner view"))
state = engine.run_until_pause("CHECK-001", now_tick=4)
print("Pause:", state["phase"], "steps:", state["steps"], "reserved attempts:", state["tool_calls"])
print("Draft:", state["draft"])
transferred = store.export()
store.close()
restored = Checkpoints.restore(transferred)
resumed = Engine(restored)
state = resumed.review("CHECK-001", state["revision"], state["draft_digest"],
"synthetic-reviewer-a", True, now_tick=5)
state = resumed.finalize_simulation("CHECK-001", now_tick=5)
print("After review and resume:", state["phase"], state["receipt"])
print("Replay same receipt:", resumed.finalize_simulation("CHECK-001", now_tick=5)["receipt"] == state["receipt"])
resumed.start(Request("CRASH-001", "EX-001", 1927))
from engine import BaselinePlanner
resumed.plan("CRASH-001", BaselinePlanner())
try:
resumed.invoke("CRASH-001", crash_after_read=True)
except SimulatedCrash:
print("Crash simulation saved phase:", restored.get("CRASH-001")["phase"])
state = resumed.recover("CRASH-001", abandon_read=True)
state = resumed.run_until_pause("CRASH-001")
print("Deliberate read-only recovery:", state["phase"], "reserved attempts:", state["tool_calls"])
restored.close()
if __name__ == "__main__":
main()