Ending and limiting an AI agent's loop
An AI agent works in a loop. It asks a model what to do next, runs a tool, reads the result and asks again.
When you build your first one, you decide what ends that loop, how far it may run and which steps a person approves first.
Inspect is open-source software for evaluating language models, developed by the UK AI Security Institute and Meridian Labs. Its documentation names each of these parts.
How the loop ends
Inspect's ReAct agent "runs a tool loop until the model calls a special submit() tool indicating it is done". If the model stops calling tools before then, the agent prompts it to carry on or to submit.
The documentation explains the choice. Some loops end as soon as the model stops calling tools, and a model sometimes stops by accident, for example by saying it will call a tool and then not calling it. An explicit submit step lets the agent encourage the model to keep working until it says it has finished.
With the submit tool switched off, the agent ends when the model stops calling tools.
Limits on time, messages and spend
Inspect lets a builder cap a run by clock time, working time, messages, turns, tokens and cost.
A message limit counts every message so far, including the tool results. A turn limit counts calls to the model, and one turn can produce several messages.
Working time leaves out time spent waiting, such as retries after a rate limit. The documentation advises setting a time limit alongside it, so that clock time has a bound too.
A cost limit is worked out from token usage, and it needs cost data for every model in use. In an Inspect evaluation, a sample that reaches a limit exits early and is still scored.
When the context window fills up
An agent that runs long enough may fill the model's whole context window. By default the ReAct agent then stops and logs the reason.
A builder can choose instead to truncate the message history and carry on. Inspect also offers compaction, which manages the context as it grows and helps keep costs and context within limits on long runs.
A person approving some tool calls
Inspect's approval mode supports three arrangements. A human operator can approve every tool call, or only selected ones, with the rest running without approval. Custom approvers can approve, reject or escalate to another approver.
By default the human approver offers three choices: approve, reject or terminate.
The documentation notes that approving every call "can be quite tedious, and not all tool calls are necessarily worthy of human oversight". Its example asks a person to approve shell and Python commands, and lets other calls, such as reading a file, through automatically.
Once approval mode is on, every tool call has to be handled by some approver. Any call left unhandled is rejected.
Useful links
- Using Agents (Inspect, UK AI Security Institute)
- ReAct Agent (Inspect)
- Setting Limits (Inspect)
- Tool Approval (Inspect)
- Inspect (home page)