Human-in-the-loop (HITL) review for agents¶
HITL Review adds an interactive feedback loop to agentic operators. After the
LLM Agent produces an initial output, a human reviewer can approve, reject, or
request changes through a chat UI. The review ends on a terminal action, or when
hitl_timeout or max_hitl_iterations is reached. On Airflow 3.3+ the task waits
for the reviewer in the awaiting_input state and holds no worker or pool slot
while it waits.
This document describes the architecture, workflow, API, XCom schema, and usage.
Overview¶
See also
This page covers the iterative review loop on AgentOperator. For a one-shot
approve, edit or reject gate on LLMOperator and its subclasses, see
Approval gates for LLM operators.
Components
HITL Review Plugin: FastAPI app mounted at
/hitl-reviewon the Airflow API server. Provides REST endpoints and a chat UI for reviewers.
Storage: The review session, every output and every piece of feedback is stored in XCom on the task instance. The worker writes the session and the agent outputs; the plugin writes human feedback and actions. On Airflow 3.3+ the conversation the agent needs to regenerate is also kept in the task state store while the task waits.
Compatibility: Requires Airflow 3.1+. Uses the Task SDK execution model where workers communicate via the Execution API and XCom; the plugin runs on the API server and accesses the metadata database.
How the task waits
Airflow 3.3+: each review round is a Human-in-the-loop request on the task instance, and the task parks in the
awaiting_inputstate until the reviewer answers it. A parked task holds no worker slot and no pool slot, so a review that takes hours costs nothing while it waits. When the reviewer acts in the chat UI, the plugin answers the request and the task is scheduled again; the next round (regenerating with the feedback, or returning the approved output) runs in a new worker process.hitl_poll_intervalis not used.Airflow 3.1 and 3.2: the task stays
runningand polls the human action XCom everyhitl_poll_intervalseconds, holding its worker slot for the whole review.
Because each round is a Human-in-the-loop request, a parked review also appears on the Required Actions page. It can be answered there with Approve, Request changes (with feedback) or Reject, but the output and the earlier rounds are only shown in the chat UI.
Note
On Airflow 3.3+ each round is a new run of the task, so execution_timeout
applies to each round separately and hitl_timeout is what bounds the review
as a whole. pre_execute and on_execute_callback also run once per round.
The plugin on the API server resumes the parked task, so upgrade the provider on the API server no later than on the workers. A worker on the new provider with an API server on the old one parks, and the old plugin’s answers never resume it.
Workflow¶
The operator and the plugin never talk to each other directly. On Airflow 3.3+ each round parks the task and the reviewer’s answer schedules it again:
On Airflow 3.1 and 3.2 the operator stays running and polls the
airflow_hitl_review_human_action XCom instead of parking.
The reviewer’s answer resolves to one of five outcomes:
Using HITL review with AgentOperator¶
Enable the review loop with enable_hitl_review=True:
from airflow.providers.common.ai.operators.agent import AgentOperator
from airflow.providers.common.ai.toolsets.sql import SQLToolset
from datetime import timedelta
AgentOperator(
task_id="summarize",
prompt="Summarize the sales data",
llm_conn_id="openai",
toolsets=[SQLToolset(db_conn_id="postgres")],
enable_hitl_review=True,
hitl_timeout=timedelta(hours=4),
)
Parameters
enable_hitl_review: WhenTrue, the operator enters the review loop after the first generation. DefaultFalse.max_hitl_iterations: Maximum outputs the reviewer can see (1 = initial output plus subsequent regenerations). When the reviewer requests changes at iteration>= max_hitl_iterations, the task fails withHITLMaxIterationsErrorwithout running the LLM. For example,5allows changes at iterations 1 to 4; the fifth output must be either approved or rejected. Default5.hitl_timeout: Maximum wall-clock time for all review rounds combined, including the time spent regenerating.None= no wall-clock timeout. Once it passes the task fails withHITLTimeoutError(on Airflow 3.3+ the scheduler resumes the parked task to raise it), andretriesapply as for any failure. When polling, the task also fails, re-raising the XCom error, if pulling the human action XCom fails 10 times in a row.hitl_poll_interval: Seconds between XCom polls while waiting for a human response on Airflow 3.1 and 3.2. Not used on Airflow 3.3+, where the task parks instead. Default10.
Accessing the chat UI: The chat loads as a React plugin on the task
instance page. Use the HITL Review extra link on the task instance, or
navigate to
/dags/{dag_id}/runs/{run_id}/tasks/{task_id}/plugin/hitl-review.
Example Dag
@dag(tags=["example"])
def example_agent_operator_hitl_review():
"""AgentOperator with HITL review — a human approves output via hitl-review plugin UI."""
AgentOperator(
task_id="summarize_with_review",
prompt="Summarize the Q4 sales report in 3 bullet points.",
llm_conn_id="pydantic_ai_default",
system_prompt="You are a concise business analyst.",
enable_hitl_review=True,
max_hitl_iterations=5,
hitl_timeout=timedelta(minutes=30),
)
With durable execution¶
With durable=True (see Durable execution), the first output and every
regeneration are agent runs in the task’s journal, so a retry replays them instead of
calling the model and the tools again (on Airflow 3.1 and 3.2, only the first output; see the
end of this section). Each regeneration logs its own Durable: line in the task log, after
the first run’s.
On Airflow 3.3 and later, each request for changes is also kept in the task state store beside the journal, with the round it was given in and a digest of the output the reviewer read. When the task fails after the review has started (a regeneration hits a failing tool or an unavailable model, or the review times out) the retry replays the first output, applies the recorded feedback to it without asking, replays each regeneration, and shows the reviewer the first round nobody has answered yet. The HITL Review tab shows the replayed rounds with their feedback. The task log has a line for each:
Applying the feedback given on iteration 1 in an earlier attempt: Mention that Atlas Pro drove most of the growth.
Each regeneration runs under the first run’s id with -review-<n> appended, n being the
round whose feedback it follows, the same on every attempt, so capabilities that keep state by
run id find it again on a retry.
Feedback applies only to the output it was given on. When a replayed run produces a different output, for example because a tool that runs on every attempt returned something new, the reviewer is asked again from that round, the feedback recorded for later rounds is dropped, and this warning is in the task log:
The output of iteration 1 is not the one the reviewer asked to change in an earlier attempt, so the reviewer is asked again.
A review that ends in Reject, or in HITLMaxIterationsError, fails the task, and the
retry starts the review over: the recorded feedback is dropped, and the model is asked again
for the first output. The tool calls before that answer replay, so the retry does not repeat
their side effects. Without durable execution a retry runs everything again, tools included.
The attempt that ended logs:
The review ended without an approved output; a retry asks the model again for the first output and starts the review over.
When the reviewer approves, the task deletes the journal and the recorded feedback. A clear that deletes the task’s state (Clearing a task) starts the agent and the review over.
On Airflow 3.1 and 3.2, where the review polls instead of parking, feedback is not recorded: a retry replays the first output and asks the reviewer about every round again, and each regeneration after an answer runs again, its model requests and tool calls included.
REST API¶
The plugin exposes a FastAPI app at /hitl-review. Base URL:
{AIRFLOW_BASE_URL}/hitl-review
Common query parameters (where applicable):
dag_id: Dag ID.run_id: Dag run ID.task_id: Task ID.map_index: Map index for mapped tasks. Use-1for non-mapped tasks or index for dynamic mapping.region_idandregion_index: Select one loop pass or one mapped slot. Use theregion_idandregion_indexof the task instance as returned by the public task instance endpoints. Send them together;region_indexwithoutregion_idis rejected. Only supported on Airflow 3.4 or later; earlier hosts return 400 when either is sent. A task inside a loop addressed without them returns 400, and a selection that matches more than one task instance returns 409.
Endpoints¶
Method |
Path |
Description |
|---|---|---|
GET |
|
Liveness check. Returns |
GET |
|
Find the feedback session for a task instance. Returns
|
POST |
|
Request changes. Body: |
POST |
|
Approve the current output. Session must be |
POST |
|
Reject the output. Session must be |
Response model: HITLReviewResponse¶
{
"dag_id": str,
"run_id": str,
"task_id": str,
"status": "pending_review"
| "changes_requested"
| "approved"
| "rejected"
| "max_iterations_exceeded"
| "timeout_exceeded",
"iteration": int,
"max_iterations": int,
"prompt": str,
"current_output": str,
"conversation": [{"role": "assistant" | "human", "content": str, "iteration": int}],
"task_completed": bool,
}
XCom keys and storage¶
All keys use the prefix airflow_hitl_review_.
Key |
Writer |
Value |
|---|---|---|
|
Worker |
|
|
Plugin |
|
|
Worker |
Per-iteration AI output (string or JSON) |
|
Plugin, and the worker when it resumes |
Per-iteration human feedback text |
Session lifecycle¶
pending_review: Awaiting human action. Plugin accepts approve, reject, or feedback.
changes_requested: Feedback submitted; the worker is regenerating. The plugin does not accept new actions until the worker pushes a new output and status returns to
pending_review.approved / rejected: Terminal. The review has ended.
On Airflow 3.3+ the plugin also refuses (409) an action when the task’s request for the round has already been answered, for example on the Required Actions page.
Chat UI¶
The plugin provides an interactive chat UI that loads in the task instance page. The UI:
Fetches session and conversation from the REST API
Displays the current output and feedback history
Submits approve, reject, or feedback via POST endpoints