Combination of automation and human judgment. Automation handles standard tasks, while humans validate or intervene when needed.
Human In The Loop workflow
A Human In The Loop (HITL) workflow is a type of workflow that combines automated and manual tasks that need human intervention. Rather than fully automating a process, a HITL workflow includes steps where humans review, validate, or make decisions that machines cannot handle on their own.
Many real world processes do not require full automation. In fact, the best workflows are those that combine the decision-making of humans and the power of software to handle tedious tasks.
HITL workflows are widely used in following scenarios:
To illustrate the importance of HITL let's take the example of a legal document review process. The system starts by scanning documents for relevant keywords, clauses, and potential issues. A human review step in which lawyers review documents flagged by the system. Without the second review step, the system could make errors that have high risk that cannot be tolerated.
If you would like to use an orchestration tool to handle your HITL workflows you have to make sure that the tool supports this kind of workflow and allows you to use manual steps inside the workflows. Some workflow orchestration tools do not have built-in support for HITL workflows and it may be challenging to add these manual steps. So be careful to choose the right tool before implementing your workflows. In this section we will list some of the well-known tools that support this type of workflow.
Prefect provide two functions (pause_flow_run and suspend_flow_run) that can be used to implement HITL workflows. Here is an example using pause_flow_run fonction:
1from prefect import flow2from prefect.flow_runs import pause_flow_run3from prefect.logging import get_run_logger45@flow6def greet_user():7 logger = get_run_logger()8 user = pause_flow_run(wait_for_input=str)9 logger.info(f"Hello, {user}!")10
In Argo workflows you can suspend the execution of workflows using the suspend template, below is an example of a workflow using this feature.
12apiVersion: argoproj.io/v1alpha13kind: Workflow4metadata:5 generateName: suspend-template-6spec:7 entrypoint: suspend8 templates:9 - name: suspend10 steps:11 - - name: build12 template: hello-world13 - - name: approve14 template: approve15 - - name: delay16 template: delay17 - - name: release18 template: hello-world1920 - name: approve21 suspend: {}2223 - name: delay24 suspend:25 duration: "20" # Must be a string. Default unit is seconds. Could also be a Duration, e.g.: "2m", "6h"2627 - name: hello-world28 container:29 image: busybox30 command: [echo]31 args: ["hello world"]32
Flyte provide three different methods, flytekit.sleep, flytekit.wait_for_input, and flytekit.approve, for implementing HITL workflows. The example below use wait_for_input to implement an approval step before publishing an important report.
1import typing2from flytekit import wait_for_input34@union.task5def create_report(data: typing.List[float]) -> dict:6 return {"report_data": data"}78@union.task9def send_report(report: dict, title: str) -> dict:10 return {"title": title, **report}1112@union.workflow13def reporting_workflow(data: typing.List[float]) -> dict:14 report = create_report(data=data)15 title_input = wait_for_input("title", timeout=timedelta(hours=1), expected_type=str)16 return send_report(report=report, title=title_input)17
Airflow do not support user validation tasks. But there is a work around to implement this type of task using the retry feature. Similar to this code:
1from datetime import timedelta23from airflow import AirflowException45def fail_task():6 raise AirflowException("Please change this step to success to continue")78user_validation_step = PythonOperator(9 dag=dag,10 task_id="user_validation_step",11 python_callable=fail_task,12 retries=1,13 max_retry_delay=timedelta(days=7)14)15
With the rise of agent development, and due to the nature of LLMs and the hallucination problem, Human In The Loop workflows will be used more and more in the future. In this article, we have seen what HITL workflows are, when to use them, and some of the workflow orchestration tools that support this type of workflow.