Understanding the Boundary Between AI Agents and Design Patterns Through Human-in-the-Loop Practice
A user reply does not by itself make an agent system controllable. This article explains why prompt- and tool-description-based clarification is not the same as engineered human-in-the-loop (HITL) control, and how state machines, interceptors, the command pattern, and the strategy pattern can pause execution, preserve task state, and resume safely after human input or approval.
1. Where the Problem Starts: A User Can Reply Without the System Being Controllable
The value of an agent is that it turns a natural-language goal into executable action: understand the task, create a plan, choose tools, handle results, and adjust later steps based on feedback. Business goals, however, are often incomplete, and execution can surface new situations that require human judgment.
Consider a request such as “Summarize last month’s orders and send the summary to the relevant owners.” Several questions remain open:
- Which time zone and business cycle define “last month”?
- Should the summary include all orders, or only completed ones?
- Who are the “relevant owners”?
- Does the summary contain sensitive fields?
- Is approval required before sending?
One common approach is to instruct the agent, in the system prompt, to ask the user when it encounters ambiguity. Another is to emphasize required parameters, format constraints, and missing-information rules in tool descriptions.
Both approaches are useful for ordinary clarification. They mainly address how to make the model ask a question. They do not automatically solve how the system pauses, saves state, and safely resumes execution.
HITL—human-in-the-loop collaboration—focuses on that second problem. A person should be able not only to join the conversation, but also to supply information, review a plan, modify a candidate action, or stop the task at an explicit execution point.
Multi-turn questioning should not simply be treated as ineffective HITL. The more accurate distinction is this: ordinary follow-up questions provide participation at the conversation level, while engineered HITL adds control at the execution level.
2. Why Prompts and Tool Descriptions Are Still Limited
2.1 Conversation History Is Not Reliable Execution State
Multi-turn dialogue usually stores information in the message history. After new input arrives, the agent interprets the task again in light of earlier content.
The problem is that a transcript is a carrier of expressed information. It is not naturally the same thing as structured, validated business state. When history grows long, the system may summarize, trim, or extract it. During that processing, negative conditions, time ranges, user revisions, and the source of parameters can all be weakened.
For example, a user may first say “do not include canceled orders,” and later add “group by department.” If the earlier constraint is not stored reliably, the model may produce a query that groups correctly but filters incorrectly.
Even keeping every original message does not guarantee that the model will interpret them the same way every time. Model reasoning is uncertain, and long context also increases processing cost.
A more robust approach is to store confirmed facts separately from the raw conversation:
- Conversation records explain intent and support interaction traceability.
- Structured state stores confirmed parameters.
- Parameter provenance distinguishes user input, system defaults, and model inference.
- State versions identify changes and conflicts.
The model then does not have to “dig out” every execution condition from natural-language history on each turn.
2.2 Tool Descriptions Cannot Replace Parameter Validation
A tool description can tell the model what a parameter should satisfy, but it cannot guarantee that the model will produce a valid value.
Three layers need to be distinguished:
- The first is model prompting, such as stating that a date must be complete or that recipients must be explicit.
- The second is programmatic validation, such as checking date format, field type, enum range, and required fields.
- The third is business validation, such as confirming that a recipient is allowed to view the data and that the target belongs to the current user’s accessible scope.
The model can help with understanding and suggestions. Whether a format is legal, a permission is satisfied, or a business rule passes should be decided by deterministic program logic.
If every tool independently maintains its own follow-up rules, semantic inconsistency and duplicated maintenance become likely. Rules that should be handled uniformly belong in a shared validation layer. Constraints that truly belong to a tool should remain at that tool’s execution boundary.
2.3 Dynamic Tool Loading Magnifies the Recovery Problem
Some agents load tool definitions only when needed, in order to control context size. After the user supplies missing information, a full replan does not necessarily select the previous tool again.
That does not mean dynamic loading is inherently unreliable. It means a pending action should not exist only in the model’s temporary context.
On pause, record the candidate action, required parameters, and the relevant definition version. On resume, first check whether that information is still valid, then decide whether to continue or replan. An updated or expired tool definition must not be reused with old parameters without verification.
3. The Core of HITL: Pause Execution Authority, Keep Task State
Engineered HITL can be summarized as follows:
When execution reaches a point that requires a human decision, the system blocks subsequent protected actions, saves the necessary state, and, after valid feedback arrives, continues the task from an explicit position.
“Keeping one continuous conversation” should be understood as logical continuity of the task, not as a requirement to keep the same network connection, thread, or model request open.
Human feedback may arrive in seconds or hours. Holding execution resources the entire time easily leads to connection timeouts, wasted resources, and process failures.
A reasonable implementation usually does the following:
- Save an execution checkpoint.
- Create a pending human-intervention item.
- Mark the task as waiting.
- Release execution resources that no longer need to be held.
- Resume the task after feedback arrives.
A new model call may occur underneath, but it should serve the same task instance and read explicit execution state, rather than guessing progress entirely from message history.
HITL continuity is therefore continuity of state and control flow, not a physical connection that never closes.
4. Agents and Design Patterns: A Division of Boundaries, Not a Replacement
The contrast in the original question can be understood as a difference between two modes of control.
Agents emphasize dynamic decisions: given a goal and context, decide what to do next. Traditional design patterns emphasize stable collaboration: use explicit interfaces, state, and call relationships so the system runs predictably.
There is tension between them, but they are not mutually exclusive.
A more reasonable architecture lets the agent handle reasoning over open problems, while deterministic code handles constraints, permissions, state transitions, and side effects.
4.1 State Machines: Make Execution Stages Identifiable
A task can be abstracted into states such as:
Created → Planning → Validation → Waiting for human → Resuming → Executing → Completed
Failure, cancellation, and timeout branches should also be considered. Different tasks may use different state divisions; the same enum does not have to be applied mechanically.
A state machine makes clear which operations are allowed in the current stage. A task in “waiting for approval,” for example, cannot go directly to an external send step. After approval arrives, the system must also verify that the approval applies to the current version of the action.
“Cannot continue” then becomes a constraint the program can enforce, not merely a prompt the model is hoped to follow.
4.2 Interceptors and Hooks: Centralize the Execution Boundary
A unified interception point can be placed before tool calls to check:
- whether parameters are complete;
- whether data-access permissions are satisfied;
- whether operational risk triggers human review;
- whether the current approval is valid;
- whether there is a risk of duplicate execution.
Hooks can carry extension logic, but safety cannot be inferred from the hook’s name alone. What matters is whether the hook sits on the mandatory path of every protected action.
If any call path can bypass the check, the system may still produce side effects without approval.
4.3 Command Pattern: Turn an Action into an Inspectable Object
Representing a pending action as a structured object makes it easier to display, validate, approve, and audit.
An action object can include the operation type, target, parameters, task version, and expected impact. This is a general modeling approach, not a fixed interface of any particular product.
“Send the summary report,” for example, should not remain only a sentence generated by the model. It should correspond to explicit recipients, attachment content, data scope, and delivery method.
What a human approves should be that concrete action, not a vague “allow the agent to continue.”
4.4 Strategy Pattern: Distinguish Risk Levels
Not every missing parameter requires formal approval.
Low-risk read-only operations can run automatically once parameters are valid. Operations that involve external delivery, data modification, or irreversible effects can use a stricter confirmation mechanism.
Separating risk judgment from the concrete tool implementation helps keep rules in one place. A risk policy still cannot replace underlying permission control: even after approval, permissions must be checked at execution time.
5. Implementation Paths for Two Typical Scenarios
Scenario 1: Missing Parameters, Then Continue the Query After User Input
The user asks: “Query abnormal orders from the recent period.”
The agent recognizes that the time range is unclear and forms a candidate query. During parameter validation, the system finds that start and end dates are missing and creates a human parameter-completion item.
The interface should not only say “please provide more information.” It should also show:
- the current task goal;
- confirmed filters;
- missing fields and what they are used for;
- acceptable input forms;
- a way to cancel the task.
After the user supplies dates, the system first checks format and business scope, then writes valid values into structured state. It then resumes from the checkpoint before the query, rather than unconditionally replanning the entire task.
If the added content changes the original scope—for example, the user also asks to delete the abnormal orders—that should be recognized as a task change. The plan and risk should be reassessed, not merged in as an ordinary parameter.
Scenario 2: A High-Risk Action Still Needs Re-Verification After Approval
The user asks the system to generate a summary report and send it to multiple recipients.
The system can first complete the read-only data query and report generation, then enter approval before the actual send. The approval view should show recipients, report content, data scope, and possible sensitive information.
After approval, the system should still check:
- whether the report matches the version that was approved;
- whether recipients have changed;
- whether the current operator still has permission;
- whether the approval has expired;
- whether the send has already been executed.
If key content changes, the old approval should not automatically cover the new action.
Approval is not a permanently valid “agree” flag. It is an authorization record for a specific task version and a specific action payload.
6. An Illustrative Execution Flow
The pseudocode below only shows the division of responsibilities. It does not correspond to any concrete framework interface:
Handle candidate action(task, action):validation result = Validate parameters and business constraints(action)if required parameters are missing:Save checkpoint(task, action)Create parameter-completion item(task, missing fields)Update task state to waiting for humanreturnif validation fails:Record the failure reasonBlock executionreturnif approval is required and there is no valid approval for the current action:Save checkpoint(task, action)Create approval item(task, action summary, action version)Update task state to waiting for humanreturnRecheck permissions, action version, and duplicate-execution recordsExecute actionSave execution resultAdvance task state
Handle human feedback(item, feedback):Verify feedback identity and operation permissionCheck whether the item is valid and not expiredCheck whether the task version matchesif the user cancels:Mark the task canceledreturnValidate and save feedbackUpdate the item and task state in a controlled transactionSubmit a task-resume event
A failure can still occur between executing an action and saving its result. Querying a record once before execution cannot fully prevent duplicate operations. The failure window also needs idempotent design, a unique execution identifier, transaction boundaries, and result reconciliation.
7. Engineering Details That Cannot Be Omitted in Production
7.1 Consistency Between Persistence and Event Delivery
If task state has already become “resumable” but the resume event is not successfully submitted, the task may stall indefinitely. Conversely, if the event is submitted while the state is not updated, recovery may be incorrect.
Design a consistency mechanism for the system’s conditions—for example, save state and the outbound event in the same transaction, then have an independent process deliver it reliably. Consumers should also tolerate duplicate events rather than assume an event arrives only once.
7.2 Concurrent Feedback and Version Conflicts
The same approval item may be handled by multiple users at once, or submitted more than once because of repeated clicks.
The system should use state checks, version control, or atomic updates so the item has only one valid terminal transition. Late feedback must not overwrite a rejection or cancellation that has already taken effect.
7.3 Human Input Is Not a Trusted Instruction
Text supplied by a person may also contain instructions unrelated to the task, or attempts to change tool-use rules.
For parameter completion, prefer parsing feedback into fields that are allowed to change, rather than promoting the entire input to a high-priority instruction. Free-text changes should go through intent recognition, permission checks, and risk assessment again.
7.4 Timeout, Rejection, and Revocation
Waiting for a human is not waiting forever. The system needs an explicit timeout behavior: remind, escalate, cancel, or keep the task but forbid continuation.
Rejection should be handled as a normal business outcome, not lumped into system errors. After approval is revoked, execution can be blocked if the action has not run. If the side effect has already occurred, compensation depends on business capability; not every operation can be assumed to roll back.
7.5 Audit and Privacy
Audit records should cover the reason for intervention, the version of the pending action, the person who responded, the outcome, and the action actually taken after resume.
Logs and approval views should follow least disclosure. Keeping enough information for traceability is not the same as copying all sensitive data, and it does not mean the model’s internal reasoning must be stored.
8. How to Tell Whether HITL Is Actually Effective
Evaluating HITL is not only a matter of whether the user replied. Task quality and system controllability also need to be observed.
Useful indicators include:
- whether, after human intervention, the task resumes from the correct point;
- whether confirmed parameters stay consistent in later steps;
- whether unapproved actions are reliably blocked;
- whether duplicate calls or duplicate side effects occur;
- whether timeout, rejection, and cancellation paths are complete;
- whether users can understand why the system is waiting and what approval affects;
- whether resume triggers unnecessary full replanning.
Tests should not cover only the happy path. They should also simulate process exit, duplicate feedback, permission changes, tool-definition updates, and content changes after approval.
9. Conclusion: Use Deterministic Boundaries to Carry Uncertain Reasoning
HITL is not a confirm button added to a chat window, and it is not a matter of writing more constraints into a prompt. It is an execution-control mechanism built around human participation.
Multi-turn questions clarify intent. Structured state stores facts. Checkpoints support recovery. Interceptors hold the execution boundary. Approval expresses a specific authorization. Audit provides traceable evidence.
The division between agents and design patterns then becomes clear: the former supplies flexible reasoning for open tasks, and the latter supplies stable constraints for real business operations.
Reliable human–agent collaboration does not mean people constantly chase the agent’s output. It means people can take execution authority when needed, while the system accurately stores, understands, and carries out that control.
