P1122 min

Human-in-the-Loop

Fully autonomous agents aren't always the answer. Learn when and how to keep humans in the loop for safety, compliance, and trust.

SDK FocuspermissionModecanUseTool (advanced)AskUserQuestionhooks.PermissionRequesthooks.Stop/goal/loop

Why HITL Matters

Human oversight matters when an action is uncertain, consequential, hard to reverse, or regulated:

  • Agents hallucinate actions — misinterpret prompts and overstep boundaries
  • Mistakes scale instantly — autonomous errors cascade across systems
  • Regulations require it — EU AI Act mandates human oversight for high-risk AI
  • Trust is earned — users build confidence gradually, not overnight

Oversight does not guarantee success; it creates a decision boundary where a qualified reviewer can stop, correct, or defer a risky action.

HITL Patterns

Approval Gate

Agent proposes, human approves before execution:

python
async def execute_with_approval(action, risk_level):
    if risk_level == "high":
        # Block until human approves
        approval = await request_human_approval(
            action=action,
            context=get_full_context(),
            timeout="24h"
        )
        if not approval.granted:
            return ActionResult(status="rejected", reason=approval.reason)

    return await execute(action)
Premium lesson preview

Continue with full access

This lesson stays here for preview. Full access unlocks the complete lesson, flashcards, and related practice.

Sign In to Unlock

One purchase unlocks advanced lessons, practice, and future updates.