← Lesson
Stop Conditions and Budgets
Joeven
Run
Reset
Python loads on first run
def goal_satisfied(obs): return isinstance(obs, dict) and "final" in obs def should_stop(decision, obs, steps, max_steps): if goal_satisfied(obs): return "success" if steps >= max_steps: return "budget" if decision.get("name") == "handoff": return "handoff" return None def run(max_steps, always_search): steps = 0 last = None while True: steps += 1 if always_search: decision = {"name": "search"} obs = {"hits": steps} else: decision = {"name": "finish"} obs = {"final": "done"} why = should_stop(decision, obs, steps, max_steps) print("step", steps, decision["name"], why) last = obs if why: if why == "budget": return "cannot: step budget" return last print("happy", run(4, always_search=False)) print("stuck", run(3, always_search=True))
Run to execute this in your browser. Nothing is sent to a server.