Skip to content

Human-in-the-Loop (HITL)

Human-in-the-Loop (HITL) is LangCrew’s high-level human oversight component built on top of LangGraph’s native interrupt system. It provides an easy-to-use interface for adding human approval workflows to AI agent executions.

HITL is a high-level abstraction that wraps LangGraph’s interrupt mechanisms to provide strategic control points where humans can:

  • Approve or deny tool executions before they run
  • Modify parameters before tool execution
  • Review and edit tool results after execution
  • Implement safety policies for production environments
  • Multi-language support with Chinese and English UI elements

HITL provides a high-level wrapper around LangGraph’s interrupt system with enhanced approval workflows:

from langcrew.hitl import HITLConfig
# Basic configuration
hitl_config = HITLConfig(
interrupt_before_tools=["file_write", "database_query"],
interrupt_after_tools=["data_analysis"]
)

LangCrew supports two execution modes that determine which interrupts are effective:

ModeWhen UsedEffective InterruptsIgnored Interrupts
Task ModeWhen you provide both agents and tasksinterrupt_before_tasks
interrupt_after_tasks
interrupt_before_agents
interrupt_after_agents
Agent ModeWhen you provide only agents (no tasks)interrupt_before_agents
interrupt_after_agents
interrupt_before_tasks
interrupt_after_tasks

Important: Tool-level and node-level interrupts work in both modes.

Effective in: Task Mode only

Pause before specific tasks execute to review or modify task inputs:

from langcrew import Crew, HITLConfig
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, writing_task],
hitl=HITLConfig(
interrupt_before_tasks=["research_task"] # Review before research starts
)
)

Effective in: Task Mode only

Pause after specific tasks complete to review or modify outputs:

hitl=HITLConfig(
interrupt_after_tasks=["research_task"] # Review research results
)

Effective in: Agent Mode only

Pause before specific agents execute:

from langcrew import Crew, HITLConfig
crew = Crew(
agents=[coordinator, specialist], # No tasks - Agent Mode
hitl=HITLConfig(
interrupt_before_agents=["specialist"] # Approve before specialist runs
)
)

Effective in: Agent Mode only

Pause after specific agents complete their work:

hitl=HITLConfig(
interrupt_after_agents=["coordinator"] # Review coordinator's decisions
)

Effective in: Both modes

Pause before specific tools execute (most common for sensitive operations):

hitl=HITLConfig(
interrupt_before_tools=["send_email", "make_payment", "delete_file"]
)

Effective in: Both modes (with session limitations)

Pause after specific tools complete to review results:

hitl=HITLConfig(
interrupt_after_tools=["data_analysis"] # Review analysis results
)

interrupt_before_nodes / interrupt_after_nodes

Section titled “interrupt_before_nodes / interrupt_after_nodes”

Effective in: Both modes

Pause at specific LangGraph nodes for workflow-level control:

hitl=HITLConfig(
interrupt_before_nodes=["decision_node"],
interrupt_after_nodes=["processing_node"]
)

Unified configuration for all interrupt and approval settings.

ParameterTypeDescriptionDefault
interrupt_before_tasksList[str]Tasks to interrupt before (Task Mode only)[]
interrupt_after_tasksList[str]Tasks to interrupt after (Task Mode only)[]
interrupt_before_agentsList[str]Agents to interrupt before (Agent Mode only)[]
interrupt_after_agentsList[str]Agents to interrupt after (Agent Mode only)[]
interrupt_before_toolsList[str]Tools requiring approval before execution[]
interrupt_after_toolsList[str]Tools requiring review after execution[]
interrupt_before_nodesList[str]Nodes to interrupt before[]
interrupt_after_nodesList[str]Nodes to interrupt after[]

Control tool execution with human approval workflows.

# Interrupt before/after specific tools
hitl_config = HITLConfig(
interrupt_before_tools=["file_write", "web_search"],
interrupt_after_tools=["data_analysis"]
)
  • Before interrupts: Parameter approval and modification
  • After interrupts: Result review and editing

Integration with LangGraph’s native interrupt system for workflow control.

# Interrupt before/after specific workflow nodes
hitl_config = HITLConfig(
interrupt_before_nodes=["decision_node"],
interrupt_after_nodes=["validation_node"]
)

Node-level interrupts provide granular control over workflow execution, allowing human intervention at specific decision points or validation steps in your agent workflows.

Dynamic user interaction tool for agent-initiated input requests.

from langcrew_tools.hitl import UserInputTool
# Agent can request user input during execution
user_input_tool = UserInputTool()
agent = Agent(tools=[user_input_tool, ...])

Enables agents to dynamically collect information from users during workflow execution.

HITL integrates seamlessly with all langcrew components:

  • Agents: Add approval workflows to agent tools
  • Tasks: Tasks inherit HITL settings from their assigned agents
  • Crews: Apply unified HITL policies across teams
# HITL is configured at the Agent level
agent = Agent(
role="Data Analyst",
tools=[web_search, file_write],
hitl=HITLConfig(interrupt_before_tools=["file_write"])
)
# Tasks automatically inherit HITL settings from their agent
task = Task(
agent=agent,
description="Analyze data and save report"
)
# Crew can also apply HITL policies to all agents
crew = Crew(
agents=[agent],
tasks=[task],
hitl=HITLConfig(interrupt_before_tools=["web_search"])
)
# User approves/modifies parameters before execution
hitl_config = HITLConfig(
interrupt_before_tools=["web_search", "file_write"]
)
# User reviews/edits results after execution
hitl_config = HITLConfig(
interrupt_after_tools=["data_analysis", "report_generator"]
)
  • Production environments requiring human oversight
  • Sensitive operations like file modifications or API calls
  • Quality assurance workflows needing human validation
  • Compliance scenarios requiring audit trails

HITL provides built-in multi-language interface support:

# Automatic language detection
# Currently supported languages:
# English: "approve", "deny", "yes", "no"
# Chinese: "批准", "拒绝", "同意", "不同意"
# More languages can be added in the future