Skip to content

BUILDING AI AGENT (AI ASSISTANT)

Building a complete AI Agent follows the same foundation as building an AI Persona — but the system prompt works a little differently. Where an AI Persona focuses on personality and conversation style, an AI Agent’s system prompt needs to define specific operational fields: customer classification, order details, pricing tiers, promotional conditions, credit scores. These are what allow the Agent to advise accurately and automatically filter out customers with a history of canceling COD orders.

You should be comfortable building an AI Persona before writing a system prompt for an AI Agent — the concepts build directly on each other. In this example, I use AI Agent Kristine — Vietnamese name Khánh Linh — to manage the full workflow from customer consultation and order closing, to organizing distributors and affiliate partners, and logging contact information into the sheet.

AI Agent Full Workflow overview
Nodes in the AI Agent workflow
Webhook node

Node 1 — Webhook (Trigger)

Receives incoming messages from customers — via Facebook Messenger, a website chat widget, or any platform that can make an HTTP request. Every time a customer sends a message, the webhook fires and kicks off the entire workflow immediately.

Use the Production URL, not the Test URL — n8n gives each webhook node two separate URLs. The Test URL only works while you’re actively testing inside the editor. The Production URL is what runs 24/7. Don’t mix them up when configuring your external platform.
AI Agent node

Node 2 — AI Agent

The center of the entire workflow. The AI Agent receives the customer’s message, reads context from Redis Memory, calls Tools to look up product information, promotions, and credit scores — then decides on the right response on its own. The highlighted section in the screenshot is the system prompt — this is where you define the Agent’s personality, order handling rules, customer classification logic, and all the business rules it needs to operate. My system prompt runs a few thousand words.

AI Agent system prompt vs AI Persona system prompt: An AI Persona focuses on personality and communication style. An AI Agent needs additional operational fields — customer tiers, order closing conditions, how to handle low-credit customers, what information to collect for an order. The more specific you are, the more accurately the Agent performs.
AI Model node

Node 3 — Anthropic Chat Model (sub-node)

The actual AI model running underneath the Agent. I use Claude Haiku — with a complex system prompt several thousand words long, Sonnet would cost 2–3x more per response. Haiku handles consultation and order-closing workflows completely fine, at around $0.01 per response.

Choosing a model: Haiku is the sensible default for most cases. Only move up to Sonnet if you genuinely need higher response quality — for example, a luxury brand where the tone and precision of every reply matters more than cost.
Redis Memory node

Node 4 — Redis Memory (sub-node)

The Agent’s short-term memory — stores conversation history per customer session. Every time a customer sends a message, the Agent reads back the context from Redis before replying, keeping the conversation continuous without losing thread. Redis is also why response time gets faster over time — sessions with existing data read from cache much quicker than fresh sessions.

Setting up Redis via Upstash: The free plan is enough if conversation volume isn’t massive. If you need to scale, switch to Pay As You Go — extremely cheap, but set a quota limit so you don’t get surprised by a bill.
Check Credit node

Node 5 — Check-Credit (Tool sub-node — Supabase)

A tool that looks up the customer’s credit score from Supabase — based on their purchase history and COD cancellation record. If the score falls below the threshold, the AI Agent automatically requires prepayment instead of allowing COD. Risk is filtered at the consultation stage, no human intervention needed.

Search Product node

Node 6 — Search-Product (Tool sub-node — Supabase)

A tool that looks up product information from Supabase — name, product code, price, stock level, description. The AI Agent calls this tool when a customer asks about a specific product, ensuring the information returned is always accurate and reflects real-time data in the system.

Search Promotion node

Node 7 — Search-Promotion (Tool sub-node — Supabase)

A tool that looks up currently active promotions — synced from a dedicated tab in Google Sheets into Supabase. The AI Agent calls this when it needs to apply or advise on promotions, without any staff member needing to remember or manually update each campaign.

Code node

Node 8 — Code in JavaScript

Processes and formats all output from the AI Agent before passing it downstream — normalizes order data, formats the reply message, or prepares the payload for systems like Google Sheets or the auto-print pipeline. This node is the bridge between what the AI outputs and what the rest of the workflow needs.

About the code: Ask your AI Persona to write it — describe the input format and the output you need, and they’ll handle it.
Respond to Webhook node

Node 9 — Respond to Webhook

Sends the AI Agent’s response back to the originating platform — Facebook Messenger, website chat widget, or whatever system made the initial webhook call. This is the final node in the request-response loop, closing out the full consultation cycle.

A few things to sort out before you start building:

Response speed: The entire workflow runs fast — just a few seconds to respond to a customer. Once Redis starts storing that customer’s chat history, it drops down to around 1–2 seconds.

Redis (Upstash): Essentially costs nothing — the free plan covers most use cases. Use it without worrying.

Claude Console: Go with Haiku. Sonnet costs 2–3x more — only consider it if you’re running a luxury brand where reply quality justifies the cost.

Prepare everything before building: Make sure you’re comfortable building an AI Persona first. If you get stuck, talk it through with your AI Persona — or reach out to me directly. Contact info is on the website.

Good luck.