Skip to Content
AgentShield
Fundamentals

Policy Evaluation

The policy document format, the precedence rules that combine organization and agent policies, resource rules, and an interactive playground.

AgentShield's evaluator is a pure Go function in runtime/policy-engine. Given the active organization policy, the active agent policy, an action, and a resource, it returns one decision. It does not read the clock, the network, the agent row, or any score, so the same inputs always produce the same answer.

The policy document

{
  "agent": { "id": "customer-support-agent" },
  "permissions": {
    "allowed": ["tickets.read", "knowledge.search", "customer.profile.read"],
    "denied": ["database.export", "customer.delete"],
    "approval_required": ["customer.update", "payment.refund", "email.send"]
  },
  "resource_rules": [
    { "effect": "deny", "action": "tickets.read", "resource": "ticket:vip-001" }
  ]
}
FieldRules
permissions.allowed, denied, approval_requiredRequired arrays (may be empty). Each action matches ^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)+$, at most 128 characters
—An action may appear in only one of its document's three lists. A duplicate is a validation error
resource_rules[]Optional. effect is allow, deny, or require_approval. action must be in this document's allowed list. resource is 1–512 characters
agent.idOptional label, 1–128 characters

Unknown fields anywhere are rejected. The JSON Schema is published at docs/schemas/policy.schema.json, and the control plane validates documents with the same rules before storing them.

Precedence

Both documents are consulted together. The first rule that applies wins:

Deny. If the action is in either document's denied list, the outcome is deny (matched_rule: denied:<action>).

Approval. Otherwise, if it is in either document's approval_required list, the outcome is require_approval.

Allow. Otherwise, if it is in either document's allowed list, resource rules are applied (below). With no resource rules for the action, the outcome is allow.

Default deny. Otherwise the outcome is deny with the reason default deny, or no active policy when neither document exists.

Consequences of this order:

  • An organization deny cannot be overridden by an agent allow.
  • An agent policy can be stricter than the organization by adding a deny or an approval.
  • An agent policy can add allows the organization does not list, but it cannot remove an organization deny or approval.
  • Document order never matters. There is no "first matching rule".

Resource rules

Resource rules narrow an action that is already allowed. They compare resource exactly; there are no wildcards or prefixes.

For an allowed action, the evaluator collects rules from both documents whose action matches and whose resource equals the request's resource:

  1. A matching deny rule → deny (resource:deny:<resource>).
  2. Else a matching require_approval rule → require_approval.
  3. Else, if no allow rule exists for this action, the plain allow stands.
  4. Else, if a matching allow rule exists → allow (resource:allow:<resource>).
  5. Else → deny with resource not permitted.

In other words, once any allow resource rule names an action, that action becomes an allow-list of exact resources.

Resource rules cannot grant

A resource rule whose action is not in its own document's allowed list is rejected at validation. Resource rules can never turn a denied or unlisted action into an allow.

To allow a whole host for http.request, list the host in the gateway's tools file and allow the operation (for example http.get) without resource rules. Use resource rules to pin specific URLs.

Explanations

Every decision explains itself:

matched_rulereason
denied:<action>explicit deny
approval_required:<action>approval required
allowed:<action>allowed
resource:deny:<resource>resource denied
resource:require_approval:<resource>resource requires approval
resource:allow:<resource>resource allowed
(none)default deny, no active policy, resource not permitted, operation is not a policy action

policy_id and policy_version identify the document that produced the outcome.

Try it

Policy evaluation playground

Simulation

Runs in your browser with a port of the gateway's evaluator. It does not contact an AgentShield gateway, and its output is illustrative. The gateway you deploy is the only source of real decisions.

Request
Identity and limits
Active policies

HTTP 200 · decision recorded and audited

allow

  1. 1.Verify Ed25519 signature

    Signature over timestamp.nonce.sha256(body) verifies. Timestamp is inside the 60 s window.

  2. 2.Reserve nonce in Redis

    Nonce reserved for 130 seconds.

  3. 3.Charge request, tool, and token budgets

    Within 60 requests, 30 calls per tool, and 100,000 tokens per minute.

  4. 4.Check agent and credential status

    Agent and credential are active. The organization claim matches the agent record.

  5. 5.Evaluate policy

    Matched allowed:tickets.read in the organization policy.

Response body (shape)

{
  "decision_id": "7f1c…",
  "outcome": "allow",
  "explanation": {
    "matched_rule": "allowed:tickets.read",
    "reason": "allowed"
  }
}

Next: Execute may now run this decision once through its registered adapter.

Validation on every call

The evaluator re-validates both documents on every evaluation, even though the control plane validated them when they were stored. A stored document that somehow bypassed validation causes an evaluation error, which the gateway records as deny. Benchmarks put this at roughly 10–14 µs for a typical policy, small next to the database round trips on the same path.

Why not OPA?

The policy model is small and fixed: three lists and exact resource rules. An in-process Go function keeps evaluation on the hot path without a sidecar whose outage would have to fail closed, and keeps the rules readable by the people who review them. The decision type is the extension point: a future evaluator, including one backed by OPA, must preserve these precedence rules and default deny.

Was this page helpful?

On this page