Agent Governance ToolkitAgent Governance Toolkit 4.1.0 · Python 3.10+
Dashboard
0%

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.

python
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.

python
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.

ExampleEach engine stops a call the other would have allowed
for tool in ["order_status", "refund", "delete_account"]:
    print(f"{tool:16} -> {guard(tool, {})}")

What each engine caught

  • order_status passed both, so the guard returns allowed by both and the tool may run.
  • refund cleared govern() but the kernel stopped it, because refund is 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
ReadsThe tool name and contentThe role, the tool and the arguments
DefaultFail-open, allows an unlisted toolDefault-deny, refuses an unknown role
RunsFirst, as a cheap filterSecond, 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.
Watch out. Two engines mean two policies to keep in step. A tool allowed in one and forgotten in the other is refused, which is safe but confusing, so the guard names which engine stopped a call. Order matters too: put the cheap, name-only govern() check first and the kernel, which also reads arguments, second.
Try it yourself
  • Add refund to 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_account message 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.