Skip to main content

Approve routine requests by rule

Let a rule approve the requests that are always fine, so that people see only the ones that need a decision.

RecipeReadyView source
Works with
Plain HTTP

What it shows​

  1. An agent may read and write invoices. A request to write still waits for a person, because a write is medium risk.
  2. You write a rule in the portal: for this agent, the type invoices and the action write are approved.
  3. A request inside the rule is approved at once, and the portal records which rule did it.
  4. A request with an action that the rule does not name waits for a person.
  5. A request to delete waits for a person, whatever a rule says.

A rule stands in for the person who wrote it. It works for a limited time, 7 days at most.

Before you start​

  • An agent whose capabilities cover the action of the rule. The setup script registers the agent "Bookkeeping agent" with the capabilities invoices:read and invoices:write.
  • The owner of an agent cannot write a rule for that agent, and the owner is the person who registered it. The setup script therefore makes a second user, Maya Chen, the owner. You can then write the rule as the administrator.
  • Check that your plan includes just-in-time permissions in the plans matrix.
VariableValue
LUMOAUTH_URLThe address of LumoAuth: https://app.lumoauth.dev, or https://eu.app.lumoauth.dev for the EU region.
LUMOAUTH_ORG_IDYour organization, for example acme-corp.
LUMOAUTH_API_KEYFor the setup script only: an API key with the scopes admin:agents:read, admin:agents:write and admin:users:write. The agent itself needs no API key.
AGENT_CLIENT_IDThe client ID of the agent, which is its agent ID (agt_…). The setup script prints it.
AGENT_CLIENT_SECRETThe client secret of the agent. The setup script prints it.

The setup script creates what the recipe needs, through the Admin API. You can run it again at any time.

node approvals/auto-approve-rules/setup.mjs
setup.mjs
// Creates what the recipe needs: an agent that may read and write invoices,
// and a user who owns it. Run it again at any time.
//
// node approvals/auto-approve-rules/setup.mjs
//
// The API key needs the scopes admin:agents:read, admin:agents:write and
// admin:users:write.
import { randomBytes } from 'node:crypto';
import { call, ensure, printEnv } from '../../_lib/admin.mjs';

const agent = await ensure('/admin/agents', (a) => a.name === 'Bookkeeping agent', {
name: 'Bookkeeping agent',
description: 'Reads invoices and corrects them.',
identityType: 'client_secret',
// A rule approves only what is inside the capabilities of the agent.
capabilities: ['invoices:read', 'invoices:write'],
});

// LumoAuth shows a secret once, in the answer that creates it. On a second
// run the script therefore asks for a new secret, and the old one stops.
const secret =
agent.clientSecret ??
(await call('POST', `/admin/agents/${agent.agentId}/rotate-credentials`)).data.clientSecret;

// The owner of an agent cannot write a rule for it, and the agent belongs to
// the person who created it: you. Give it to another person, so that you can
// write the rule in the portal.
const owner = await ensure('/admin/users', (u) => u.email === 'maya.chen@example.com', {
email: 'maya.chen@example.com',
name: 'Maya Chen',
// The recipe never signs in as this user, so nobody needs the password.
password: `${randomBytes(18).toString('base64url')}#Aa1`,
emailVerified: true,
});
await call('PATCH', `/admin/agents/${agent.agentId}`, { ownerId: owner.id });

console.log(`Agent "${agent.name}" is ready. Its owner is ${owner.email}.`);
printEnv({ AGENT_CLIENT_ID: agent.agentId, AGENT_CLIENT_SECRET: secret });

Then write the rule in the portal:

  1. Go to AI Agents, then Agent rules, and open the tab Auto-approve rules.
  2. Click Create rule.
  3. Under Agent, choose "Bookkeeping agent".
  4. Under Authorization type, enter invoices.
  5. Under Actions the rule may approve, enter write.
  6. Under Expires in, keep "1 day", and click Create rule.

The list now shows the rule with an ID that starts with aap_.

Code​

The agent needs no change for a rule. It sends the same request as in Ask a person for a permission, for one task, and the answer says approved or pending.

Run each command from the recipes folder of the examples repository. Set the folder up once for your language. Every version below was run against a LumoAuth organization. The script was run before the rule existed and after it was created in the portal.

approvals/auto-approve-rules/http/requests.sh
#!/bin/sh
# An agent sends three requests. A rule approves the first one at once, and
# the other two wait for a person. Needs curl and jq.
#
# sh approvals/auto-approve-rules/http/requests.sh
set -eu

API="$LUMOAUTH_URL/orgs/$LUMOAUTH_ORG_ID/api/v1"

# The agent signs in with its ID and its secret.
AGENT_TOKEN=$(curl --silent --show-error --fail "$API/oauth/token" \
--user "$AGENT_CLIENT_ID:$AGENT_CLIENT_SECRET" \
--data "grant_type=client_credentials" | jq -r .access_token)

post() {
curl --silent --show-error "$API$1" \
--header "Authorization: Bearer $AGENT_TOKEN" \
--header "Content-Type: application/json" \
--data "$2"
}

TASK_ID=$(post /jit/task '{"name": "Correct invoice INV-7741", "type": "finance"}' | jq -r .task_id)

# Sends one request and prints the answer. The answer comes at once: this
# script does not wait for a person.
request() {
post /jit/request "{
\"task_id\": \"$TASK_ID\",
\"authorization_details\": {\"type\": \"invoices\", \"actions\": $1, \"identifier\": \"INV-7741\"},
\"justification\": \"The total of INV-7741 is wrong.\"
}" | jq -r --argjson actions "$1" '"invoices \($actions | join(",")): \(.status), risk \(.risk_level)"'
}

# The rule names the action "write": approved with no person.
request '["write"]'
# The rule must cover every action of a request. It does not name "read".
request '["read", "write"]'
# A delete is high risk. No rule approves it.
request '["delete"]'

# The end of the task also closes the two requests that still wait.
post "/jit/task/$TASK_ID/complete" '{}' > /dev/null
echo "task: completed"
sh approvals/auto-approve-rules/http/requests.sh

Check the result​

Output
invoices write: approved, risk medium
invoices read,write: pending, risk medium
invoices delete: pending, risk high
task: completed
  • Run the script before you create the rule: the first line also says pending.
  • In the portal, open AI Agents, then Approvals, and the tab Approved. The first request shows "Auto-approved by rule" and the ID of the rule.
  • Open Audit logs under Security. The approval is the event jit.permission_policy_approved.
  • To stop a rule, open the menu … of its row and click Revoke. The next request waits for a person again.

Limits​

  • A rule matches a type and a list of actions, for one agent or for every agent. It cannot read an amount or the identifier of a record.
  • A rule approves only requests of medium risk. Today those are the requests with a write action. Requests with a delete, admin, execute, transfer, publish or rotate action always wait for a person.
  • No rule can exist for the types payment, user_data, credentials and admin_action.
  • A rule never approves a request that is outside the capabilities of the agent, or that carries privileges.
  • Read-only requests inside the capabilities of the agent need no rule: LumoAuth approves them at once.
  • The answer to the agent does not name the rule. The portal and the audit log do.
  • Rules are written in the portal. The API has no call for them.