ai-hub
[en]es
[concept][changing]

Human-in-the-Loop (HITL): Integrating Human Oversight in Agents

HITL is a design pattern where a human reviews, approves, or corrects agent decisions before critical actions are executed, balancing autonomy with control.

// 5 min read · updated 2026-06

Human-in-the-Loop (HITL) is a design pattern where a human steps into the agent's flow to review, approve, or correct actions before they are executed. The agent operates autonomously until it encounters a decision that exceeds a certain risk or uncertainty threshold — then it asks for human input. This combines the speed and scale of AI with the judgment, ethics, and context that only a human can provide.

Pro Tip: HITL is not a failure of the agent. It's a design feature. The best autonomous systems aren't the ones that never ask for help, but the ones that know exactly when to ask.

What is it

The HITL pattern relies on three modes of human intervention, ordered from most to least agent autonomy:

  1. Human-in-the-loop (real-time supervision): the agent executes, but a human can stop or correct it on the fly. Common in code assistants and moderated chatbots.
  2. Human-on-the-loop (review): the agent proposes an action, the human reviews and approves it before execution. Typical for sending emails, creating tickets, or payments.
  3. Human-in-command (full control): the human initiates every action manually. The agent only suggests, never executes.

The key to the pattern is defining when and how human intervention is triggered. Common criteria:

  • Model uncertainty: if the model signals low certainty (via self-report or proxies like logprobs), request review. LLMs don't expose a calibrated confidence score, so this is an approximation, not a direct measurement.
  • Irreversible actions: sending an email, processing a payment, deleting data.
  • Sensitive content: personal data, legal or medical topics.
  • First time: if the agent has never executed that action before, require initial human approval.

Note: HITL is not the same as having a human manually operate the system. It's a hybrid design where the human intervenes only at critical points, not at every step.

Mental model

Think of an airplane autopilot. 99% of the flight is handled by the autopilot (the agent). But during takeoff, landing, and emergencies, the human pilot takes control. The system knows when to delegate to the human, and the human knows when to take over.

User → Agent → Critical action? → No → Execute
                         ↓ Yes
                   Pause → Human reviews → Approves → Execute
                                         → Rejects → Don't execute / Correct

The agent does the heavy lifting; the human does the fine judgment.

How it's used

Basic HITL: approval before execution

The most common case: the agent prepares a sensitive action and waits for human confirmation.

import json
 
critical_actions = ["send_email", "delete_record", "process_payment"]
 
def execute_with_approval(agent_response):
    decision = json.loads(agent_response)
 
    if decision["action"] in critical_actions:
        print(f"\n⚠️  Critical action detected: {decision['action']}")
        print(f"   Arguments: {decision['arguments']}")
        print(f"   Reasoning: {decision.get('reasoning', 'N/A')}")
 
        approval = input("   Approve? (y/n): ").lower()
 
        if approval != "y":
            print("   ❌ Action rejected by supervisor.")
            return None
 
        print("   ✅ Action approved.")
        return execute_action(decision)
 
    # Non-critical actions execute without supervision
    return execute_action(decision)

HITL with confidence threshold

The agent only asks for help when it's not sure:

def generate_with_hitl(question):
    response = client.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": question +
                   "\n\nIf you are not 100% sure of the answer, "
                   "reply with 'UNSURE: [your best estimate]'"}]
    )
    answer = response.choices[0].message.content
 
    if answer.startswith("UNSURE"):
        print(f"\n⚠️ The agent is unsure about: {question}")
        print(f"   Its estimate: {answer.replace('UNSURE: ', '')}")
        correction = input("   Enter the correct answer (or press Enter to use the estimate): ")
 
        if correction.strip():
            return correction
 
    return answer

HITL with review queue for multiple agents

In multi-agent systems, centralize human review:

review_queue = []
 
def request_human_review(agent_id, action, context):
    review_queue.append({
        "agent_id": agent_id,
        "action": action,
        "context": context,
        "status": "pending"
    })
 
def process_review_queue():
    for item in review_queue:
        if item["status"] != "pending":
            continue
 
        print(f"\n{'='*50}")
        print(f"Agent: {item['agent_id']}")
        print(f"Action: {item['action']}")
        print(f"Context: {item['context']}")
 
        decision = input("Approve, reject, or modify? (a/r/m): ").lower()
 
        if decision == "a":
            item["status"] = "approved"
        elif decision == "r":
            item["status"] = "rejected"
        elif decision == "m":
            modification = input("Enter the modification: ")
            item["context"] = modification
            item["status"] = "modified"
 
process_review_queue()

Warning: An unbounded review queue can become a bottleneck. Define an SLA for human review: if the human doesn't respond within X seconds, the system executes a fallback (reject, retry, or escalate).

HITL with logging and auditing

Every human intervention should be recorded:

def log_intervention(agent, action, decision, human, timestamp):
    record = {
        "agent": agent,
        "action": action,
        "agent_decision": decision["original"],
        "final_decision": decision["final"],
        "reviewed_by": human,
        "timestamp": timestamp,
        "intervention_type": "approval" if decision["final"] else "rejection"
    }
    db.insert("hitl_audit", record)

When to use it / when not to

✅ Use it when❌ Don't use it when
The agent's actions can have real-world consequencesThe agent only generates text without executing actions
You need to comply with regulations requiring human oversightSpeed matters more than accuracy
The agent operates in a domain where errors are costlyThe human has no better context than the agent
You're in early stages and want to validate agent behaviorThe system must scale to millions of operations without intervention
Decisions require ethical or contextual judgmentYou have one human reviewing hundreds of decisions per minute

Pro Tip: Don't put a human in charge of reviewing every step. Design the agent to be autonomous 90% of the time. If the human is approving more than 20% of decisions, your agent needs better criteria, not more oversight.

History and evolution

View history

The concept of Human-in-the-Loop predates LLMs by decades. It's used in control systems, autonomous vehicles, and traditional machine learning (active learning). In the context of AI agents, the term gained traction with the rise of autonomous assistants (2023-2024) that could execute actions on behalf of users.

Companies like Adept, Cognition (Devin), and OpenAI (with GPTs and assistants) popularized the pattern: the agent suggests, the user approves. As agents become more autonomous, the balance between autonomy and human control is one of the most active design problems in AI engineering.

By 2025, the HITL pattern matured toward systems that learn from human interventions to reduce how often they need to ask for help — essentially, the agent becomes more autonomous with every correction it receives.

// related