{
  "schemaVersion": 1,
  "id": "graph-vs-agent-loop",
  "function": "control_action",
  "starter": "def control_action(payload):\n    \"\"\"Implement the public contract; disclose assistance used.\"\"\"\n    raise NotImplementedError(\"graph-vs-agent-loop\")\n",
  "checks": [
    {
      "id": "graph-search-progress",
      "input": {
        "mode": "graph",
        "tenant": "A",
        "principal": {
          "tenant": "A",
          "approved": true
        },
        "phase": "retrieve",
        "proposal": {
          "tool": "search",
          "args": {
            "tenant": "A",
            "operation_key": null
          }
        },
        "budget": {
          "remaining": 5,
          "cost": 2
        },
        "steps": 0,
        "max_steps": 4
      },
      "expected": {
        "decision": "allow",
        "reason": "dispatch_candidate",
        "next_phase": "draft",
        "tool": "search"
      },
      "error": null
    },
    {
      "id": "loop-can-repeat-search",
      "input": {
        "mode": "loop",
        "tenant": "A",
        "principal": {
          "tenant": "A",
          "approved": true
        },
        "phase": "draft",
        "proposal": {
          "tool": "search",
          "args": {
            "tenant": "A",
            "operation_key": null
          }
        },
        "budget": {
          "remaining": 5,
          "cost": 2
        },
        "steps": 0,
        "max_steps": 4
      },
      "expected": {
        "decision": "allow",
        "reason": "dispatch_candidate",
        "next_phase": "draft",
        "tool": "search"
      },
      "error": null
    },
    {
      "id": "graph-cannot-repeat-search",
      "input": {
        "mode": "graph",
        "tenant": "A",
        "principal": {
          "tenant": "A",
          "approved": true
        },
        "phase": "draft",
        "proposal": {
          "tool": "search",
          "args": {
            "tenant": "A",
            "operation_key": null
          }
        },
        "budget": {
          "remaining": 5,
          "cost": 2
        },
        "steps": 0,
        "max_steps": 4
      },
      "expected": {
        "decision": "deny",
        "reason": "invalid_transition",
        "next_phase": "draft",
        "tool": null
      },
      "error": null
    },
    {
      "id": "write-candidate-awaits-receipt",
      "input": {
        "mode": "graph",
        "tenant": "A",
        "principal": {
          "tenant": "A",
          "approved": true
        },
        "phase": "execute",
        "proposal": {
          "tool": "refund",
          "args": {
            "tenant": "A",
            "operation_key": "refund-1"
          }
        },
        "budget": {
          "remaining": 5,
          "cost": 2
        },
        "steps": 0,
        "max_steps": 4
      },
      "expected": {
        "decision": "allow",
        "reason": "dispatch_candidate",
        "next_phase": "reconcile",
        "tool": "refund"
      },
      "error": null
    },
    {
      "id": "approval-checkpoint-is-not-dispatch",
      "input": {
        "mode": "graph",
        "tenant": "A",
        "principal": {
          "tenant": "A",
          "approved": true
        },
        "phase": "approve",
        "proposal": {
          "tool": "refund",
          "args": {
            "tenant": "A",
            "operation_key": "refund-1"
          }
        },
        "budget": {
          "remaining": 5,
          "cost": 2
        },
        "steps": 0,
        "max_steps": 4
      },
      "expected": {
        "decision": "advance",
        "reason": "approval_checkpoint",
        "next_phase": "execute",
        "tool": null
      },
      "error": null
    },
    {
      "id": "unapproved-write-pauses",
      "input": {
        "mode": "graph",
        "tenant": "A",
        "principal": {
          "tenant": "A",
          "approved": false
        },
        "phase": "execute",
        "proposal": {
          "tool": "refund",
          "args": {
            "tenant": "A",
            "operation_key": "refund-1"
          }
        },
        "budget": {
          "remaining": 5,
          "cost": 2
        },
        "steps": 0,
        "max_steps": 4
      },
      "expected": {
        "decision": "pause",
        "reason": "approval_required",
        "next_phase": "execute",
        "tool": null
      },
      "error": null
    },
    {
      "id": "foreign-model-args-denied",
      "input": {
        "mode": "graph",
        "tenant": "A",
        "principal": {
          "tenant": "A",
          "approved": true
        },
        "phase": "execute",
        "proposal": {
          "tool": "refund",
          "args": {
            "tenant": "B",
            "operation_key": "refund-1"
          }
        },
        "budget": {
          "remaining": 5,
          "cost": 2
        },
        "steps": 0,
        "max_steps": 4
      },
      "expected": {
        "decision": "deny",
        "reason": "tenant_mismatch",
        "next_phase": "execute",
        "tool": null
      },
      "error": null
    },
    {
      "id": "budget-pauses",
      "input": {
        "mode": "graph",
        "tenant": "A",
        "principal": {
          "tenant": "A",
          "approved": true
        },
        "phase": "retrieve",
        "proposal": {
          "tool": "search",
          "args": {
            "tenant": "A",
            "operation_key": null
          }
        },
        "budget": {
          "remaining": 1,
          "cost": 2
        },
        "steps": 0,
        "max_steps": 4
      },
      "expected": {
        "decision": "pause",
        "reason": "budget_exhausted",
        "next_phase": "retrieve",
        "tool": null
      },
      "error": null
    },
    {
      "id": "step-limit-pauses",
      "input": {
        "mode": "graph",
        "tenant": "A",
        "principal": {
          "tenant": "A",
          "approved": true
        },
        "phase": "retrieve",
        "proposal": {
          "tool": "search",
          "args": {
            "tenant": "A",
            "operation_key": null
          }
        },
        "budget": {
          "remaining": 5,
          "cost": 2
        },
        "steps": 4,
        "max_steps": 4
      },
      "expected": {
        "decision": "pause",
        "reason": "step_limit",
        "next_phase": "retrieve",
        "tool": null
      },
      "error": null
    },
    {
      "id": "missing-write-key-denied",
      "input": {
        "mode": "graph",
        "tenant": "A",
        "principal": {
          "tenant": "A",
          "approved": true
        },
        "phase": "execute",
        "proposal": {
          "tool": "refund",
          "args": {
            "tenant": "A",
            "operation_key": null
          }
        },
        "budget": {
          "remaining": 5,
          "cost": 2
        },
        "steps": 0,
        "max_steps": 4
      },
      "expected": {
        "decision": "deny",
        "reason": "write_key_required",
        "next_phase": "execute",
        "tool": null
      },
      "error": null
    },
    {
      "id": "loop-stop-is-not-completion",
      "input": {
        "mode": "loop",
        "tenant": "A",
        "principal": {
          "tenant": "A",
          "approved": true
        },
        "phase": "retrieve",
        "proposal": {
          "tool": "finish",
          "args": {
            "tenant": "A",
            "operation_key": null
          }
        },
        "budget": {
          "remaining": 5,
          "cost": 2
        },
        "steps": 0,
        "max_steps": 4
      },
      "expected": {
        "decision": "stop",
        "reason": "model_stop",
        "next_phase": "retrieve",
        "tool": null
      },
      "error": null
    },
    {
      "id": "graph-stop-needs-done",
      "input": {
        "mode": "graph",
        "tenant": "A",
        "principal": {
          "tenant": "A",
          "approved": true
        },
        "phase": "retrieve",
        "proposal": {
          "tool": "finish",
          "args": {
            "tenant": "A",
            "operation_key": null
          }
        },
        "budget": {
          "remaining": 5,
          "cost": 2
        },
        "steps": 0,
        "max_steps": 4
      },
      "expected": {
        "decision": "deny",
        "reason": "invalid_transition",
        "next_phase": "retrieve",
        "tool": null
      },
      "error": null
    },
    {
      "id": "completed-stop-no-budget",
      "input": {
        "mode": "graph",
        "tenant": "A",
        "principal": {
          "tenant": "A",
          "approved": true
        },
        "phase": "done",
        "proposal": {
          "tool": "finish",
          "args": {
            "tenant": "A",
            "operation_key": null
          }
        },
        "budget": {
          "remaining": 5,
          "cost": 2
        },
        "steps": 4,
        "max_steps": 4
      },
      "expected": {
        "decision": "stop",
        "reason": "completed",
        "next_phase": "done",
        "tool": null
      },
      "error": null
    },
    {
      "id": "bool-step-rejected",
      "input": {
        "mode": "graph",
        "tenant": "A",
        "principal": {
          "tenant": "A",
          "approved": true
        },
        "phase": "retrieve",
        "proposal": {
          "tool": "search",
          "args": {
            "tenant": "A",
            "operation_key": null
          }
        },
        "budget": {
          "remaining": 5,
          "cost": 2
        },
        "steps": true,
        "max_steps": 4
      },
      "expected": null,
      "error": "ValueError:input_shape"
    },
    {
      "id": "string-approval-rejected",
      "input": {
        "mode": "graph",
        "tenant": "A",
        "principal": {
          "tenant": "A",
          "approved": "true"
        },
        "phase": "execute",
        "proposal": {
          "tool": "refund",
          "args": {
            "tenant": "A",
            "operation_key": "refund-1"
          }
        },
        "budget": {
          "remaining": 5,
          "cost": 2
        },
        "steps": 0,
        "max_steps": 4
      },
      "expected": null,
      "error": "ValueError:input_shape"
    },
    {
      "id": "reconcile-cannot-replay",
      "input": {
        "mode": "graph",
        "tenant": "A",
        "principal": {
          "tenant": "A",
          "approved": true
        },
        "phase": "reconcile",
        "proposal": {
          "tool": "refund",
          "args": {
            "tenant": "A",
            "operation_key": "refund-1"
          }
        },
        "budget": {
          "remaining": 5,
          "cost": 2
        },
        "steps": 0,
        "max_steps": 4
      },
      "expected": {
        "decision": "deny",
        "reason": "invalid_transition",
        "next_phase": "reconcile",
        "tool": null
      },
      "error": null
    }
  ]
}
