Skip to main content

Stop an agent at once

Suspend an agent and watch everything that it holds stop working: tokens, approvals in progress and connections.

RecipeDraftView source
This page is a draft. The code exists, and not all of it has been run for this page yet. The page says what was checked.
Works with
lumo CLIPlain HTTPJavaScript / TypeScriptExpress

What it shows​

  1. An agent, "Settlement runner", works in a loop. Before each step it asks LumoAuth whether it may go on.
  2. An administrator suspends the agent, from the lumo CLI or with one call to the Admin API.
  3. 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.
  4. Your services learn about the suspension from a webhook, and drop what they keep for the agent.
  5. 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:read and admin:agents:write. Create it in the portal under Applications & developer tools, API keys.
  • For the CLI version: the lumo CLI. Run lumo login, or set LUMO_API_KEY, LUMO_ORG and LUMO_BASE_URL.
  • Two terminals, both with the variables below.
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_KEYAn API key with the scopes admin:agents:read and admin:agents:write. The curl scripts and the setup script read it.
LUMO_API_KEYFor the lumo CLI, together with LUMO_ORG and LUMO_BASE_URL: the same three values as above. Not needed after lumo login.
AGENT_IDThe ID of the agent (agt_…). The setup script prints it.
AGENT_CLIENT_IDThe client ID of the agent, for the loop. The setup script prints it.
AGENT_CLIENT_SECRETThe client secret of the agent. The setup script prints it once.
WEBHOOK_SECRETFor 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.

agents/kill-switch/cli/suspend.sh
#!/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
agents/kill-switch/cli/reactivate.sh
#!/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.

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:

Output
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.updated for the change of status and agent.credentials_revoked with 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 disable sets the status inactive, not suspended. It stops the agent in the same way.
  • A suspension arrives at a webhook as agent.updated with the new status. agent.revoked arrives 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.