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