mirror of
https://github.com/khoaliber/n8nworkflows.xyz.git
synced 2026-04-28 00:29:22 +00:00
creation
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
Production AI Playbook: Human Oversight (1 of 3)
|
||||
|
||||
https://n8nworkflows.xyz/workflows/production-ai-playbook--human-oversight--1-of-3--13847
|
||||
|
||||
|
||||
# Production AI Playbook: Human Oversight (1 of 3)
|
||||
|
||||
This document provides a technical analysis of the **Production AI Playbook: Human Oversight (1 of 3)** workflow. This workflow automates the drafting of customer support responses while maintaining a "Human-in-the-loop" (HITL) architecture to ensure quality and accuracy before delivery.
|
||||
|
||||
### 1. Workflow Overview
|
||||
The workflow is designed to intake customer inquiries via a chat interface, generate a draft response using an AI Agent, and pause execution until a human operator reviews and approves or rejects the draft. Approved responses are automatically sent via Gmail, while rejected ones prompt the user for revisions.
|
||||
|
||||
**Logical Blocks:**
|
||||
* **1.1 Draft Generation:** Captures input and generates an AI-powered draft.
|
||||
* **1.2 Human Review:** Pauses the workflow to present the draft for manual validation.
|
||||
* **1.3 Routing & Fulfillment:** Executes the final action (sending an email) or flags the need for revision based on the human decision.
|
||||
|
||||
---
|
||||
|
||||
### 2. Block-by-Block Analysis
|
||||
|
||||
#### 2.1 Draft Generation
|
||||
This block handles the initial interaction and the reasoning required to create a support email.
|
||||
* **Nodes Involved:** `When chat message received`, `AI Agent`, `OpenRouter Chat Model`.
|
||||
* **Node Details:**
|
||||
* **When chat message received (Chat Trigger):** Acts as the entry point. Configured with `responseMode: responseNodes`, meaning the workflow explicitly controls what the user sees in the chat via subsequent nodes.
|
||||
* **AI Agent (LangChain Agent):** Uses a system message to act as a "Customer Support Assistant." It is programmed to be empathetic and accurate while avoiding unauthorized promises.
|
||||
* **OpenRouter Chat Model:** Provides the LLM logic (e.g., GPT-4 or Claude 3) via OpenRouter.
|
||||
* **Edge Cases:** Failure to connect to the LLM API will stop the draft generation.
|
||||
|
||||
#### 2.2 Human Review
|
||||
This block implements the "Human Oversight" requirement.
|
||||
* **Nodes Involved:** `Human Approval`.
|
||||
* **Node Details:**
|
||||
* **Human Approval (Chat Node):** Uses the `sendAndWait` operation. It displays the `{{ $json.output }}` from the AI Agent to the operator.
|
||||
* **Configuration:** Includes "Approve" (Send to Customer) and "Reject" (Revise) buttons.
|
||||
* **Wait Logic:** The workflow execution enters a "Waiting" state. It only resumes once a human clicks a button in the n8n Chat interface.
|
||||
* **Edge Cases:** If "Limit Wait Time" is reached (if configured), the node may time out.
|
||||
|
||||
#### 2.3 Routing & Fulfillment
|
||||
This block processes the human decision and interacts with external services.
|
||||
* **Nodes Involved:** `If`, `Gmail - Send Reply`, `Approved Response`, `Rejected Response`.
|
||||
* **Node Details:**
|
||||
* **If (Logic):** Checks the boolean expression `{{ $json.data.approved }}`.
|
||||
* **Gmail - Send Reply:** If approved, it sends an email to the customer. It uses the original AI Agent output as the body and defaults to `customer@example.com` if no email is found.
|
||||
* **Approved/Rejected Response (Chat Nodes):** These nodes send a final confirmation message back to the chat interface to inform the operator that the action is complete.
|
||||
* **Edge Cases:** Gmail OAuth2 expiration or invalid recipient email addresses.
|
||||
|
||||
---
|
||||
|
||||
### 3. Summary Table
|
||||
|
||||
| Node Name | Node Type | Functional Role | Input Node(s) | Output Node(s) | Sticky Note |
|
||||
| :--- | :--- | :--- | :--- | :--- | :--- |
|
||||
| When chat message received | Chat Trigger | Entry Point | - | AI Agent | Draft Response |
|
||||
| AI Agent | AI Agent | Content Drafting | When chat message received | Human Approval | Draft Response |
|
||||
| OpenRouter Chat Model | OpenRouter Model | LLM Provider | - | AI Agent | Draft Response |
|
||||
| Human Approval | Chat Node | HITL Interface | AI Agent | If | Human Review |
|
||||
| If | If Node | Decision Logic | Human Approval | Gmail, Rejected Response | Route and Send |
|
||||
| Gmail - Send Reply | Gmail Node | External Action | If (True) | Approved Response | Route and Send |
|
||||
| Rejected Response | Chat Node | Feedback | If (False) | - | Route and Send |
|
||||
| Approved Response | Chat Node | Feedback | Gmail - Send Reply | - | Route and Send |
|
||||
|
||||
---
|
||||
|
||||
### 4. Reproducing the Workflow from Scratch
|
||||
|
||||
1. **Trigger Setup:**
|
||||
* Add a **When chat message received** node.
|
||||
* Set **Response Mode** to "Using Response Nodes".
|
||||
2. **AI Integration:**
|
||||
* Add an **AI Agent** node.
|
||||
* Connect an **OpenRouter Chat Model** node (or OpenAI/Anthropic) to the AI Agent.
|
||||
* In the Agent's System Message, define the persona: *"You are a customer support assistant... draft a professional response."*
|
||||
3. **Human-in-the-loop Setup:**
|
||||
* Add a **Chat Node** (labeled "Human Approval").
|
||||
* Set **Operation** to "Send and Wait for Response".
|
||||
* Set **Response Type** to "Approval".
|
||||
* Configure **Approval Options**:
|
||||
* Approve Label: "Send to Customer"
|
||||
* Disapprove Label: "Revise"
|
||||
* Message content: `**Draft Response for Review** \n\n {{ $json.output }}`.
|
||||
4. **Logic Branching:**
|
||||
* Add an **If** node.
|
||||
* Condition: Boolean `{{ $json.data.approved }}` is equal to `true`.
|
||||
5. **Fulfillment & Feedback:**
|
||||
* **True Branch:** Add a **Gmail** node configured to "Send an Email". Use `{{ $("AI Agent").first().json.output }}` for the body.
|
||||
* Follow the Gmail node with a **Chat Node** (Response mode) saying "Response approved and sent."
|
||||
* **False Branch:** Add a **Chat Node** (Response mode) saying "Response was rejected. Please provide revision feedback."
|
||||
6. **Credentials:**
|
||||
* Configure **OpenRouter API** credentials.
|
||||
* Configure **Gmail OAuth2** credentials.
|
||||
|
||||
---
|
||||
|
||||
### 5. General Notes & Resources
|
||||
|
||||
| Note Content | Context or Link |
|
||||
| :--- | :--- |
|
||||
| This template is a learning companion to the Production AI Playbook. | General Guidance |
|
||||
| Complete technical strategy for building reliable AI systems in n8n. | [Link to blog](https://go.n8n.io/PAP-HO-Blog) |
|
||||
| Recommended: Swap Gmail for Outlook or SMTP as needed for your stack. | Customization Tip |
|
||||
| Use "Limit Wait Time" on Human Approval to prevent stale executions. | Performance Note |
|
||||
Reference in New Issue
Block a user