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
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
Build a Multi-Agent System (from Scratch) ebook for free