Skip to main content

Overview

Human-in-the-Loop (HITL) workflows pause execution to collect input from humans, then resume based on the response. Use cases include:
  • Approval workflows: Review and approve agent actions
  • Ambiguous decisions: Escalate to humans when AI is uncertain
  • Quality control: Human review before final output
  • Data collection: Gather additional context from users

How It Works

  1. Request: Executor calls ctx.request_info() with request data
  2. Pause: Workflow pauses and emits a request_info event
  3. Human Response: External system collects response
  4. Resume: Workflow resumes with response data
  5. Handle Response: Executor’s @response_handler processes the response
Human-in-the-loop workflow diagram

Basic Pattern

Request Information

Use ctx.request_info() to pause and request input:
Python

Handle Response

Use @response_handler to process the human response:
Python

Running with Human Input

Interactive Workflow

Collect input during execution:
Python

Pre-supplied Responses

Provide responses when resuming from checkpoint:
Python

Complete Example: Content Review Workflow

A workflow where an agent drafts content and a human reviews it:

Checkpoint Integration

Combine HITL with checkpoints for durable pause/resume:
Python

Multiple Concurrent Requests

Handle multiple request-info calls in parallel:
Python

Typed Request-Response

Use dataclasses for type-safe request-response:
Python

Best Practices

  • Use clear, specific prompts in request data
  • Include context needed for human decision
  • Use structured data (dataclasses, Pydantic models) for type safety
  • Provide sensible defaults when possible
  • Validate responses before processing
  • Handle unexpected responses gracefully
  • Provide feedback to user about what happens next
  • Log all request-response pairs for audit
  • Always use checkpoint storage for HITL workflows
  • Test checkpoint restore with pending requests
  • Document what happens if response is never provided
  • Implement timeouts for critical workflows
  • Show clear request IDs for tracking
  • Display relevant context with each request
  • Support bulk response collection
  • Provide status indicators (pending, responded, processed)

Advanced Patterns

Escalation Pattern

Escalate to human only when AI is uncertain:
Python

Tool Approval Pattern

Require approval before executing sensitive tools:
Python

Next Steps

Checkpoints

Learn more about checkpoint integration with HITL

Orchestration Patterns

Explore workflow orchestration patterns