Human-in-the-Loop Automation with n8n — Liam McGarrigle

By AI Engineer

Share:

Key Concepts

  • n8n: A low-code/no-code workflow automation tool that allows users to build complex integrations and AI agents visually.
  • AI Agent Node: A specialized node that acts as an orchestrator, capable of using various tools (like Gmail or Google Calendar) to perform tasks.
  • Human-in-the-Loop (HITL): A safety mechanism that intercepts "destructive" or sensitive actions (e.g., sending emails) to require manual approval before execution.
  • Expressions: JavaScript-based logic used within n8n fields to manipulate data, format dates, or reference outputs from previous nodes.
  • Tools: Individual nodes (e.g., Gmail, Google Calendar) that the AI agent can invoke at its discretion based on its system prompt.
  • Memory: A feature that allows the AI to maintain context across multiple chat turns, with options ranging from "Simple Memory" to external databases like PostgreSQL.
  • MCP (Model Context Protocol): A standard for connecting AI agents to external systems, allowing n8n to interact with other platforms like Claude Code.

1. Building an AI Agent Workflow

The workshop focused on creating a Gmail and Google Calendar management agent. The process follows a modular architecture:

  • Trigger: The workflow starts with a Chat Trigger, which provides an interface to interact with the agent.
  • AI Agent Node: The core component that connects to an LLM (e.g., Claude 3.5 Sonnet via OpenRouter).
  • Memory: Essential for conversational continuity. The "Simple Memory" setting is recommended for beginners, with the context window length adjustable to manage token usage.
  • Tools: By adding nodes like "Gmail: Send Email" or "Google Calendar: Create Event" as tools, the agent gains the ability to perform actions autonomously.

2. Human-in-the-Loop (HITL) Methodology

To prevent the agent from performing unauthorized or erroneous actions, a review step is implemented:

  • Implementation: After adding a tool node, users can click the "+" button to insert a Human Review step.
  • Mechanism: The agent attempts to call the tool, but the workflow pauses at the Human Review node. The user receives a prompt in the chat interface to "Approve" or "Decline" the action.
  • Customization: Users can use expressions (e.g., {{ $json.tool.parameters.subject }}) to display specific details of the proposed action to the human reviewer, ensuring they know exactly what they are approving.

3. Technical Best Practices

  • Prompt Engineering: The speaker emphasizes that the Node Name and Node Description are critical. The LLM uses these to understand what a tool does. Providing clear, descriptive text in the tool description is more effective than relying solely on a global system prompt.
  • Data Formatting: When dealing with dates or complex objects, use JavaScript expressions. For example, using {{ $now.toDateTime().format('DD-MM-YYYY') }} ensures that the AI provides human-readable information rather than raw UTC timestamps.
  • Error Handling: If a node fails, the error message usually provides the solution. For instance, when using the Chat Trigger, the "Response Mode" must be set to "Using Respond Nodes" to allow the workflow to pause for human review.

4. Advanced Scaling and Architecture

  • Sub-Agents: To avoid overwhelming a single agent with too much context, the speaker suggests building specialized sub-agents (e.g., one for GitHub issues, one for Jira, one for Calendar) and using an "Agent" node to orchestrate them.
  • REST API Integration: n8n workflows can be exposed as REST APIs using a Webhook trigger, allowing them to be called by external systems or other internal company tools.
  • Environment Management: For enterprise users, n8n supports Git integration, allowing for development, staging, and production environments to manage code changes and approvals.

5. Notable Quotes

  • "One of the problems we're seeing and where the winners are going to lie is seeing what your agent can do, knowing what it's doing, seeing what went wrong and being able to tweak it and fix it." — Liam, Developer Advocate at n8n.
  • "Everything that we would consider like destructive or sensitive, we can add a human review step... It just cannot get past this layer."

Synthesis/Conclusion

The workshop demonstrated that n8n is a powerful platform for building AI agents that are not only functional but also safe and controllable. By combining LLMs with visual workflow orchestration, users can automate complex tasks like email and calendar management. The key takeaway is the importance of the Human-in-the-Loop pattern, which provides the necessary "peace of mind" for deploying AI in professional environments. By leveraging modular tool design, proper prompt engineering, and n8n’s built-in debugging tools, developers can create robust, scalable automation systems.

Chat with this Video

AI-Powered

Load the transcript when you're ready to chat so the initial page stays lighter.

Related Videos

Ready to summarize another video?

Summarize YouTube Video