Stop a scripted agent with evidence
Implement run_script(actions, catalog, budget). The scripted policy proposes dictionaries of kind lookup with a product or kind final with an evidence ID. Each proposal consumes one decision. A successful lookup records o1, o2, and so on; repeated lookup of the same product stops with loop_detected. Unknown products stop with blocked. A final action completes only when its reference exists. Invalid proposals consume a decision and continue. Return status, calls, decisions, and answer. Stop with budget_exhausted when more proposals remain beyond the budget, otherwise policy_exhausted. The catalog is a trusted product-to-count fixture.
Your task
- Complete the starter function using the contract above.
- Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
- Run tests to record your result, then compare with the explained reference solution.
Examples
Inputrun_script([{"kind":"lookup","product":"pen"},{"kind":"final","evidence":"o1"}], {"pen":7}, 2)
Output{"status":"complete","calls":1,"decisions":2,"answer":7}
Inputrun_script([{"kind":"final","evidence":"missing"}], {}, 2)
Output{"status":"policy_exhausted","calls":0,"decisions":1,"answer":null}
Implement the function, then run the tests.
Ctrl / ⌘ + Enter to test · Shift + Tab leaves editor