Overview

8 Human In The Loop

This chapter explains why human oversight is sometimes essential in an LLM agent workflow, especially when a task becomes ambiguous or when the stakes are high. It builds on earlier improvements to the agent and shows how humans can be brought into the loop at the right moment to provide clarification, approve results, or directly supervise execution. The central idea is that autonomy is valuable, but not every task should be left entirely to the model.

The chapter presents three human-in-the-loop patterns. First, a tool-based approach lets the agent request human input whenever it gets stuck, such as needing a preference or missing detail to continue. Second, a result-approval approach sends a completed task outcome to a human for review, and if rejected, the agent receives feedback and tries again. Third, a supervised-execution approach gives the human full control over each step in the processing loop, making it possible to inspect, modify, reject, or abort intermediate work. These patterns are implemented by extending the framework with new data structures, helper functions, and targeted updates to the agent and task handler logic.

The chapter also demonstrates these ideas in practice with examples such as computing the Hailstone sequence while asking for input, then later asking for approval of the final result, and finally stepping through the task manually under supervision. It closes by connecting these patterns to multi-agent systems, noting that tool-based and approval-based human oversight can carry over with adjustments, while full supervision is harder to apply across multiple agents unless a coordinator structure is used. Overall, the chapter shows how to design agent systems that remain useful and flexible while still allowing humans to intervene where reliability, safety, or development insight matters most.

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
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
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
UML class diagrams for ApprovalResult and RejectedTaskResult
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
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()
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
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

What is the main purpose of human-in-the-loop (HITL) task execution in this chapter?Human-in-the-loop task execution adds a human operator into parts of the agent workflow where autonomy is risky, ambiguous, or insufficient. In this chapter, HITL is used to improve reliability, handle ambiguity, provide oversight for high-stakes outputs, and allow deeper supervision during debugging or development.
When should an LLM agent ask a human for input during task execution?An LLM agent should ask for human input when execution becomes ambiguous and it cannot continue confidently on its own. A common example is when the agent has narrowed options but needs a preference or decision from the human, such as choosing between flight classes or selecting a restaurant cuisine.
What is Tool-Based HITL?Tool-Based HITL is a pattern where the agent uses a dedicated tool, HumanInputTool, to ask a human operator for clarification or additional information. The agent decides when to call the tool, and the tool returns the human’s response so execution can continue.
How is HumanInputTool implemented in the framework?HumanInputTool subclasses BaseTool and implements the required name, description, parameters_json_schema, and __call__() members. It accepts a prompt and optional choices, validates arguments, displays the request to the human, and returns the response as a ToolCallResult.
What happens if the human closes input or cancels a HumanInputTool prompt?If stdin closes before a response is received, the tool returns an error result indicating no input was received. If the human cancels with KeyboardInterrupt, the tool also returns an error result describing that the human declined to provide input.
What is Result-Approval HITL?Result-Approval HITL is a pattern where the agent completes a task and then a human reviews the final result before it is accepted. If the human approves, the loop ends; if the result is rejected, human feedback is sent back into the processing loop so the agent can revise its output.
What changes were needed to support Result-Approval HITL?Supporting Result-Approval HITL required updates to both LLMAgent and TaskHandler, plus new data structures: ApprovalResult and RejectedTaskResult. The agent’s run() method gained a with_approval option, and TaskHandler gained request_approval() and logic to feed rejected results back into get_next_step().
What is the purpose of RejectedTaskResult?RejectedTaskResult packages the failed task result along with the human’s feedback. It is then passed back into get_next_step() so the agent can create a new step that directly addresses the rejection rationale.
What is Supervised-Execution HITL?Supervised-Execution HITL gives the human operator full control over the processing loop. Instead of the agent automatically cycling through steps, the human manually invokes get_next_step() and run_step(), allowing inspection, modification, rejection, or approval of intermediate results.
Why does the chapter introduce SupervisedTaskHandler and run_supervised()?SupervisedTaskHandler is a specialized TaskHandler subclass that supports stepwise human control, including methods like complete(), reject(), and abort(). run_supervised() returns this handler so the human can drive execution manually instead of letting the agent run autonomously.

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


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) ebook for free
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) ebook for free