Task 1.6

Human-in-the-Loop

Human-in-the-loop (HITL) patterns integrate human oversight into agentic workflows. Rather than running fully autonomously, agents pause at critical decision points to get human approval, input, or correction.

Approval Gates

Approval gates pause agent execution before high-impact actions. When the agent wants to perform a sensitive operation (deleting data, sending emails, making purchases), the system presents the proposed action to a human reviewer for approval. The agent only proceeds after explicit approval.

Implementation involves intercepting tool calls before execution, presenting the call details to a human, and either executing or blocking based on the human's decision. The key design challenge is minimizing disruption while maintaining safety.

Escalation Patterns

Escalation transfers control from the agent to a human when the agent encounters situations it cannot handle confidently. Triggers for escalation include: low confidence in the response, encountering edge cases not covered by instructions, detecting potential safety issues, or user explicitly requesting human help.

Effective escalation preserves context — the human should receive the full conversation history, the agent's analysis, and a clear explanation of why escalation was triggered. This prevents the human from starting from scratch.

Feedback Loops

Human corrections during HITL interactions can be used to improve agent behavior over time. When a human modifies an agent's proposed action, that correction signal can inform prompt updates, few-shot example additions, or guardrail adjustments.

The feedback loop pattern: agent proposes action, human approves or corrects, correction is logged, patterns in corrections inform system improvements. This creates a virtuous cycle where human oversight becomes less necessary over time as the system learns from corrections.

Key Concept

Strategic Interruption, Not Constant Supervision

Effective HITL systems interrupt the human only when the cost of an error is high. Requiring approval for every action defeats the purpose of automation. The goal is to identify the specific decision points where human judgment adds the most value — typically irreversible actions, high-cost decisions, or novel situations outside the agent's training.

Exam Traps

EXAM TRAP

Requiring human approval for every tool call

Excessive approval requirements negate the benefits of automation. HITL should be selective — only for high-impact or uncertain actions.

EXAM TRAP

Not preserving context during escalation

When escalating to a human, the full conversation context must be passed. The exam may test whether you understand that context-free escalation is ineffective.

EXAM TRAP

Treating HITL as an all-or-nothing choice

HITL is a spectrum. Different actions within the same agent can have different levels of human oversight — some autonomous, some requiring approval, some requiring full human takeover.

Check Your Understanding

An agent manages a company's social media accounts. It can draft posts, schedule them, and respond to comments. Which HITL approach is most appropriate?

Build Exercise

Build an Approval Gate System

Intermediate45 minutes

What you'll learn

  • Implement tool call interception for approval
  • Design approval UX for reviewers
  • Handle timeout and fallback for pending approvals
  • Log approval decisions for audit
  1. Create a tool wrapper that intercepts tool calls and classifies them as 'auto-approve' or 'requires-approval' based on the tool name and parameters.

    WHY: Not all tool calls need approval — classification is the first step in selective HITL.

    YOU SHOULD SEE: Read operations are auto-approved; write/delete operations require approval.

  2. Implement the approval flow: when approval is required, pause execution, display the proposed action, and wait for a human decision.

    WHY: The approval flow must clearly present what the agent wants to do and why.

    YOU SHOULD SEE: A clear prompt showing the tool name, parameters, and requesting approve/deny.

  3. Add an audit log that records every approval decision: timestamp, tool call, parameters, decision, and reviewer.

    WHY: Audit trails are essential for compliance and for understanding agent behavior patterns.

    YOU SHOULD SEE: A JSON log file with complete records of all approval decisions.

  4. Handle edge cases: what happens when the reviewer is unavailable? Implement a timeout with configurable default (approve/deny/escalate).

    WHY: Production systems must handle the case where no human is available to approve.

    YOU SHOULD SEE: After a configurable timeout, the system takes a safe default action (typically deny).

Sources

Previous

Multi-Agent Systems