Skip to main content
Agent-scoped policies let you apply different compliance and enforcement settings to individual agents (identified by nodeId) within the same workspace. When no agent-scoped policy exists, the middleware treats the agent as having no enforcement (allow-all). Having the SDK present is not sufficient without an active policy.

How It Works

The middleware resolves policies using a scope hierarchy:
  1. Base policy: workspace-level policy (no nodeId), applies to all agents by default.
  2. Agent policy: node-specific policy keyed by nodeId, overrides the base policy for that agent.
When the middleware receives a tool call, it resolves the effective nodeId from the runtime agent state header (x-agent-state) and fetches the corresponding policy based on the configured scope.

Configuration

Remote Policy Source (Dynamic)

For production environments, configure the middleware to fetch policies dynamically per nodeId:
These examples focus on policy-source fields. Keep your base middleware options (signer, otel, sec0, and other required fields) from Quickstart.

Local Policy (Static)

For local development or simple setups, pass the policy YAML directly. Note that static policies apply uniformly. Agent scoping requires a remote source that resolves per-nodeId.

Policy Source Options

Scope Behavior

How nodeId Is Resolved

The middleware determines the effective nodeId at runtime using this priority:
  1. Runtime header: extracted from the x-agent-state header on the incoming tool call (set by upstream agent decorators)
  2. Configured default: the nodeId field in the policy source config
  3. None: falls back to base policy (or throws in "agent" scope)

Example: Different Policies Per Agent

A common pattern is giving different agents different compliance rules. For example, an EHR agent may need HIPAA compliance packs while an order agent only needs basic security rules.
With this setup:
  • Tool calls from EhrAgent are enforced with the ehr-agent policy (e.g., HIPAA compliance packs)
  • Tool calls from OrderAgent are enforced with the order-agent policy (e.g., basic security rules)
  • If either agent has no scoped policy, it falls back to the base workspace policy
Having sec0-sdk/middleware in the runtime is not sufficient for enforcement. If the scoped policy for a nodeId is empty and fallbackToBase falls back to an empty base policy, enforcement is effectively off for that agent.