Stop an agent at once
Suspend an agent and watch everything that it holds stop working: tokens, approvals in progress and connections.
What it shows
- An agent, "Settlement runner", works in a loop. Before each step it asks LumoAuth whether it may go on.
- An administrator suspends the agent, from the lumo CLI or with one call to the Admin API.
- The next step of the agent is refused with
401. The agent still holds the token from its first step, and that token has not expired. - Your services learn about the suspension from a webhook, and drop what they keep for the agent.
- The administrator brings the agent back. The agent then requests a new token.
In the same step as the change of status, LumoAuth revokes what the agent holds: its access tokens, its just-in-time requests and tokens, its place on connections of the token vault and its keys at AI gateways.
Before you start
- An agent in the registry, and its client ID and secret. The setup script registers the agent and prints the values.
- An API key with the scopes
admin:agents:readandadmin:agents:write. Create it in the portal under Applications & developer tools, API keys. - For the CLI version: the lumo CLI. Run
lumo login, or setLUMO_API_KEY,LUMO_ORGandLUMO_BASE_URL. - Two terminals, both with the variables below.
| Variable | Value |
|---|---|
LUMOAUTH_URL | The address of LumoAuth: https://app.lumoauth.dev, or https://eu.app.lumoauth.dev for the EU region. |
LUMOAUTH_ORG_ID | Your organization, for example acme-corp. |
LUMOAUTH_API_KEY | An API key with the scopes admin:agents:read and admin:agents:write. The curl scripts and the setup script read it. |
LUMO_API_KEY | For the lumo CLI, together with LUMO_ORG and LUMO_BASE_URL: the same three values as above. Not needed after lumo login. |
AGENT_ID | The ID of the agent (agt_…). The setup script prints it. |
AGENT_CLIENT_ID | The client ID of the agent, for the loop. The setup script prints it. |
AGENT_CLIENT_SECRET | The client secret of the agent. The setup script prints it once. |
WEBHOOK_SECRET | For the webhook handler: the signing secret of your webhook. LumoAuth shows it once, when you create the webhook. |
The setup script creates what the recipe needs, through the Admin API. You can run it again at any time.
node agents/kill-switch/setup.mjs
setup.mjs
// Registers the agent of the recipe, "Settlement runner", and prints its
// client ID and secret. Run it again at any time.
//
// node agents/kill-switch/setup.mjs
//
// The API key needs the scopes admin:agents:read and admin:agents:write.
import { call, list, printEnv } from '../../_lib/admin.mjs';
const name = 'Settlement runner';
const capabilities = ['payments:settle'];
let agent = (await list('/admin/agents')).find((a) => a.name === name);
let secret;
if (agent) {
// A run of the recipe can leave the agent suspended. Bring it back, then
// make a new secret: LumoAuth shows a secret once.
await call('POST', `/admin/agents/${agent.agentId}/enable`);
secret = (await call('POST', `/admin/agents/${agent.agentId}/rotate-credentials`)).data.clientSecret;
} else {
agent = (
await call('POST', '/admin/agents', {
name,
description: 'Settles the open payments of each day.',
identityType: 'client_secret',
capabilities,
})
).data;
secret = agent.clientSecret;
}
console.log(`Agent "${name}" (${agent.agentId}) is active.`);
printEnv({ AGENT_ID: agent.agentId, AGENT_CLIENT_ID: agent.agentId, AGENT_CLIENT_SECRET: secret });
Code
Start the agent in the first terminal, with the command of the tab Node.js: the agent. After a few steps, run the suspend script of the lumo CLI tab or of the curl tab in the second terminal. Run the reactivate script of the same tab afterwards.
Run each command from the recipes folder of the examples repository. Set the folder up once for your language. Run the agent in one terminal, and suspend it from a second terminal with the lumo CLI or with curl.
- lumo CLI
- curl
- Node.js: the agent
- Node.js: the webhook handler
#!/bin/sh
# An administrator suspends the agent, with the lumo CLI.
#
# sh agents/kill-switch/cli/suspend.sh
set -eu
# The status becomes "suspended". In the same step LumoAuth revokes the
# tokens, the approvals and the gateway keys that the agent holds.
lumo api POST "/agents/$AGENT_ID/disable"
lumo agents get "$AGENT_ID" --output json
#!/bin/sh
# An administrator brings the agent back, with the lumo CLI.
#
# sh agents/kill-switch/cli/reactivate.sh
set -eu
# The status becomes "active". Nothing that the suspension revoked comes
# back: the agent requests a new token.
lumo agents enable "$AGENT_ID"
sh agents/kill-switch/cli/suspend.sh
Run against a LumoAuth organization.
#!/bin/sh
# An administrator suspends the agent, with curl.
#
# sh agents/kill-switch/http/suspend.sh
set -eu
# The status becomes "suspended". In the same step LumoAuth revokes the
# tokens, the approvals and the gateway keys that the agent holds.
curl --silent --show-error --request POST \
"$LUMOAUTH_URL/orgs/$LUMOAUTH_ORG_ID/api/v1/admin/agents/$AGENT_ID/disable" \
--header "X-API-Key: $LUMOAUTH_API_KEY"
echo
#!/bin/sh
# An administrator brings the agent back, with curl.
#
# sh agents/kill-switch/http/reactivate.sh
set -eu
# The status becomes "active". Nothing that the suspension revoked comes
# back: the agent requests a new token.
curl --silent --show-error --request POST \
"$LUMOAUTH_URL/orgs/$LUMOAUTH_ORG_ID/api/v1/admin/agents/$AGENT_ID/enable" \
--header "X-API-Key: $LUMOAUTH_API_KEY"
echo
sh agents/kill-switch/http/suspend.sh
Run against a LumoAuth organization.
// The agent works in a loop. Before each step it asks LumoAuth, so it stops
// within one step when an administrator suspends it.
//
// node agents/kill-switch/js/loop.mjs
import { setTimeout as sleep } from 'node:timers/promises';
import { LumoAgent } from '@lumoauth/agent';
// Reads LUMOAUTH_URL, LUMOAUTH_ORG_ID, AGENT_CLIENT_ID and AGENT_CLIENT_SECRET.
const agent = new LumoAgent();
for (let step = 1; ; step++) {
try {
// The agent got its token once, at the first step. The token stays valid
// for about an hour, but LumoAuth checks the agent on every request.
const answer = await agent.ask('payments:settle', { batch: step });
console.log(`step ${step}: ${answer.allowed ? 'allowed' : 'denied'}`);
} catch (error) {
console.log(`step ${step}: refused with ${error.statusCode} (${error.message})`);
console.log('The agent stops.');
break;
}
await sleep(2000);
}
node agents/kill-switch/js/loop.mjs
Run against a LumoAuth organization.
// Your service learns from a webhook that an agent was stopped.
//
// node agents/kill-switch/js/webhook.mjs
import { createHmac, timingSafeEqual } from 'node:crypto';
import express from 'express';
// The signing secret of the webhook. LumoAuth shows it once, when you create
// the webhook. `lumo tunnel` forwards events without a signature, so leave
// the variable unset only for local work with the tunnel.
const secret = process.env.WEBHOOK_SECRET;
if (!secret) console.warn('WEBHOOK_SECRET is not set: this handler accepts unsigned events.');
// X-LumoAuth-Signature: kid=v1,t=<time>,id=<delivery ID>,v1=<HMAC>
// The HMAC covers "<t>.<id>.<raw body>".
function signed(rawBody, header) {
const parts = Object.fromEntries(header.split(',').map((field) => field.split(/=(.*)/s).slice(0, 2)));
const expected = createHmac('sha256', secret).update(`${parts.t}.${parts.id}.${rawBody}`).digest();
const given = Buffer.from(parts.v1 ?? '', 'hex');
return given.length === expected.length && timingSafeEqual(given, expected);
}
const app = express();
// express.raw keeps the bytes of the body, which the signature covers.
app.post('/webhooks/lumoauth', express.raw({ type: 'application/json' }), (req, res) => {
if (secret && !signed(req.body, req.get('X-LumoAuth-Signature') ?? '')) {
return res.status(401).end();
}
const { event, data } = JSON.parse(req.body);
const status = data.metadata?.status;
// A suspension arrives as agent.updated with the new status. agent.revoked
// arrives when an agent is revoked for good or deleted.
if (event === 'agent.revoked' || (event === 'agent.updated' && status !== 'active')) {
console.log(`${event}: agent ${data.target_id} is ${status}. Drop its sessions and cached tokens here.`);
} else {
console.log(`${event}: nothing to do`);
}
res.status(204).end();
});
const port = Number(process.env.PORT ?? 3000);
app.listen(port, () => console.log(`Waiting for webhooks on http://localhost:${port}/webhooks/lumoauth`));
node agents/kill-switch/js/webhook.mjs
Compiles. Not run against an organization. The handler was tested with requests that were signed locally in the documented format. It received no event from LumoAuth: the test organization delivered no webhooks.
To try the webhook handler, start it and forward the events of your organization to it with lumo tunnel --to http://localhost:3000/webhooks/lumoauth. The tunnel forwards events without a signature, so leave WEBHOOK_SECRET unset for that test. For a deployed service, create a webhook for the events agent.updated and agent.revoked in the portal or with POST /admin/webhooks, and set WEBHOOK_SECRET to its signing secret.
Check the result
The first terminal:
step 1: allowed
step 2: allowed
step 3: allowed
step 4: refused with 401 (Authentication failed — check your access token.)
The agent stops.
- The suspend script prints the agent with
"status": "suspended". - Open Audit logs in the portal. The suspension wrote
agent.updatedfor the change of status andagent.credentials_revokedwith a count for each kind of credential. - In the portal, the same action is the Suspend button on the page of the agent, under AI Agents, Agents.
Limits
- Reactivation restores nothing. Tokens, approvals and gateway keys that the suspension revoked stay revoked.
lumo agents disablesets the statusinactive, notsuspended. It stops the agent in the same way.- A suspension arrives at a webhook as
agent.updatedwith the new status.agent.revokedarrives when an agent is revoked for good or deleted. A revoked agent cannot be reactivated. - A service that verifies the tokens of the agent offline, with the public keys alone, accepts a token until it expires. Such a service needs the webhook, a security event or token introspection.