cd /news/ai-agents/human-in-the-loop-design-where-ai-ag… · home › topics › ai-agents › article
[ARTICLE · art-177260] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

Human-in-the-Loop Design: Where AI Agents Should Pause for Approval

A developer outlined an architectural pattern for human-in-the-loop approval gates in AI agents, publishing a copy-paste Python module that stores proposed actions as pending, authenticates the approver, and executes only after an authorized approval is recorded, failing closed otherwise. The design argues approval must be a trusted application event bound to a user identity and timestamp rather than a model-generated claim, and recommends deterministic rules over model self-reported confidence to decide which actions require review. It also warns that approval fatigue and time-of-check to time-of-use bugs can let risky actions slip through.

recommendation

Gate agent actions that touch external systems behind a fail-closed approval record bound to an authenticated approver and exact payload, and re-approve if the payload changes before execution.

more in playbook: Securing agents and AI tools
by read4 min views7 publishedNov 27, 2026

Human-in-the-loop (HITL) is not a fallback for weak models. It is an architectural layer for any agent that touches external systems. The question is not whether to add a human checkpoint, but where to place it.

Start with a copy-paste approval gate. This module stores a proposed action as pending, authenticates the approver, and executes only after an authorized approval is recorded. It fails closed: if the caller cannot approve, nothing runs.

from dataclasses import dataclass
from enum import Enum
from typing import Optional
from datetime import datetime, timezone

class ApprovalStatus(str, Enum):
    PENDING = "pending"
    APPROVED = "approved"
    REJECTED = "rejected"

@dataclass
class PendingAction:
    id: str
    action: str           # what the agent proposes to do
    payload: dict         # exact arguments to execute
    requested_by: str     # user or agent identity
    status: ApprovalStatus = ApprovalStatus.PENDING
    approved_by: Optional[str] = None
    approved_at: Optional[datetime] = None
    idempotency_key: Optional[str] = None

def approve_and_execute(
    draft: PendingAction,
    approver_id: str,
    can_approve: bool,
    executor,
) -> str:
    if not can_approve:
        raise PermissionError("This identity cannot approve outgoing actions")
    if draft.status is not ApprovalStatus.PENDING:
        raise ValueError("This action is no longer pending")
    if draft.idempotency_key and already_executed(draft.idempotency_key):
        raise ValueError("This action has already been executed")
    draft.status = ApprovalStatus.APPROVED
    draft.approved_by = approver_id
    draft.approved_at = datetime.now(timezone.utc)
    log_audit(draft)  # append-only: who, when, what
    return executor(draft.payload)

Key rule: approval is a trusted application event bound to a user identity and timestamp, not a model-generated statement that "the user approved."

Do not ask for approval just because the system can. Sort actions into three buckets using impact and reversibility:

Risk is not only about the action itself. Consider who is affected, how quickly errors can be corrected, and whether the user reasonably expects the agent to proceed.

A checkpoint is not a yes/no button. It is the right information at the moment of decision, so the reviewer can judge in seconds instead of re-investigating from scratch. Show the person:

Instead of "Approve action?", show: "Send this reply to customer A about order 4821. It offers a replacement under the delayed-shipment policy. The message will be sent from the support inbox." The person should be able to inspect or edit the draft before approval.

Approval fatigue is a real failure mode. When reviewers click through hundreds of low-stakes actions, the one risky item sails through because it looked like the other ninety-nine. Fewer, meaningful checkpoints beat many trivial ones.

Use deterministic rules. Filter by dollar amounts, data sensitivity levels, or confidence thresholds to decide which actions need human review. Do not rely solely on the model's self-reported confidence score, which can be hallucinated. Combine model signals with hard-coded business rules. Reviewers must be able to edit, reject, or take over a task rather than merely approve or block it.

You cannot rely on the LLM's context window to remember whether a user approved an action. Store the proposed action as pending in a database, and execute it only after an authorized approval is recorded. The audit trail must be append-only and tied to a specific identity and timestamp.

Prevent time-of-check to time-of-use bugs: if a draft changes after approval, require a new approval. An agent must not be able to modify a payload between the human's review and execution.

Approval is one layer in a larger design that also includes authentication, authorization, validation, and monitoring. Authenticate approvers, check authorization scopes, bind approval to the exact content, and maintain an audit trail. These checks live in application code and trusted services, not in prompts. A prompt can explain the workflow to the model; it cannot enforce a permission boundary.

This series has covered permission hooks that fail on exit codes, read-only role guards that are not walls, and unattended-run deny rules. This post addresses a different layer: where to place the human approval point in the workflow, how to make the approval state durable and idempotent, and how to keep approvals meaningful instead of ceremonial.

A support agent drafts a refund for order 4821. The refund is $120, reversible within 30 days, but it touches money and an external customer. Bucket: medium impact, hard to fully reverse.

The gate should present: "Refund $120 to customer A for order 4821, paid by card, reason: delayed shipment. Funds return to the original card within 5–10 business days. Cannot be recalled after the batch settles at 22:00 UTC." The reviewer can edit the amount or reason, approve, reject, or take over and process manually.

The system records: who requested it (agent identity), who approved it (support lead ID), when (timestamp), and the exact payload (order ID, amount, payment method). If the agent changes the amount after approval, a new approval is required before execution.

Approval is not a one-time yes. Three behaviors belong in every gate:

These rules live in application code and trusted services, not in prompts. A prompt can explain the workflow to the model; it cannot enforce a permission boundary.

This post was written with AI assistance. The author is responsible for its content.

── more in #ai-agents 4 stories · sorted by recency
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/human-in-the-loop-de…] indexed:0 read:4min 2026-11-27 · —