Module 3 Lesson 5: Human-in-the-Loop Pattern
·Agentic AI

Module 3 Lesson 5: Human-in-the-Loop Pattern

The safety net. When and how to pause an autonomous agent to ask for human approval.

Human-in-the-Loop (HITL): The Final Approval

No matter how many "Critics" or "Validators" you build, there are some actions that are too risky to leave to an LLM. Human-in-the-Loop is the pattern where an agent "Pauses" its execution, saves its state, and waits for a human to click "Approve" or "Reject."

1. When to use HITL

  • Financial Transactions: Moving more than $1,000.
  • Irreversible Deletions: Deleting a database or an AWS instance.
  • Sensitive Communication: Sending an email to a VIP client.
  • Ambiguity: When the agent has two choices and isn't sure which one the user prefers.

2. Breaking the "Autonomous" Illusion

Total autonomy is rarely what a business actually wants. A business wants efficiency.

  • The agent does 90% of the work (Research, Drafting, Coding).
  • The human does 10% of the work (Reviewing, Tweaking, Approving).

3. The "Breakpoint" Architecture

In frameworks like LangGraph, we define "Breakpoints." When the agent reaches a specific "Node" (e.g., the send_email node), it triggers a pause.

sequenceDiagram
    participant A as Agent
    participant H as Human
    participant S as System (Email)
    
    A->>H: "I have drafted the response. Ready to send?"
    H->>A: "Wait, fix the spelling of the CEO's name."
    A->>H: "Fixed. Ready now?"
    H->>A: "Yes. APPROVED."
    A->>S: Sending email...

4. Why HITL is a UX Challenge

The hardest part of HITL isn't the AI—it's the UI.

  • How do you notify the human? (Slack? Email? Dashboard?)
  • How much "Context" do you show the human?
  • If the human waits for 3 days to approve, does the agent still remember what it was doing? (This is why Persistent State is critical).

5. Code Example: A Conceptual Breakpoint

def send_money_agent(amount, recipient):
    # 1. Draft the transaction
    tx = draft_transaction(amount, recipient)
    
    # 2. TRIGGER HUMAN APPROVAL
    if amount > 100:
        approval_status = request_human_approval(tx) # This pauses the script
        
        if approval_status == "REJECTED":
            return "Transaction cancelled by user."
            
    # 3. Final action
    return execute_transaction(tx)

Key Takeaways

  • HITL is the only way to deploy agents in high-stakes environments safely.
  • Breakpoints allow agents to pause and persist state.
  • HITL turns a "Black Box" into a Collaborative Tool.
  • The goal is to automate the Toil but delegate the Judgment.

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn