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.
Before you begin
Section titled “Before you begin”- 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.
How it works
Section titled “How it works”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.
Or the request waits for the owner
Section titled “Or the request waits for the owner”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.1Host: foobar.cvyuh.comContent-Type: application/x-www-form-urlencodedDPoP: 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 RequestContent-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.1Host: foobar.cvyuh.comContent-Type: application/x-www-form-urlencodedDPoP: 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 itsclient_notification_tokenas 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 isaccess_denied.
Set it up
Section titled “Set it up”With the admin API (Call the API shows how to get $CVYUH_SESSION):
-
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 } } }' -
Make sure each agent that may need approval has a business owner.
-
To let requests wait instead of failing, add
urn:ietf:params:oauth:grant-type:deferredto the realm’s and the agent’s client’sgrantTypes.
Good to know
Section titled “Good to know”- 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 meansaccess_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.
Limits and defaults
Section titled “Limits and defaults”| What | Default | Range |
|---|---|---|
| Guardrails per risk class | None: no limit | — |
maxTokenSecs | — | At least 60 seconds |
How long a held request waits (cibaLifetimeSecs) | 300 seconds | 60 to 1800 |
The least time between polls (cibaPollIntervalSecs) | 5 seconds | — |
| Requests waiting on one owner | — | Twenty; past that, new ones are refused access_denied |
What the agent and its owner see
Section titled “What the agent and its owner see”- The agent asking for a held scope gets
interaction_required, or, with the deferred grant, adeferral_codeto 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.
Audit record
Section titled “Audit record”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.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Cause | Fix |
|---|---|---|
An agent is refused unauthorized_client asking for a held scope | It has no business owner | Give the agent an owner |
A held request is access_denied at once | Its owner already has twenty requests waiting | The owner answers some, or you give the agent another owner |
completion_mode=deferred is ignored, and the agent gets interaction_required | The deferred grant isn’t offered to the realm or the agent’s client | Add urn:ietf:params:oauth:grant-type:deferred to both grantTypes |
| An agent’s tokens last longer than you set | The agent’s risk class has no entry, or another class than you expect | Check the agent’s risk class |
Reference
Section titled “Reference”Errors while polling
Section titled “Errors while polling”| Error | When |
|---|---|
authorization_pending, slow_down | The owner hasn’t answered yet, or the agent polled too soon |
access_denied | The owner refused, or the code was revoked |
expired_token | The request ran out before the owner answered |
invalid_grant | The 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_client | The client isn’t an agent’s |
Settings
Section titled “Settings”| Where | Setting | What it does |
|---|---|---|
Realm, agentSettings | agentGuardrails | A map from risk class to { maxTokenSecs, requireApproval }. Empty by default |
| Realm and client | grantTypes include urn:ietf:params:oauth:grant-type:deferred | Lets a held request wait for the owner. Off by default |
| Realm | cibaLifetimeSecs | How long a held request waits (default 300; from 60 to 1800) |
| Realm | cibaPollIntervalSecs | The least time between polls (default 5) |
| Client | deferredClientNotificationEndpoint | Where the client is told a held request was answered |
Related
Section titled “Related”- Have an agent ask its owner: the task, from both sides.
- Bounded approvals: the owner approves one exact action.
- Issuance policy: rules by risk class over every token.