Skip to content

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)
Full access preview

Continue with full access

You're reading a preview. Full access unlocks the full lesson, its flashcards and exercise.

Sign in to unlock

One purchase unlocks Stages 2–3, Specials, exercises and future updates