Human In The Loop
Last updated
Last updated
In the previous tutorials, we explored how an Agent can dynamically use tools to answer queries or complete assigned tasks. Human-in-the-loop adds a layer of control by allowing the Agent to request human input, approval, or feedback before proceeding.
There are 2 ways human in the loop can be used:
Using node to halt the execution
Enable Require Human Input for Agent's tools
The Human Input node allows execution to be paused and only resumed after a human has provided feedback to either approve or reject the action.
In this tutorial, we’ll learn how to create an automated email reply agent that asks for user feedback before sending out the email.
The goal of this use case is to create an intelligent email reply system that:
Receives incoming email inquiries
Generates professional email responses using AI
Requests human approval before sending
Allows for revisions and improvements
Automatically sends the approved email
Drag and drop the Start node onto the canvas. This will be the entry point for incoming email data.
Configure the Start node with the following settings:
Input Type: Select "Form Input" to capture structured email data
Form Title: "Email Inquiry"
Form Description: "Incoming email inquiry"
Add the following Form Input Types:
Subject (String): To capture the email subject line
Body (String): To capture the email content
From (String): To capture the sender's email address
Add an Agent node and connect it to the Start node. This agent will analyze the incoming email and generate an appropriate response.
Add system message, for example:
Add the following tools to enhance the agent's capabilities:
Google Custom Search: To research customer information and provide relevant context
Current DateTime: To include accurate timestamps in responses
Add a Human Input node and connect it to the Email Reply Agent. This creates the human-in-the-loop checkpoint.
Configure the Human Input node:
Description Type: "Fixed"
Description: "Are you sure you want to proceed?"
Enable Feedback: True (allows humans to provide additional feedback)
This node will pause the workflow and present the AI-generated response to a human reviewer. The reviewer can either:
Proceed: Approve the response and continue to email sending
Reject: Send feedback and loop back to the agent for improvements
Add a Loop node to handle rejection scenarios. This allows the workflow to return to the Email Reply Agent for improvements.
Configure the Loop node:
Loop Back To: Select "Email Reply Agent" from the dropdown
Max Loop Count: 5 (prevents infinite loops)
Connect the "reject" output from the Human Input node to this Loop node. When a human rejects the response, the workflow will return to the agent with the feedback for improvement.
Add an LLM node and connect it to the "proceed" output of the Human Input node. This node will structure the approved response into proper email format.
Set up JSON Structured Output:
Key: "subject", Type: "string", Description: "Subject of the email"
Key: "body", Type: "string", Description: "Body of the email"
Add a Tool node and connect it to the Email Subject & Body LLM node. This will handle the actual email sending.
Configure the Tool node:
Tool: Select "Gmail" from the available tools
Message Actions: "sendMessage"
Configure the tool input arguments:
to: Use the variable {{ $form.from }}
to reply to the original sender
subject: Use {{ llmAgentflow_0.output.subject }}
to get the generated subject from Step 5
body: Use {{ llmAgentflow_0.output.body }}
to get the generated email body from Step 5
When an email inquiry comes in, here's what happens:
Form Input: The system captures the email subject, body, and sender information
AI Analysis: The Email Reply Agent analyzes the inquiry and generates a professional response using web search for additional context
Human Review: The workflow pauses and presents the AI-generated response to a human reviewer
Decision Point: The human can either:
Approve: The response proceeds to email formatting and sending
Reject: The response returns to the agent with feedback for improvement
Email Formatting: If approved, the response is structured into proper email format with subject and body
Email Sending: The final email is automatically sent via Gmail to the original sender
Start the workflow by filling out the form with a sample email inquiry
Review the Agent response in the Human Input step
Reject the response and provide more feedback:
Review the revised response from Agent:
Proceed and verify that email is being sent correctly:
When an Agent decides to use tools, the following happens under the hood:
Given a user query, the LLM determines whether tool calls are needed.
If tool calls are identified from LLM output response, Flowise locates the matching tools and executes the corresponding functions.
The results from the tool executions are returned to the LLM.
The LLM then decides whether additional tool calls are required or if it has enough information to return the final response.
When Require Human Input is enabled, we place an additional checkpoint after tool calls are detected:
This is crucial for sensitive tool calls such as placing orders, bookings, meetings, sending emails, etc, where you need human confirmation and review.
We can use the sample email reply system above, but simplify it to have just a single Agent.
Add an Agent node and connect it to the Start node. This single agent will handle both email analysis and human approval.
Add a system message to Agent, for example:
Add the following tools:
Google Custom Search: For researching customer information
Gmail: For creating email drafts with human approval
Configure the Gmail tool:
Gmail Type: "drafts"
Draft Actions: "createDraft"
Require Human Input: ✅ Enable this option - This is the key feature that creates the HITL functionality
Form Input: User submits email inquiry details
AI Analysis: The agent analyzes the email and uses Google Search for additional context
Draft Creation: When the agent attempts to create a Gmail draft, the workflow pauses
Human Review: The system presents the draft email for human approval
Decision: Human can approve (create draft) or reject (provide feedback and retry)
Start the workflow by filling out the form with a sample email inquiry
Before the Agent creates the Gmail draft, it will ask the user for approval or rejection.
If the tool is approved, the Agent will proceed to call the tool and create the draft in Gmail. The Agent is smart enough to determine the appropriate subject, body, and recipient for the email.
From the dashboard left side bar, click Executions.
Find the Execution trace, and click Share.
The execution trace is now available as a public link. You can share this link with others for review.
Users outside of Flowise can reject or approve: