Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Capstone: an agent with safe limits

After this lesson: I can plan an agent with an allowlist, a budget and a human check.

60 min lessonNo commands

An agent that unlocks accounts

An AI agent is a program where a model chooses actions, one step at a time. Because an agent acts, its limits decide how much harm one mistake can do.

Say an IT team wants one that reads a ticket, finds the user and unlocks their account. It could unlock the wrong person, or loop for an hour. In this capstone you plan its limits and review a recorded run.

By the end of this lesson

Note

I can plan an agent with an allowlist, a budget and a human check.

Key words

WordWhat it meansExample
Agenta program where a model chooses actions in steps
Toolone action the agent may ask to rununlock_account
Allowlistthe only tools the agent may use
Budgeta limit on steps or cost
Human checka person approves a risky action first
Run logthe record of every step an agent took

The cells students fill in are left blank in this preview.

Where to go deeper

Note

This capstone plans limits and reviews a run. The AI lessons on the Resources page teach the rest. Building agents. Evaluating agents. Securing agents. Agent safety in depth.

An allowlist says which tools exist

The model may ask for any action it likes. Your code decides what actually runs.

An allowlist is the short list of tools the agent may use. Your program checks every request against it before running anything. Anything not on the list is blocked, however reasonable it sounds. The program below checks a recorded sample of requests.

Try it: block what is not allowed

Code: node
// The agent may only use these tools.
const allowed = ["read_ticket", "look_up_user", "unlock_account", "reply"];

// A recorded sample: the tools the model asked for, in order.
const asked = ["read_ticket", "look_up_user", "delete_user", "unlock_account", "reply"];

for (const tool of asked) {
  if (allowed.includes(tool)) {
    console.log("run   ", tool);
  } else {
    console.log("BLOCK ", tool);
  }
}

// Add "reset_password" to the asked list, then press Run.
// Is it run or blocked? Should it be on the allowlist?

A budget and a person set limits

A budget stops an agent that loops. Five steps is plenty to unlock one account. Past that, the agent stops and hands the ticket to a person.

A human check is for actions that are hard to undo. Unlocking an account changes who can get in, so a person approves it first. Reading a ticket is safe, so it runs at once.

Review a run from its log

Every step goes in a run log: the tool, its input and its result. After a test run, you read the log line by line.

Look for three things. A tool that should not be there. Steps past the budget. A risky step with no approval. The program prints a recorded run with notes beside each step.

Try it: review a recorded run

Code: python
# A recorded run of the help desk agent. Budget: 5 steps.
run = ["read_ticket", "look_up_user", "unlock_account",
       "look_up_user", "unlock_account", "reply"]
BUDGET = 5
RISKY = ["unlock_account"]

step = 1
for tool in run:
    note = ""
    if tool in RISKY:
        note = "needs a person to approve"
    if step > BUDGET:
        note = "over budget"
    print(step, tool, note)
    step = step + 1

# Change BUDGET to 6 and run it again.

A common mistake

Warning

Many people think a clear line in the prompt, such as "never delete accounts", keeps an agent safe. A prompt is a request, and a model can ignore it. Put every limit in code, where it is checked before each tool runs.

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.