n8n Training Hub
Back to home

The assistant that sorts the requests

Agents

A company gets a mix of messages every day: quote requests, support questions, job applications, spam. Someone has to read them, work out what each one is, and route it. In this track you build an agent that does it: it classifies the message, extracts the key data in a structured way, and routes it toward different actions.

n8n nodes involved
  • Webhook
  • AI Agent
  • Chat Model
  • Edit Fields (Set)
  • Switch

Five inbound messages to feed your agent. Copy one into the chat below, or paste it straight into n8n.

  • Hello, I'd like a quote for 200 units of model X. What would it cost? Marco Rossi, marco.rossi@email.it

  • Your software won't start anymore after yesterday's update, it's urgent. Laura B., laura.bianchi@azienda.it

  • Hi, I'm attaching my CV, I'd be interested in roles in the production department. Giuseppe Verdi

  • CONGRATULATIONS you won a 500 euro voucher click here now!!!

  • Hi, I already wrote last week about the quote for the 200 units but got no reply. Following up. Marco Rossi

These are the same messages the chat tool sends. Switch IT / EN to copy either language.

0/5 done
Step A1

Receive a message

Goal

Build a workflow with a Webhook node that receives a message over POST and returns a simple response. Send a first test message to your webhook and check that the execution lands in n8n.

Done criteria

Get help
Node flow
WebhookPOST
Respond to Webhook200

The Webhook node is your workflow's front door. Add it as the trigger, set HTTP Method to POST, and give Path a name you recognize. n8n then shows two URLs: a Test URL and a Production URL.

While you build, click "Listen for test event". n8n registers the Test URL and waits about 120 seconds for one incoming call, so you can watch the data land right in the editor. The Production URL only works after you save and activate the workflow, and those runs show up under the Executions tab, not on the canvas.

To answer the caller, set the Webhook's "Respond" parameter: "Immediately" returns a default 200 at once, "When Last Node Finishes" waits for the whole workflow, and "Using 'Respond to Webhook' Node" lets you shape the reply with a dedicated node at the end.

Your message arrives nested under body, so you read it as {{ $json.body.message }}. Paste the Test URL into the chat tool above, click "Listen for test event", send a message, and the execution should appear.

Screenshots
Step A2

Classify the message

Goal

Add an AI Agent (or Chat Model) node that, given the message text, returns one category from: quote, support, application, spam.

Done criteria

Get help
Node flow
Webhook
AI Agent
Chat Model

Add an AI Agent node and connect a Chat Model sub-node to it (OpenAI, Mistral, Ollama, whatever you hold a credential for). Since n8n 1.82 the Agent always runs as a Tools Agent, so the Chat Model connection is required: it is the brain the agent thinks with.

The whole game is the system prompt. Tell the model to reply with ONLY one category from a closed list: quote, support, application, spam. No sentences, no explanation, no punctuation. The tighter you constrain the output, the more stable it stays across messages.

Feed it the incoming text with an expression. Webhook data is nested under body, so reference the message as {{ $json.body.message }}. Run an easy one first (the quote), then throw the ambiguous and the spam messages at it and check it stays consistent.

System prompt

You are a helpful assistant tasked with understanding the user's request category, only output the category picking from this list: quote, support, application, spam.

Screenshots
Step A3

Extract structured data

Goal

Have the agent, alongside the category, extract a JSON object with the fields: name, email (if present), and request subject.

Done criteria

Get help
Node flow
AI Agentstructured JSON
Output Parser

Now ask the agent for structured output, not just a label. The clean way is to turn on "Require Specific Output Format" on the AI Agent and attach a Structured Output Parser sub-node.

In the parser, pick a Schema Type. "Generate From JSON Example" is the beginner-friendly one: paste a sample object like { "category": "", "name": "", "email": "", "subject": "" } and n8n infers the schema, treating every field as required. "Define using JSON Schema" gives you full control when you want it.

The golden rule: every field is always present, even when empty. Test with message 4 (the spam), where there is no name and no email. A well-built parser returns those fields as empty strings instead of dropping them, and that predictable shape is what lets the next nodes trust the data.

System prompt

You are a helpful assistant that processes inbound messages. Classify the request and extract the sender's details. Always return every field, and when a value is missing return an empty string. Fields: category (one of quote, support, application, spam), name (the sender's full name), email (the sender's email address), subject (a short summary of the request).

JSON schema
{
  "category": "",
  "name": "",
  "email": "",
  "subject": ""
}
Screenshots
Step A4

Route to different actions

Goal

Add a Switch node that, based on the category, sends the message down different branches (at least three: quote, support, application). On each branch, for now, a single Set node that writes what that branch would do is enough.

Done criteria

Get help
Node flow
AI Agent
Switch
  • quote
  • support
  • application
  • spam

Add a Switch node after the agent and feed it the category field. In "Rules" mode you add one rule per output: category equals quote goes to the first output, support to the second, application to the third. Use "Rename Output" to label each branch, and turn on the "Fallback Output" to catch anything that matches nothing.

Think of each branch as a real action: a quote goes to sales, support opens a ticket, an application goes to people ops. You do not have to build those for real yet. One Edit Fields (Set) node per branch, writing a descriptive action field, is enough to prove the routing.

Send spam down its own branch that simply drops it. This is the moment your automation stops just reading and starts deciding.

Screenshots
Step A5Stretch

Connect the follow-ups

Goal

Message 5 in the dataset is a follow-up to message 1 (same sender, same request). Get the agent to recognize that it is a follow-up.

Done criteria

Get help
Node flow
AI Agentfollow_up flag

There is no persistent memory in this workflow, so the simple trick is to let the model spot the signal in the text itself. In the system prompt add a rule: if the message mentions a previous contact, a reminder, or a chase-up, set a follow_up field to true.

Message 5 is a follow-up to message 1, same sender, same 200-unit quote. A good prompt flags it from cues like "I already wrote last week" and "following up".

This is a deliberate taste of a limitation. Real agents that link conversations over time need actual memory or a database to look the sender up. For now you are recognizing the pattern from language alone, which is enough to feel where the ceiling is.

System prompt

You are a helpful assistant that processes inbound messages. Classify the request, extract the sender's details, and flag follow-ups. Always return every field; when a value is missing return an empty string. Fields: category (one of quote, support, application, spam), name (the sender's full name), email (the sender's email address), subject (a short summary of the request), follow_up (true if the message refers to a previous contact, a reminder, or a chase-up, otherwise false).

JSON schema
{
  "category": "",
  "name": "",
  "email": "",
  "subject": "",
  "follow_up": false
}

From the n8n docs