Overview

8 Human In the Loop

This chapter explains when and why humans should participate in agent execution, especially when a task is unclear, risky, or needs oversight. It frames human-in-the-loop as a practical extension to the framework, useful when an LLM agent needs clarification to move forward, when a human should validate a potentially costly outcome, or when every step should be visible for debugging and development. The chapter emphasizes that human involvement can be optional and selective, but is often the right safeguard for ambiguous or high-stakes work.

The first pattern adds a human input tool that lets an agent ask a person for missing information during execution without changing the main processing loop. The second pattern inserts a result-approval gate after task completion so a human can accept a result or reject it with feedback, which then sends the agent back through the loop to revise its work. To support this, the framework adds approval-related data structures and updates the agent and task handler logic so rejected outputs can be transformed into new inputs for another iteration.

The final pattern gives a human full step-by-step control through supervised execution, where task processing is no longer automatic but manually driven. A specialized task handler exposes actions to complete, reject, or abort a task, and a new supervised run method returns that handler for interactive control. The chapter closes by showing how these patterns fit into development workflows, introducing a dedicated inspection tool for supervised runs, and noting which approaches can carry over into multi-agent systems and which require additional synchronization or hierarchical oversight.

The updated build plan, completing Part 2 with Human in the Loop
The updated build plan, completing Part 2 with Human in the Loop
Task executions can become ambiguous, blocking progress until a human operator provides clarifying input
Task executions can become ambiguous, blocking progress until a human operator provides clarifying input
Prevent costly incorrect results for high-stakes tasks by having a human operator review the result for approval
Prevent costly incorrect results for high-stakes tasks by having a human operator review the result for approval
An LLM agent uses the HumanInputTool (how we support Tool-Based HITL in our framework) whenever a task execution becomes ambiguous
An LLM agent uses the HumanInputTool (how we support Tool-Based HITL in our framework) whenever a task execution becomes ambiguous
The UML class diagram for HumanInputTool for supporting Tool-Based HITL
The UML class diagram for HumanInputTool for supporting Tool-Based HITL
TaskResults of high-stakes tasks are sent to a human operator for review—approved results close the loop while rejected results are sent back for further processing
TaskResults of high-stakes tasks are sent to a human operator for review—approved results close the loop while rejected results are sent back for further processing
UML class diagrams for ApprovalResult and RejectedTaskResult
UML class diagrams for ApprovalResult and RejectedTaskResult
The necessary updates to LLMAgent and TaskHandler to support Result-Approval HITL
The necessary updates to LLMAgent and TaskHandler to support Result-Approval HITL
The sequence of interactions between a human operator, LLMAgent, and the TaskHandler it dispatches for carrying out the Result-Approval HITL pattern
The sequence of interactions between a human operator, LLMAgent, and the TaskHandler it dispatches for carrying out the Result-Approval HITL pattern
Autonomous task execution advances the processing loop on its own, while supervised task execution gives a human operator full control over invocations of get_next_step() and run_step(), allowing them to pause and inspect or modify intermediate results as needed
Autonomous task execution advances the processing loop on its own, while supervised task execution gives a human operator full control over invocations of get_next_step() and run_step(), allowing them to pause and inspect or modify intermediate results as needed
UML class diagram for SupervisedTaskHandler and LLMAgent showing its new methods run_supervised() and run_supervised_with_skill()
UML class diagram for SupervisedTaskHandler and LLMAgent showing its new methods run_supervised() and run_supervised_with_skill()
The LLM Agent Inspector developer tool, cycling through get_next_step() and run_step() for a supervised task execution.
The LLM Agent Inspector developer tool, cycling through get_next_step() and run_step() for a supervised task execution.
The initial page loaded by the Agent Inspector Application
The initial page loaded by the Agent Inspector Application
Result approval gating in supervised task execution with the LLM Agent Inspector. Under the hood, it makes use of the complete() and reject() methods of SupervisedTaskHandler.
Result approval gating in supervised task execution with the LLM Agent Inspector. Under the hood, it makes use of the complete() and reject() methods of SupervisedTaskHandler.

Summary

  • Reasons for involving humans in task executions include task ambiguity, high stakes, as well as approval of step executions that pose security risks requiring lockdown
  • Our framework supports three of our named HITL patterns: Tool-Based HITL, Result-Approval HITL, and Supervised-Execution HITL
  • The new HumanInputTool allows LLM agents built with our framework to prompt a human mid-task execution
  • We enabled Result-Approval HITL by modifying the LLMAgent.run() method to prompt a human to review the produced TaskResult
  • A TaskResult that is approved by the human closes the processing loop, while a rejected TaskResult becomes a RejectedTaskResult, passed immediately to the next get_next_step() invocation
  • Supervised-Execution HITL gives the human operator full control of the processing loop, allowing them to advance execution of the task, step by step
  • We built the SupervisedTaskHandler, a subclass of TaskHandler, to enable Supervised-Execution HITL, invoked by the new LLMAgent.run_supervised() method
  • The LLM Agent Inspector tool is a developer tool offering a convenient interface for Supervised-Execution HITL, and a glimpse of the kind of higher-level tools that can be built on top of our framework
  • Both Tool-Based HITL and Result-Approval HITL patterns survive when we extend to MAS
  • Supervised-Execution HITL doesn’t survive when extending to MAS since it’d require the human operator to simultaneously supervise the processing loops of every LLM agent in the system; however, the essence of supervising tasks remains intact with a coordinator LLM agent supervising the work of subagents

FAQ

When should humans be in the loop for an LLM agent?Humans should be in the loop when task execution becomes ambiguous, when the task is high-stakes, or when oversight is needed for debugging, compliance, or safety. In ambiguous cases, the agent may need clarifying input to continue. In high-stakes cases, a human can review results before they are finalized or acted on.
What are the three human-in-the-loop patterns covered in this chapter?The chapter covers three patterns: Tool-Based HITL, Result-Approval HITL, and Supervised-Execution HITL. Tool-Based HITL lets the agent ask a human for input during execution. Result-Approval HITL adds a review gate after the task result is produced. Supervised-Execution HITL gives the human full control over each step of the processing loop.
What is Tool-Based HITL and when is it useful?Tool-Based HITL uses a HumanInputTool that an LLM agent can call whenever it needs clarification or missing information. It is useful when execution is blocked by ambiguity, such as needing a human preference before continuing a task. The agent decides when to call the tool, just like any other tool.
How does the HumanInputTool work?HumanInputTool asks the human operator a prompt and waits for a response. It can optionally include a list of valid choices to constrain the answer. Its implementation defines a name, description, JSON schema for the arguments, and a __call__() method that displays the prompt and returns the human’s response.
Why does the HumanInputTool include a choices parameter?The choices parameter lets the agent restrict the human’s response to a known set of valid values. This is useful when the task requires a limited set of answers, such as choosing between economy and business class. If choices are provided, the prompt re-asks until the human enters one of the allowed values.
What is Result-Approval HITL?Result-Approval HITL adds a human review step after the agent produces a TaskResult. The human can approve the result, which closes the loop, or reject it and provide feedback. Rejected results are sent back into the processing loop so the agent can revise them.
What changes were needed to support Result-Approval HITL?Supporting Result-Approval HITL required updates to both LLMAgent and TaskHandler. The framework adds a new request_approval() method, a with_approval flag in run(), and two new data structures: ApprovalResult and RejectedTaskResult. If a result is rejected, the feedback is fed back into the next processing cycle.
What happens when a result is rejected in Result-Approval HITL?When the human rejects a TaskResult, the system creates a RejectedTaskResult containing the failed result and the human’s feedback. That rejected result is then passed into the next get_next_step() call, allowing the agent to revise its approach. The review itself does not count as a new task step.
What is Supervised-Execution HITL?Supervised-Execution HITL gives the human operator full control over the processing loop. Instead of the agent automatically advancing through get_next_step() and run_step(), the human manually invokes each step and inspects intermediate results. This is especially useful for debugging or development.
Why is Supervised-Execution HITL best suited for development rather than production?Because it requires a human to oversee every step, it is slower and more hands-on than the other HITL patterns. That makes it ideal for understanding how an agent behaves, diagnosing failures, and refining the system. In production, lighter-weight oversight patterns like tool-based input or result approval are usually more practical.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Build a Multi-Agent System (from Scratch) Build a Multi-Agent System (from Scratch) ebook for free
Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Build a Multi-Agent System (from Scratch) Build a Multi-Agent System (from Scratch) ebook for free