Workspace/Coding labs
Loading progress

Stop a scripted agent with evidence

Intermediate65 min

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

  1. Complete the starter function using the contract above.
  2. Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
  3. Run tests to record your result, then compare with the explained reference solution.

Examples

EXAMPLE 1

Inputrun_script([{"kind":"lookup","product":"pen"},{"kind":"final","evidence":"o1"}], {"pen":7}, 2)

Output{"status":"complete","calls":1,"decisions":2,"answer":7}

Completion requires a prior observation.
EXAMPLE 2

Inputrun_script([{"kind":"final","evidence":"missing"}], {}, 2)

Output{"status":"policy_exhausted","calls":0,"decisions":1,"answer":null}

An unsupported final proposal is rejected.
solution.pyPython 3.12