The idea
Some actions should never run on the model’s judgement alone: sending emails, spending money, deleting data, changing production. Human-in-the-loop inserts an approval step: the agent proposes the action, execution pauses, a person approves, edits or rejects, and the run continues.
Implement it at the tool layer, not in the prompt. Mark tools as needing approval; when the model calls one, save state (checkpoint), notify a human with the exact arguments, and resume with their decision as the tool result.
Show approvers exactly what will happen ("Send email to anna@x.com with subject ..."), not a vague summary.
It lets you deploy useful agents before you trust them fully, and it is often a compliance requirement.
Picture it
Words to know
- InterruptA deliberate pause in a run waiting for outside input.
Try it without code
Classify your tools
- List every tool your agent has.
- Mark each as read-only, reversible or irreversible.
- Irreversible ones need approval.
Use it in code
Approval gate around risky tools.
NEEDS_APPROVAL = {"send_email", "delete_file", "create_payment"}
def execute(call, handlers, ask_human):
if call.name in NEEDS_APPROVAL:
decision = ask_human(f"Agent wants to run {call.name} with {call.input}. Approve? [y/N/edit] ")
if decision.lower().startswith("edit"):
call.input.update(parse_edit(decision)) # your own parser, e.g. "edit subject=New title"
elif decision.lower() != "y":
return {"status": "rejected by human", "reason": decision}
return handlers[call.name](**call.input)
# CLI version: ask_human = input. In a web app: checkpoint, notify, resume on click.Add an approval gate to a send_email tool (print instead of sending) and test approve, reject and edit.
Common mistakes
- Relying on the prompt ("ask before sending") instead of code.
- Approval screens that hide the real arguments.