An AI agent policy template for OPA
A policy engine is only useful if the model cannot argue with it. This Rego starter decides one question per tool call — allow, require a named human, or deny — from the tool name, the arguments and the caller’s scopes, and it fails closed on anything it does not recognise.
It is written as a starting point, not a product. The eight decision cases in the file are the specification: read them first, then adapt the thresholds to the workflow you are governing.
What is inside
| Section | What it covers |
|---|---|
| Decision shape | allow / deny / requires-approval, with a reason string the runtime can log and show a reviewer. |
| Fail-closed defaults | Only a read-only tool the agent holds a scope for is auto-allowed. Everything unknown is denied. |
| Arguments, not names | Amounts over a limit, personal data classes and write operations route to a named human rather than passing. |
| Test file | agent-action-gate_test.rego covering the eight decision cases documented in the policy header. |
How to use it
- Run opa test on the two files before you change anything. If the baseline fails, the OPA version differs from the one this was written against.
- Replace the sample tool names and scopes with your own registry entries.
- Set the spend and data-class thresholds to the values your risk owner will defend to an examiner.
- Deploy in log-only mode first for a week and compare what the policy would have blocked with what actually happened.
- Move to enforce once the denial list is boring. Keep the last versions so a change can be explained.
How do you write a policy that decides what an AI agent may do?
Does this policy work with Open Policy Agent v1?
Yes — it is written for OPA v1 syntax. The eight decision cases were checked on an independent Rego v1 engine on 2026-10-03; run `opa test` against your own OPA binary before you rely on it, since the test file and the binary have not been run together here.
Why fail closed rather than warn?
A warning arrives after the call has already reached the system of record. Fail-closed means the default answer to an unrecognised tool, an unscoped caller or an oversized amount is no, and the reviewer sees the denial instead of a customer seeing the mistake.
Can I use this commercially?
The file is published as Apache-2.0 (proposed in the file header). Adapt it freely; keep the attribution notice if you redistribute it.