Skip to content
GatewayMarkdown

Agent guardrails

Give riskier agents shorter-lived tokens, and hold the scopes you name until the agent's business owner approves.

AvailableAPIDeferred Token Response (draft)

For each risk class an agent can have (see AI agents), you can cap how long an agent’s access tokens live, and name scopes an agent of that class gets only once its business owner approves. Use them to give high-risk agents short-lived tokens, and to keep sensitive actions, such as payments or deleting data, behind a human’s yes.

The realm applies them at every token request an agent makes, on its own account or acting for a user. A risk class with no entry has neither limit. Guardrails are applied by the realm, so they need no gateway.

  • A realm administrator in a group holding RealmOwner, to set the guardrails, with the API.
  • Agents with a risk class, set on each agent: see AI agents.
  • A business owner for every agent that may need approval.

For each risk class, agentSettings.agentGuardrails holds:

  • maxTokenSecs: the longest an access token for an agent of that class may live. At least 60 seconds.
  • requireApproval: scopes an agent of that class gets only after its business owner approves.

When such an agent asks for a listed scope, the request is answered interaction_required. The agent then asks its owner through backchannel authentication, and the owner approves on their Approvals page.

An agent’s client that may use the deferred grant can ask the realm to hold the request instead, by sending completion_mode=deferred. This works for its own client_credentials request and for a token exchange:

POST /oauth2/token HTTP/1.1
Host: foobar.cvyuh.com
Content-Type: application/x-www-form-urlencoded
DPoP: eyJ…
grant_type=client_credentials&scope=payments:send&completion_mode=deferred
&client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer&client_assertion=eyJ…

In place of interaction_required, the request is held and answered with a deferral_code, how long it may be polled (expires_in) and how often (interval):

HTTP/1.1 400 Bad Request
Content-Type: application/json
{ "error": "authorization_pending", "deferral_code": "8kq2…", "expires_in": 300, "interval": 5 }

It waits on the owner’s Approvals page beside backchannel requests. The agent polls every interval seconds under the same DPoP key:

POST /oauth2/token HTTP/1.1
Host: foobar.cvyuh.com
Content-Type: application/x-www-form-urlencoded
DPoP: eyJ…
grant_type=urn:ietf:params:oauth:grant-type:deferred&deferral_code=8kq2…
&client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer&client_assertion=eyJ…

Once the owner allows it, the poll returns the token the request was held for: the agent’s own for client_credentials, or the delegated token naming the user and the agent for a token exchange.

  • Told when it’s answered. A client that registers a deferredClientNotificationEndpoint (https, at a public host) is called once the owner answers, with the code, and with its client_notification_token as a Bearer token when it gave one. It still polls for the token. No call goes when a request expires unanswered.
  • Canceled by revoking the code at the revocation endpoint, with token_type_hint=urn:ietf:params:oauth:token-type:deferral-code. The next poll is access_denied.

With the admin API (Call the API shows how to get $CVYUH_SESSION):

  1. Set the guardrails per risk class:

    Terminal window
    curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/agentSettings/agentSettings \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{ "agentGuardrails": {
    "high": { "maxTokenSecs": 120, "requireApproval": ["payments:send", "records:delete"] },
    "limited": { "maxTokenSecs": 300 } } }'
  2. Make sure each agent that may need approval has a business owner.

  3. To let requests wait instead of failing, add urn:ietf:params:oauth:grant-type:deferred to the realm’s and the agent’s client’s grantTypes.

  • Collected once. If the same code is collected twice, the second poll is refused invalid_grant, and the token the first poll got stays valid.
  • A held exchange stands only with its subject. The token it was made from must still be valid when the agent collects, and revoking that token later revokes the collected one too. The agent must also still be allowed to act for the user.
  • Canceling doesn’t recall a token. A token the agent already collected for a code stays valid after the code is revoked: revoke it on its own.
  • An owner is needed. When a request is first held, an agent with no business owner is refused unauthorized_client, and an owner who already has twenty requests waiting means access_denied.
  • No interactive mode. The approver is the agent’s owner, who answers in their own inbox, so there’s no page for the agent to send anyone to.
WhatDefaultRange
Guardrails per risk classNone: no limit—
maxTokenSecs—At least 60 seconds
How long a held request waits (cibaLifetimeSecs)300 seconds60 to 1800
The least time between polls (cibaPollIntervalSecs)5 seconds—
Requests waiting on one owner—Twenty; past that, new ones are refused access_denied
  • The agent asking for a held scope gets interaction_required, or, with the deferred grant, a deferral_code to poll. Asking for a token longer than its class allows, it gets a token that lives only as long as the class allows.
  • The owner sees the request on their Approvals page, with the agent and the scopes it asked for, and allows or refuses it. See Have an agent ask its owner.

Every token request an agent makes, issued or refused by a guardrail, is a TOKEN_ISSUED record, or TOKEN_EXCHANGED for a token exchange, with what was asked and why it was refused. Changing the guardrails is a PATCHED record for agentSettings. See What is recorded.

SymptomCauseFix
An agent is refused unauthorized_client asking for a held scopeIt has no business ownerGive the agent an owner
A held request is access_denied at onceIts owner already has twenty requests waitingThe owner answers some, or you give the agent another owner
completion_mode=deferred is ignored, and the agent gets interaction_requiredThe deferred grant isn’t offered to the realm or the agent’s clientAdd urn:ietf:params:oauth:grant-type:deferred to both grantTypes
An agent’s tokens last longer than you setThe agent’s risk class has no entry, or another class than you expectCheck the agent’s risk class
ErrorWhen
authorization_pending, slow_downThe owner hasn’t answered yet, or the agent polled too soon
access_deniedThe owner refused, or the code was revoked
expired_tokenThe request ran out before the owner answered
invalid_grantThe code is unknown, was issued to another client, or was already collected; the poll is under another DPoP key; or, for a held exchange, the subject token was revoked or has expired, or the agent may no longer act for the user
unauthorized_clientThe client isn’t an agent’s
WhereSettingWhat it does
Realm, agentSettingsagentGuardrailsA map from risk class to { maxTokenSecs, requireApproval }. Empty by default
Realm and clientgrantTypes include urn:ietf:params:oauth:grant-type:deferredLets a held request wait for the owner. Off by default
RealmcibaLifetimeSecsHow long a held request waits (default 300; from 60 to 1800)
RealmcibaPollIntervalSecsThe least time between polls (default 5)
ClientdeferredClientNotificationEndpointWhere the client is told a held request was answered