Skip to content
AI Support Agent

Module 08 · ai · intermediate

Solutions 08 · AI Support Agent

Exercise 1

  1. Create a sheet Orders with columns order_id, email, status, items, carrier, tracking, estimated_delivery and copy the three demo orders in.
  2. Delete the lookup_order Code tool. Add a Google Sheets Tool named lookup_order:
    • Description: same as before
    • Operation: Get Row(s), your document, sheet Orders
    • Filters: column order_id, value {{ $fromAI('order_id', 'The order ID, format A1234', 'string') }}
  3. In the system message, add: "If lookup_order returns nothing, the order doesn't exist."

$fromAI() tells n8n the model should fill that parameter, so you don't need a Code node at all.

Exercise 2

Sub-workflow 08 - Create Ticket:

When Executed by Another Workflow (summary, customer_contact, priority)
  → Edit Fields: ticket_id = {{ 'T-' + Math.floor(10000 + Math.random() * 90000) }}, created_at = {{ $now.toISO() }}
  → Google Sheets: Append Row to "Tickets"
  → Telegram/Slack/Gmail: "🎫 {{ $json.ticket_id }} ({{ $json.priority }}): {{ $json.summary }} ({{ $json.customer_contact }})"
  → Edit Fields: return { ticket_id, reply_within: '1 business day' }

Publish it. In the agent workflow, replace the Code tool with Call n8n Workflow Tool named create_support_ticket, pick the sub-workflow, keep the description, and map each input with $fromAI('summary'), $fromAI('customer_contact'), $fromAI('priority').

Exercise 3

  1. Chat Trigger → Mode Embedded Chat; Options → Allowed Origins: http://localhost:8080.
  2. index.html:
<link href="https://cdn.jsdelivr.net/npm/@n8n/chat/dist/style.css" rel="stylesheet" />
<script type="module">
  import { createChat } from 'https://cdn.jsdelivr.net/npm/@n8n/chat/dist/chat.bundle.es.js';
  createChat({ webhookUrl: 'http://localhost:5678/webhook/course-08-support-chat/chat' });
</script>
  1. Serve it: python3 -m http.server 8080 and open http://localhost:8080.

Pin a specific @n8n/chat version in production instead of the latest.

Stretch

Copy test/test.sh, put your 10 cases in a cases.json (message, expect regex), loop with jq -c '.[]', and print a pass rate. Run it before and after each prompt change; that's a basic eval harness.