Skip to main content

Policy Configuration

Policy groups control what flows through the relay. Each policy group is a Rego file (Open Policy Agent’s policy language) that defines which middleware rules to apply. Rego gives you conditional logic, time-based gating, and the ability to combine multiple rules in a single group. Policy groups are applied through a two-step process:
  1. Create a policy group with Rego source that defines the middleware rules
  2. Create a policy binding that attaches the group to a tenant, agent, or subscription

How the Middleware Pipeline Works

Every middleware rule specifies which legs of this flow it applies to via enabledLegs:
At least one leg must be enabled. The API will reject a policy where all four legs are false.

How Evaluation Works

When a message flows through the relay:
  1. The system finds all active bindings that match the current tenant, agent, and subscription
  2. For each binding, the associated policy group’s Rego file is evaluated with the request context as input
  3. The Rego file returns a list of middleware configs to execute
  4. Each middleware config is instantiated and executed in the specified order
  5. If any middleware returns BLOCK, the message is rejected
Bindings are evaluated in priority order (lower number = higher priority). Within a group, middlewares are ordered by their order field.

Rego File Structure

Every policy group’s Rego file must follow this structure:

Middleware Types

Skill Restriction

Control which skills an agent is allowed to use. You can allowlist or blocklist skills by ID, name, or tag.
At least one of skillIds, skillNames, or skillTags must be non-empty. Use ALLOWLIST mode for high-security environments where agents should only use explicitly approved skills.

Regex Detection

Match message content against a regular expression.

PII Detection (Presidio)

Detect personally identifiable information using Microsoft Presidio.

PII Detection (AWS Comprehend)

Detect PII using AWS Comprehend.

Rate Limiting

Throttle request volume. Three strategies are available: Sliding Window:
Token Bucket:
Leaky Bucket:

Human-in-the-Loop (HITL)

Pause messages for manual human approval before they reach the target agent.
See the Human-in-the-Loop tutorial for the complete approval workflow.

Conditional Logic with Rego

This is where OPA’s power comes in. Instead of static rules, you can use Rego’s if statements to activate rules conditionally based on the request context, time of day, day of week, and more.

Available Input Context

Every Rego evaluation receives this input:

Time-Based Activation

Activate rules only during specific time windows using OPA’s built-in time.* functions with input.timestampNanos:

Combining Always-On and Conditional Rules

Rego uses AND logic within a single if block (all conditions must be true). For OR logic, define multiple middlewares contains blocks with the same middleware config but different conditions - if any block matches, the middleware is included.

Negation

Apply rules when a condition is NOT met:

Common Time-Gating Patterns

Business hours only (Mon-Fri 09:00-17:00 UTC):
Weekdays only:
Date-range / maintenance window:
Agent-specific conditions:

Future Possibilities

Rego supports many more patterns that can be used as we enrich the input context:
  • Tenant-specific overrides - different rules per tenant ID
  • Agent metadata matching - rules based on agent properties like name and group
  • Dynamic config values - threshold values computed from input data

Policy Actions

Every detection rule requires an action that determines what happens when a match is found:

Creating a Policy Group

The Rego source is validated before saving:
  • Rego syntax is checked
  • Each middleware config is validated against its type-specific schema
  • Invalid configs are rejected with detailed error messages

Testing Before Saving

Use the evaluate endpoint to dry-run your Rego without creating a group:
For time-gated policies, pass a timestamp to test at a specific point in time. When omitted, the current server time is used:

Policy Bindings

Bindings attach a policy group to a scope. Three levels are available:
When multiple bindings apply to a message, they are evaluated in priority order (lower number = higher priority). Within each binding’s policy group, middlewares execute in order field sequence. All matching middlewares from all applicable bindings are applied.

Evaluation Order

All middlewares from all matching bindings execute in this sequence. If any middleware returns BLOCK, the chain short-circuits and the message is rejected.

Create Bindings

Tenant-level (applies to all agents):
Agent-level (applies to a specific agent):
Subscription-level (applies to a specific source -> sink path):

Versioning

Both policy groups and bindings are versioned using semantic versioning (e.g. 1.0.0, 2.0.0).
  • Updating a group creates a new version. The old version is disabled automatically.
  • Upgrading a binding points it to the latest group version via POST /v1/policy-bindings/{id}/upgrade.
  • Version history is available via GET /v1/policy-groups/{id}/history.

Ownership

Every policy group has a primary owner and an optional secondary owner (escalation contact). Ownership can be transferred via POST /v1/policy-groups/{id}/transfer-ownership.

Example: Full Setup

That’s it - two API calls instead of four. The Rego file contains all your rules.

Next Steps

Human-in-the-Loop

Set up manual approval workflows for sensitive operations.

Monitoring & Audit

View policy enforcement events and audit trails.