Both policy engines behind one gate
One guard runs both policy engines in turn, the lite govern() gate and the PolicyEngine kernel, so a tool call has to pass both before it runs and either engine can stop it.
Last updated: 14 Oct, 2026 · Agent Governance Toolkit 4.1.0
The course built two independent gates: the one-line govern(): the smallest real gate and the fuller One choke point for every tool call. They read a call differently and miss different things. Putting both behind one function is defense in depth: a call must clear each one.
Building the two engines
The lite gate carries an allow-list and an explicit deny. The kernel carries a per-role allow-list. They are deliberately not identical here, so each engine ends up being the one that stops a different call.
import warnings; warnings.simplefilter("ignore")
from agent_os.lite import govern
from agent_control_plane import PolicyEngine, AgentKernel
# engine one: the lite govern() gate from the first part
gate = govern(allow=["order_status", "refund"], deny=["delete_account"])
# engine two: the policy engine wrapped in a kernel
policy = PolicyEngine()
policy.add_constraint("support", ["order_status", "delete_account"])
kernel = AgentKernel(policy_engine=policy)One guard that asks both
The guard runs govern() first, because it is cheap and reads only the tool name. If that passes, it asks the kernel, which can also read the arguments. A call is allowed only when neither engine objects.
def guard(tool, args):
d = gate.evaluate(tool) # the lite gate decides first
if not d.allowed:
return f"govern blocked: {d.reason}"
v = kernel.intercept_tool_execution("support", tool, args) # then the kernel
if v is not None:
return f"kernel blocked: {v['error']}"
return "allowed by both"A call through the combined gate
Three calls show the two engines covering for each other. One passes both; one is stopped by the kernel because it is not on the role's list; one is stopped by govern() because it is explicitly denied.
for tool in ["order_status", "refund", "delete_account"]:
print(f"{tool:16} -> {guard(tool, {})}")order_status -> allowed by both refund -> kernel blocked: RuntimeError: PolicyViolation - Role support cannot use tool refund delete_account -> govern blocked: Action 'delete_account' is explicitly denied
What each engine caught
- order_status passed both, so the guard returns
allowed by bothand the tool may run. - refund cleared govern() but the kernel stopped it, because
refundis not on support's kernel allow-list even though the lite gate allows it. - delete_account never reached the kernel, because
govern()denies it outright and the guard returns before the second check.
What each engine adds
| govern() | The kernel | |
|---|---|---|
| Reads | The tool name and content | The role, the tool and the arguments |
| Default | Fail-open, allows an unlisted tool | Default-deny, refuses an unknown role |
| Runs | First, as a cheap filter | Second, for the deeper check |
Where you put two engines behind one gate
- A migration, where a new engine runs alongside the old one until you trust it to stand alone.
- A belt-and-braces deployment, where a mistake in one policy is caught by the other.
- A split of concerns, letting the lite gate hold a short global deny-list while the kernel holds the per-role detail.
govern() check first and the kernel, which also reads arguments, second.Related
- Previous: Shadow mode: trying a policy safely
- Next: Sandbox policy, without running a sandbox
- See also: govern(): the smallest real gate
- Add
refundto the kernel's allow-list and confirm it now passes both engines. - Swap the order so the kernel runs first and read how the
delete_accountmessage changes. - Add a third engine, a content check with
blocked_content, as a further step in the guard.
You understood something today that you didn't yesterday.