Sub topic 3
Waiting for Humans: Timeouts and Escalation
Assume you understand how an agent calls tools, reads JSON, and runs as a background job. This chapter focuses on what happens when an approval request waits longer than expected.
Timeouts and escalation
An approval request should have an expiry time. A stale request must not execute automatically. After expiry, the workflow can cancel the action, notify another reviewer, or escalate to an on-call team.
import time
def resolve(request, decision):
if time.time() > request["expires_at"]:
return {"status": "expired"}
if decision not in {"approve", "reject", "edit"}:
raise ValueError("Unknown decision")
return {"status": decision, "call": request["call"]}
request = {
"call": {"name": "send_email", "args": {"to": "[email protected]"}},
"expires_at": time.time() + 300,
}
print(resolve(request, "reject"))A background worker can check expired requests regularly. Escalation should preserve the original request and record who received each notification.
Safe auto-approval and fatigue
Policy rules can auto-approve low-risk, reversible actions such as reading approved documentation. Unknown tools should require approval. High-impact or irreversible actions, such as deleting data or sending external messages, should normally require a human.
Approval fatigue occurs when reviewers receive too many similar prompts and approve without checking. Show only relevant details, group safe operations, set useful thresholds, and avoid asking for approval when policy already provides a safe decision.
Binding, audit, and integrity
Bind approval to a fingerprint of the tool name and arguments. If either changes, reject the approval and create a new request. Store the requester, reviewer, timestamp, decision, displayed arguments, fingerprint, policy version, and execution result in an append-only audit log.
Treat tool output and retrieved text as untrusted data. Prompt injection may tell the agent to bypass approval or alter the recipient. The policy engine, not the model's text, must control permissions. Reviewers should see the actual action, not only the agent's explanation.
Testing approval flows
Test approval, rejection, edited arguments, expiry, escalation, duplicate decisions, worker restarts, and fingerprint mismatches. Assert that rejected, expired, or modified actions never reach the tool.
Exercise
A request expires while the reviewer is offline. Should the worker execute it later if the action is low risk?
Show answer
No. Mark it expired or apply a separately defined auto-approval policy. Do not convert an old request into approval.