[KongchangAI]
· 3 min read· 1,697 words

n8n + Gemini Customer Support Agent: Auto-Escalating Refunds and Angry Customers to Humans

n8n + Gemini Customer Support Agent: Auto-Escalating Refunds and Angry Customers to Humans

Open-source n8n + Gemini customer support Agent prototype using knowledge base constraints and human fallback to control risk.

The article introduces an open-source customer support AI Agent prototype built on n8n and Gemini, positioned as a portfolio project but with practical reference value. The system chains knowledge base retrieval, sentiment detection, and refund ticket escalation into an automated pipeline. Core design: the Gemini Agent is strictly constrained to answer only from the Postgres knowledge base and can call an order_lookup tool; a Code node validates the category, sentiment, and escalate fields before routing; refunds and angry customers are forcibly escalated to Slack, with all tickets logged. The author argues this "AI for standard issues, humans for high-risk ones" split beats full automation on ROI. The article also covers open questions (sentiment thresholds, confidence scores, failure case testing) and production gaps like real webhook integration, vector retrieval replacing keyword matching, and an annotated evaluation system.

A Reusable Customer Support Automation Prototype

In B2C businesses, the speed and accuracy of handling customer support tickets directly affect repeat purchase rates. Recently, a developer on Reddit shared a customer support AI Agent project built on n8n and Gemini. It's positioned as a portfolio prototype, but several of its design decisions offer useful reference for teams preparing to deploy AI customer support.

The pain points the project addresses are very specific: knowledge base retrieval, sentiment detection, and routing refund-related tickets to humans—three steps chained into a single automated pipeline. The author open-sourced the workflow JSON, deployment steps, and SQL on GitHub, lowering the barrier to reproduction.

According to the original Reddit post, the system currently runs on simulated tickets covering four scenarios: logistics inquiries, angry refunds, password resets, and order cancellations. The next step is to integrate real helpdesk webhooks and replace keyword matching with a vector store.

reddit source: Built a customer support AI agent in n8n that escalates refunds and angry customers to a human (Gemi

Workflow Breakdown: Three Things That Determine Success

Knowledge Base Matching and Tool Calling

Each ticket is first matched against knowledge base articles stored in Postgres. The Gemini Agent is strictly constrained to answer only based on the matched article content, and can also call an order_lookup tool to query order status. This constraint is the foundation of the entire solution's reliability—without it, the LLM can easily fabricate refund policies or delivery timelines.

RAG (Retrieval-Augmented Generation) is the theoretical basis of this approach: the system first retrieves document fragments relevant to the user's question from an external knowledge base, then injects these fragments as context into the prompt, letting the model answer "based on the given materials" rather than relying on pre-trained memory. The Postgres knowledge base matching in the article is a typical retrieval step, while "answering only based on matched article content" is a common practice for constraining the generation stage in RAG. The value of RAG lies in updatable knowledge, traceable answers, and controllable hallucinations—but it is highly sensitive to retrieval quality. When the correct documents aren't recalled, the model either refuses to answer or answers incorrectly, which is exactly why the article later emphasizes replacing keyword matching with vector retrieval.

Tool Calling (Function Calling / Tool Use) refers to the LLM outputting structured call requests during generation, which external programs execute and return results to the model for continued reasoning. The order_lookup in the article is one such tool: the model initiates a call when it determines it needs order status, receives real data, and then composes its reply. The significance of tool calling is that it separates deterministic operations like "looking up data" from model reasoning, preventing the model from fabricating order status through guesswork while enabling the Agent to access real-time, private business data.

Structured Output and Code Node Validation

The Agent returns three fields: category (ticket classification), sentiment (emotional disposition), and escalate (whether to escalate to a human). Before routing, a Code node validates the output format to prevent non-structured content from the model breaking downstream flows. This step is easily overlooked but critical for production environments.

Tiered Routing

Tickets flagged for escalation are pushed to Slack for human takeover; all tickets, regardless of escalation status, are written to Postgres for record-keeping. The entire tech stack uses free tiers: n8n for orchestration, Gemini for reasoning, Supabase Postgres for storage, and Slack for the human handoff.

n8n is an open-source workflow automation tool that uses node-based visual orchestration. Each node represents an operation (HTTP request, database read/write, conditional branch, code execution, etc.), and connections between nodes define data flow. It supports self-hosting, includes numerous built-in integrations, and allows custom logic via Code nodes written in JavaScript—the structured output validation in the article is done precisely in a Code node. Compared to pure-code frameworks like LangChain, n8n's advantages are visual flows, independently debuggable nodes, and routing logic that non-engineering roles can understand; the trade-off is that complex logic is less flexible to express than in code.

Supabase is an open-source backend platform built on Postgres, offering hosted database, authentication, storage, and vector search (pgvector). The article uses it for both knowledge base storage and ticket record-keeping. The main motivation for choosing Supabase over self-hosted Postgres is the free tier and out-of-the-box experience, which also explains why the author describes the entire tech stack as "all using free tiers."

Why "Refunds and Angry Customers Must Go to Humans" Is a Smart Design

The author explicitly set a hard rule in the post: any request involving refunds or emotionally charged customers goes to a human. This isn't a compromise on technical capability—it's risk control. Refund decisions involve amounts, policies, and customer relationships; if the AI misjudges, the cost far exceeds human labor costs. Angry customers require empathy and flexible handling, and current LLMs remain unstable in such scenarios.

From an engineering perspective, this division of labor—"AI handles standard issues, humans handle high-risk issues"—is closer to actual business needs than pursuing full automation. The real bottleneck for most customer support teams isn't too many simple questions, but complex issues consuming senior agents' time. Automating standard inquiries and freeing up staff to handle refunds and complaints yields clearer ROI.

reddit source: Built a customer support AI agent in n8n that escalates refunds and angry customers to a human (Gemi

Three Open Questions the Author Left Behind

The original author posed several questions to the community, which happen to be exactly what this solution must address to reach production:

How should the sentiment threshold be set? Currently the sentiment field is judged freely by the model with no quantitative standard. In practice, one could introduce tiered labels (e.g., neutral / frustrated / angry) and set different escalation strategies for each level, rather than a single boolean.

Should a confidence score be added? This is a worthwhile enhancement. When the model's confidence in an answer falls below a threshold, it should escalate to a human even if no refund rule is triggered. Confidence can come from retrieval similarity scores or from model self-assessment.

What other failure cases should be tested? Suggestions include multi-intent tickets (a single ticket asking about logistics and also requesting a refund), long-tail questions not covered by the knowledge base, adversarial inputs (prompts that induce the model to bypass escalation rules), and cases where the order_lookup tool times out or returns empty values.

Confidence scores typically have two sources in engineering: first, similarity scores on the retrieval side (such as vector cosine similarity or keyword match scores), reflecting "whether the retrieved material is sufficiently relevant"; second, model self-assessment on the generation side, where the model provides a 0-to-1 confidence level alongside its answer. The former is objective but only measures recall quality; the latter covers reasoning uncertainty but suffers from overconfidence. In practice, the two are often combined, with a fallback rule to escalate to humans when below a threshold—directly related to the "missed escalation" risk raised in the article.

False escalations and missed escalations are a trade-off: lowering the escalation threshold reduces missed escalations but increases false ones, driving up labor costs and eroding automation benefits; raising the threshold does the opposite. These two metrics cannot be optimized simultaneously—thresholds must be set based on the business's tolerance for error costs, with annotated test sets used to separately measure the two error rates rather than looking only at overall accuracy.

What's Still Missing from Prototype to Production

The author himself identified two upgrade directions: integrating real helpdesk webhooks and replacing keyword matching with a vector store. The latter has a major impact on recall—keyword matching is fragile against synonymous expressions and colloquial descriptions, while vector retrieval can significantly improve knowledge base hit rates.

Another equally critical point not expanded upon in the post is the evaluation system. Simulated tickets can verify that the flow works, but cannot measure classification accuracy and escalation recall. Before launch, a set of annotated real tickets is needed as a test set, with continuous monitoring of two error types: false escalations (routing simple questions to humans) and missed escalations (auto-replying when a human should have been involved).

For developers wanting to reproduce this project, the author's GitHub repository provides the complete workflow JSON and SQL, making it a suitable starting point for n8n-based customer support automation. One caveat: free-tier Gemini has concurrency and rate limits, so quota needs to be evaluated under real traffic.

FAQ

What team size is this solution suitable for? Best suited for small-to-medium teams or customer support automation starter projects; n8n's visual orchestration lowers the maintenance barrier, and free tiers keep experimentation costs down.

Why choose n8n over a pure-code framework? Workflow visualization lets customer support operations staff without engineering backgrounds understand and adjust routing logic, and debugging individual nodes is more intuitive than debugging an entire codebase.

How does Gemini perform in customer support scenarios? The original post provides no quantitative evaluation, but by design, knowledge base constraints and tool calling limit the model's room for improvisation—a common approach to improving stability.

One-line Summary

Open-source n8n + Gemini customer support Agent prototype using knowledge base constraints and human fallback to control risk.

Paragraph Summary

The article introduces an open-source customer support AI Agent prototype built on n8n and Gemini, positioned as a portfolio project but with practical reference value. The system chains knowledge base retrieval, sentiment detection, and routing refund-related tickets to humans into an automated pipeline. Its core design has three points: the Gemini Agent is strictly constrained to answer only based on the Postgres knowledge base and can call an order_lookup tool; a Code node validates the three structured fields category, sentiment, and escalate before routing; refunds and angry customers are forcibly escalated to Slack for human handling, with all tickets logged to the database. The author believes this division of labor—"AI handles standard issues, humans handle high-risk issues"—is closer to business reality than pursuing full automation, with clearer ROI. The article also covers three open questions (sentiment thresholds, confidence scores, failure case testing) and production gaps such as integrating real webhooks, replacing keyword matching with vector retrieval, and building an annotated evaluation system.

#n8n#Gemini#customer support AI Agent#RAG#workflow automation
Share:

Related articles