Build a Multi-Tool AI Support Agent
Build an AI support agent in n8n that autonomously calls tools and sub-workflows.
Introduction
30 Second Summary
Great customer support agents juggle a lot at once. They pull up your account, calculate live pricing, and recite company policies from memory.
In this project, you will build a multi-tool AI agent inside n8n that does exactly that. Your agent autonomously decides which tool to call based on the customer's question, whether that means fetching real data from an API, calculating a discount, or retrieving a company policy from a separate workflow.
What You'll Build
You'll type a question into a chat window and watch your agent reason about which tool to use, call it, and come back with a real answer pulled from live data.
By the end of this project, you'll have:
- A multi-tool AI agent you can chat with naturally. Ask about a user's posts and it fetches real data from an API. Ask for a discount calculation and it routes to the calculator instead of guessing.
- A reusable sub-workflow the agent calls like a function to retrieve company policies, testable and versionable on its own.
- An escalation path that detects when the agent cannot resolve an issue and routes it for human review. A centralized error workflow catches and logs any node failure across your entire workflow.
- An optional Secret Mission to push your skills further.
Are there any prerequisites?
You'll need an n8n Cloud account (a 14-day free trial is available with no credit card required) and an OpenAI account with an API key and a small amount of credit. A few cents covers all the testing in this project.
Before We Start
Before we dive in, let's lock in what you're about to build and why it matters to you.
Set Up Your n8n Cloud Workspace and OpenAI Credentials
You've committed to what you're building and why. Now it's time to wire up the foundation your AI agent needs before it can do anything useful.
Every AI Agent node in n8n needs a chat model to reason with. That means your OpenAI credentials must be in place and verified before you can test a single message. In this step, you'll create the workflow, set up credentials, and place the two foundational nodes on the canvas.
In this step, get ready to:
- Create a new workflow in n8n Cloud and name it.
- Set up and verify your OpenAI credentials.
- Add a Chat Trigger and AI Agent node to the canvas with an OpenAI Chat Model connected.
Create a new workflow in n8n Cloud
Your n8n Cloud instance is the workspace where you build, test, and run automation workflows. The first thing you need is a blank workflow to hold all the nodes you'll add throughout this project.
- Open your n8n Cloud instance in your browser and sign in.
- On the Overview page, click Create Workflow in the Workflows list. A blank canvas opens.
- Click the workflow name at the top of the canvas (it defaults to something like "My workflow").
- Replace the name with AI Support Agent and click away to save it.
You should see AI Support Agent displayed at the top of the canvas. The workflow auto-saves as you edit.
What is a workflow in n8n?
A workflow is a collection of nodes connected together to automate a process. You build workflows on the canvas by adding nodes (each one performs a specific action) and connecting them with wires that pass data between them.
Don't see Create Workflow?
You might see a welcome screen with a Start from Scratch button instead. Click that to create a new blank workflow.
help me find where to create a new workflow in n8n Cloud
Set up your OpenAI credentials
The AI Agent node uses OpenAI's language models to reason and respond. Before you can connect a model, n8n needs your OpenAI API key stored as a credential.
- In n8n, click Credentials in the left sidebar.
- Click Add Credential in the upper-right corner.
- Search for OpenAI and select it from the list.
- Open a new browser tab and go to https://platform.openai.com/api-keys.
- Copy your API key from OpenAI.
- Back in n8n, paste your API key into the API Key field.
- Click Save. n8n tests the connection automatically when you save.
You should see a success message confirming the connection test passed. This means n8n can authenticate with OpenAI's API using your key.
What are credentials in n8n?
Credentials are private pieces of information (like API keys) that let n8n connect to external services on your behalf. n8n stores them securely and injects them into nodes at runtime so your keys never appear in the workflow itself.
Connection test failed?
Double-check that you copied the full API key from OpenAI with no extra spaces. Make sure your OpenAI account has API credit available.
help me troubleshoot why my OpenAI credential connection test failed in n8n
Add the Chat Trigger and AI Agent nodes
With credentials verified, you can place the two core nodes on the canvas. The Chat Trigger is the entry point for all conversations. The AI Agent is the brain that processes each message.
- Click the AI Support Agent workflow name in the left sidebar (or the breadcrumb at the top) to return to the canvas.
- Click Add first step... on the canvas.
- Search for Chat Trigger and select it. n8n adds the node to the canvas and opens its settings.
- Leave all the default settings on the Chat Trigger. Close the node panel to return to the canvas.
What is the Chat Trigger?
The Chat Trigger node provides a built-in chat panel for testing your AI workflows. Every message a user sends through the chat runs the workflow, so your backend logic processes each message as it arrives.
- Click the + connector on the right side of the Chat Trigger node.
- Search for AI Agent and select it. n8n adds the AI Agent node and connects it to the Chat Trigger automatically.
- With the AI Agent node open, click the + Chat Model button at the bottom of the node panel.
- Select OpenAI Chat Model from the list. The OpenAI Chat Model sub-node opens.
- In the Credential to connect with dropdown, select the OpenAI credential you just created.
- In the Model dropdown, select gpt-4o-mini. This model offers the best balance of speed and cost for testing.
- Close the OpenAI Chat Model sub-node panel to return to the canvas.
Why gpt-4o-mini?
OpenAI recommends gpt-4o-mini for the fastest speed and lowest cost. It handles tool-calling and reasoning well for testing purposes. You can switch to gpt-4o later if you need higher quality responses.
Before you move on, take a moment to predict what you expect to see on your canvas right now.
You should see two nodes on the canvas: a Chat Trigger node on the left connected by a wire to an AI Agent node on the right. The AI Agent node should show a small OpenAI Chat Model sub-node attached below it.
Don't see the OpenAI Chat Model sub-node?
Open the AI Agent node and check that you clicked the + Chat Model connector at the bottom. If you added a regular OpenAI node to the canvas instead, delete it and try again from inside the AI Agent node panel.
help me connect an OpenAI Chat Model sub-node to my AI Agent node in n8n
Your workspace is wired up and ready. Next up, you'll give this agent a personality and test what it can do without any tools.
Build a Basic Chatbot and Hit Its Limitations
Your AI Agent is wired up to OpenAI and ready to talk. Now it is time to give it a personality and see what it can do on its own.
A chatbot that forgets what you just said and has no idea who it is supposed to be is not very useful. In this step, you will add conversational memory and a support agent persona. Then you will put the agent through its paces with some real questions.
In this step, get ready to:
- Add conversational memory so the agent remembers earlier messages.
- Set a system message that defines the agent's role as a support agent.
- Test the chatbot with real customer questions.
Add conversational memory to the AI Agent
Without memory, every message the agent receives is a blank slate. It has no idea what you asked ten seconds ago. The Simple Memory sub-node stores a sliding window of recent messages so the agent can follow a multi-turn conversation.
- Double-click the AI Agent node on the canvas to open it.
- At the bottom of the node panel, find the Memory connector and click the + button.
- Select Simple Memory from the list.
- In the Simple Memory settings, set Context Window Length to 5.
- Close the Simple Memory panel by clicking Back or clicking outside it.
What is Simple Memory?
Simple Memory keeps the last few messages in a sliding window. Setting the context window length to 5 means the agent remembers the 5 most recent exchanges (your messages and its replies). Older messages slide out of the window as new ones arrive.
This memory only lasts for the current session. When you start a new chat, the agent starts fresh.
Set the system message
A system prompt tells the agent who it is, what it should do, and how it should behave. Without one, the agent is a generic assistant with no domain knowledge or escalation rules.
- Double-click the AI Agent node to open it again.
- Scroll down past the node parameters and find the Node options section.
- Click Add Option and select System Message.
- Paste the following text into the System Message field:
You are a helpful customer support agent for TechCo. You help customers with account inquiries, pricing questions, and company policies. If you cannot resolve an issue (damaged item, payment dispute, address change), include the exact text [ESCALATE] in your response.
What does this system message do?
The first sentence sets the agent's identity: it works for TechCo. The second sentence defines what it handles: accounts, pricing, and policies.
The third sentence is the escalation rule. When the agent encounters a problem it cannot solve, it must include [ESCALATE] in its response. In a later step, you will wire an IF node that detects this flag and routes the conversation to a human.
- Save your workflow by pressing Cmd+S (macOS) or Ctrl+S (Windows).
✔️ Awesome, I've got everything!
Great. Double check that the workflow saved successfully before moving on.
ⓧ I'd like to double check my setup
Here is what your AI Agent node should have configured at this point:
- Chat Model: OpenAI Chat Model sub-node, using your verified OpenAI credential with gpt-4o-mini (or gpt-4o) selected.
- Memory: Simple Memory sub-node with Context Window Length set to 5.
- System Message (under Node options): the full TechCo support agent prompt including the [ESCALATE] instruction.
The system message should be:
You are a helpful customer support agent for TechCo. You help customers with account inquiries, pricing questions, and company policies. If you cannot resolve an issue (damaged item, payment dispute, address change), include the exact text [ESCALATE] in your response.
Test the chatbot with real questions
Your agent has a persona and memory, but no access to any external data or calculation tools. Time to see how it handles questions that need real information.
- Click Chat in the top-right corner of the n8n editor to open the built-in test chat panel.
Before you type anything, think about this: the agent has no database, no API connection, and no calculator. What do you think will happen when you ask it for specific customer data?
- Type the following message and press Enter:
What posts has user 3 written on our platform?
Read the response carefully. The agent answers confidently, but the data is completely made up. It has no connection to any real data source, so it fills the gap by inventing plausible-sounding post titles.
- Now try a math question. Type this message and press Enter:
What's 15% off $249.99?
The correct answer is $212.4915. The agent may get close, or it may be slightly off. LLMs predict tokens, not compute equations, so arithmetic is inherently unreliable.
Why did the agent make things up?
This behavior is called hallucination. The agent has no tools to look up real data, so it generates plausible-sounding answers from its training data. It does not know what it does not know.
The math problem exposes a second gap. Language models work with text patterns, not a calculator. They often get arithmetic close but not exact, especially with decimals.
These two gaps are exactly what you will fix in the next step by giving the agent real tools.
Chat panel not responding?
- Make sure the Chat Trigger node is connected to the AI Agent node with a visible wire on the canvas.
- Confirm your OpenAI credential is still valid. Go to Credentials, open your OpenAI credential, and click Test.
- If you see a timeout error, your OpenAI account may be out of credit. Check your balance at platform.openai.com.
Still stuck? Why is my n8n AI Agent chat not responding?
Your chatbot talks, but it makes things up and fumbles math. In the next step, you will give it real superpowers by connecting an HTTP Request tool for live data and a Calculator tool for reliable arithmetic.
Add the HTTP Request Tool and Calculator Tool
In the last step, you asked the agent real questions and saw its core limitation. It made up user post data that does not exist, and it stumbled on a straightforward percentage calculation. Without external data or reliable computation, even the best LLM is just guessing.
The fix is tools. In this step, you will give the agent two tools it can autonomously call: an HTTP Request Tool for fetching real data from an external API, and a Calculator Tool for precise arithmetic.
In this step, get ready to:
- Add an HTTP Request Tool that fetches user data from the JSONPlaceholder API.
- Add a Calculator Tool for reliable arithmetic.
- Test the agent and verify it autonomously selects the right tool for each question.
Add the HTTP Request Tool
The HTTP Request Tool lets the AI Agent make real HTTP calls to external services. You will configure it to fetch user post data from JSONPlaceholder, a free public REST API that returns realistic test data with no signup or API key required.
- On the AI Agent node, click the + button on the Tool connector at the bottom of the node.
- Select HTTP Request from the list of available tools.
- In the HTTP Request tool configuration panel, set Method to GET.
- In the URL field, paste this URL:
https://jsonplaceholder.typicode.com/users/{{ $fromAI('userId', 'The numeric user ID to look up', 'number') }}/posts
What is $fromAI()?
The $fromAI() function lets the AI Agent fill in values dynamically. Instead of hardcoding a user ID in the URL, $fromAI('userId', 'The numeric user ID to look up', 'number') tells the agent to figure out the right user ID from the conversation and insert it automatically.
This function only works inside tool sub-nodes connected to an AI Agent. It takes three arguments: a key name, a description that helps the agent understand the value, and a data type.
- Scroll down to the Tool Description field. This field appears because the node is connected as a tool sub-node.
- Paste this description:
Look up all posts written by a specific user. Use this when the customer asks about posts, articles, or content for a specific user ID.
Why does the Tool Description matter?
The Tool Description is how the AI Agent decides when to use this tool. The agent reads every connected tool's description and matches the user's question to the most relevant one.
A vague or missing description means the agent might ignore the tool entirely, even when the question is a perfect match.
Add the Calculator Tool
- On the AI Agent node, click the + button on the Tool connector again.
- Select Calculator from the list of available tools.
Why a separate Calculator Tool?
LLMs generate text, not math. When you ask "What is 15% off $249.99?", the model generates tokens that look like a number. Sometimes it gets it right, sometimes it does not. The Calculator Tool offloads arithmetic to an actual calculator, so every result is precise.
No additional configuration is needed for this tool. It works out of the box.
- Save your workflow by clicking the Save button in the top-right corner.
Test the agent with real tools
Your AI Agent now has two tools connected. Time to see whether it actually uses them.
- Return to the chat panel by clicking Chat in the top-right corner.
- If you see messages from the last step, click the refresh icon to start a New Session.
Before you send your first message, think about what should happen differently this time. The agent now has an HTTP Request Tool that can reach an external API. Do you think it will still make up data?
- Type this question and press Enter:
What posts has user 3 written?
This time, the agent calls the JSONPlaceholder API and returns real post titles for user 3. The titles come from the API response, not the agent's imagination.
Now predict what happens with a math question. Will the agent route to the Calculator Tool instead of guessing?
- Type this question and press Enter:
What's 15% off $249.99?
The agent routes to the Calculator Tool and returns the correct answer: $212.4915. Compare this to the last step, where the agent may have miscalculated.
How does the agent choose a tool?
The AI Agent reads your question, then reads the Tool Description of every connected tool. It picks the tool whose description best matches what the question is asking for. If no tool matches, it falls back to its own training data.
You can confirm which tool the agent used by clicking on the execution log in the canvas. Each node that ran during the conversation lights up with a green checkmark.
Agent not using the tools?
- Make sure the HTTP Request node is connected as a tool sub-node on the AI Agent (attached to the Tool connector), not as a separate standalone node on the canvas.
- Check that the Tool Description field is filled in on the HTTP Request tool. Without a description, the agent does not know when to use it.
- Start a New Session in the chat panel by clicking the refresh icon. Leftover conversation context from the last step can confuse the agent.
- Verify that the URL is pasted exactly as shown, including the {{ $fromAI(...) }} expression. A missing curly brace will break the dynamic parameter.
Still stuck? My n8n AI Agent is not calling the HTTP Request Tool when I ask about user posts.
Your agent can now fetch real data and calculate accurately. Next up, you will create a separate sub-workflow and teach the agent to call it as a tool for company policy lookups.
Create a Sub-Workflow Tool for Company Policies
Your agent can now fetch real data from an API and do reliable math. But what happens when a customer asks about your returns policy or shipping terms?
You could stuff all of that policy text into the system prompt, but that makes it bloated and hard to maintain. A better approach is a sub-workflow. It is a standalone workflow the agent calls like a function. It returns structured data, can be tested independently, and can be reused by other workflows.
In this step, get ready to:
- Build a separate "Policy Lookup" workflow that returns company policy data from a Code node.
- Connect the sub-workflow to your AI Agent as a third tool using the Call n8n Workflow Tool node.
- Test that the agent calls the sub-workflow and returns real policy text instead of hallucinated answers.
Create the Policy Lookup workflow
The Policy Lookup workflow is a self-contained unit that only does one thing: return company policy data. The AI Agent in your main workflow will call it whenever a customer asks about returns, warranties, or shipping.
- In n8n, click the n8n logo (or the back arrow) in the top-left corner to return to the main dashboard.
- Click Add workflow (or the + button) to create a new workflow.
- Click on the workflow name at the top of the canvas and rename it to Policy Lookup.
Now you need a trigger that fires when another workflow calls this one.
- Click the + button on the canvas to add a new node.
- Search for Execute Sub-workflow Trigger (it is also listed as When Executed by Another Workflow under trigger nodes).
- Select it to add it to your canvas.
- Leave the default settings as they are. This node acts as the entry point for your sub-workflow.
What is a sub-workflow?
A sub-workflow is a separate n8n workflow that another workflow can call. The calling workflow sends data to the sub-workflow's trigger node, the sub-workflow runs, and the last node's output gets returned to the caller.
This keeps your main workflow clean. It also means you can update policies in one place without touching the AI Agent at all.
Add the Code node with policy data
The Code node will hold your company's policy text and return it as structured data whenever the sub-workflow is triggered.
- Click the + connector on the right side of the Execute Sub-workflow Trigger node.
- Search for Code and select it to add a Code node.
- Make sure the language is set to JavaScript and the mode is Run Once for All Items.
- Replace the default code with the following JavaScript:
// Define company policy data
const policies = {
returnsPolicy: "Items may be returned within 30 days of purchase with original packaging. Refunds are processed within 5-7 business days after we receive the returned item. Digital products are non-refundable once downloaded.",
warrantyPolicy: "All hardware products come with a 1-year limited warranty covering manufacturing defects. Extended warranty plans are available for purchase within 30 days of the original order. Warranty does not cover accidental damage.",
shippingPolicy: "Standard shipping takes 5-7 business days. Express shipping (2-3 business days) is available for an additional fee. Free shipping on orders over $50. International shipping is available to select countries."
};
// Return policies in n8n's expected data format
return [{ json: policies }];
What does this code do?
The policies object holds three keys: returnsPolicy, warrantyPolicy, and shippingPolicy. Each contains the full text of a company policy.
The return [{ json: policies }] line wraps the data in n8n's expected format. All data passed between n8n nodes is an array of items, where each item has a json key containing the actual data.
- Click the Test step button at the bottom of the Code node to run it.
You should see the output panel display a JSON object with all three policy keys and their text values.
Seeing an error about return format?
Make sure you are returning an array with an object that has a json key. The format must be [{ json: { ... } }]. If you return the object directly without wrapping it, the Code node will report an error.
help me fix the return format in my n8n Code node
- Close the Code node panel.
- Save the workflow by pressing Cmd+S (macOS) or Ctrl+S (Windows).
Your Policy Lookup workflow is complete. It has two nodes: the Execute Sub-workflow Trigger connected to the Code node.
Connect the sub-workflow as a tool in your AI Agent
The Policy Lookup workflow exists, but your AI Agent does not know about it yet. You need to add a Call n8n Workflow Tool that points to it.
- Navigate back to your AI Support Agent workflow. Click the n8n logo in the top-left to return to the dashboard, then click AI Support Agent to open it.
- Click on the AI Agent node to open it.
- Click the + Tool connector at the bottom of the node.
- Search for and select Call n8n Workflow.
The Call n8n Workflow Tool node opens. You need to tell it which workflow to call and describe when the agent should use it.
- Under Source, make sure Database is selected.
- In the Workflow dropdown, select Policy Lookup (the workflow you just created).
- In the Description field, enter the following tool description exactly:
Retrieve company policies including returns, warranty, and shipping policies. Use this when the customer asks about policies, returns, refunds, warranties, or shipping.
Why does the tool description matter so much?
The tool description is the only information the AI Agent reads to decide whether to use this tool. A vague description means the agent will not know when to call it. A specific description listing the exact topics (returns, refunds, warranties, shipping) gives the agent clear signals for when to route a question here.
- Close the Call n8n Workflow Tool node panel.
- Save the workflow by pressing Cmd+S (macOS) or Ctrl+S (Windows).
Your AI Agent now has three tools: the HTTP Request Tool, the Calculator Tool, and the Call n8n Workflow Tool pointing at Policy Lookup.
Test the sub-workflow tool in action
Time to see if the agent actually calls the sub-workflow instead of making up policy information.
- Click Chat in the top-right corner to open the built-in test chat panel.
Before you type your question, think about what you expect to happen. Do you think the agent will call the Policy Lookup sub-workflow, or try to answer from its training data?
- Type the following into the chat:
What is your returns policy?
The agent calls the Policy Lookup sub-workflow and responds with the exact policy text: items may be returned within 30 days, refunds processed in 5-7 business days, and digital products are non-refundable.
- Now try asking about warranty terms by typing:
What does your warranty cover?
- Try one more question about shipping:
How long does shipping take?
Each time, the agent should respond with details that match the policy text you wrote in the Code node. The responses reference 30-day returns, 1-year warranty, and 5-7 business day shipping because they come from your sub-workflow, not from the model's training data.
Agent not calling the sub-workflow?
Check that you saved the Policy Lookup workflow before returning to the AI Support Agent workflow. The Call n8n Workflow Tool can only find saved workflows.
Also verify that the Description field on the Call n8n Workflow Tool mentions "policies", "returns", and "shipping". Without those keywords, the agent does not know this tool is relevant to policy questions.
help me troubleshoot why my n8n AI Agent is not calling the sub-workflow tool
Why a sub-workflow instead of hardcoding policies?
If you hardcoded policies into the system prompt, any policy change would mean editing the AI Agent node. With a sub-workflow, you update the Policy Lookup workflow once and every workflow that calls it gets the latest version.
In production, you could swap the Code node for a database lookup or an API call to a CMS. The AI Agent would not need to change at all.
Your agent now has three tools it chooses from autonomously: API lookups, a calculator, and a modular sub-workflow for company policies. Next up, you will add escalation logic so the agent can flag conversations it cannot resolve, and wire up a centralized error workflow that catches failures across the entire pipeline.
Add Escalation Logic and Error Handling
Your agent can now look up real data, calculate prices, and retrieve company policies. But what happens when a customer brings a problem the agent genuinely cannot solve, like a damaged item or a payment dispute?
Right now, those conversations end in a dead end. The agent tries its best, but there is no way to flag the issue for a human. On top of that, if any node in your workflow fails, the failure is completely silent. This step adds two safety nets: an escalation path that detects when the agent flags a conversation for human review, and a dedicated error workflow that catches node failures across your entire workflow.
In this step, get ready to:
- Add an IF node that detects the [ESCALATE] flag in the agent's response and routes to a separate branch.
- Create a dedicated Error Handler workflow that catches failures from the main workflow.
- Link the error workflow to the AI Support Agent workflow and verify both escalation and error handling work.
Add an IF node for escalation branching
In Step 2, you set the system prompt to include [ESCALATE] in its response when it cannot resolve an issue. The agent already knows to flag these conversations. Now you need the workflow to detect that flag and route it to a separate path.
- In your AI Support Agent workflow, click the + connector on the right side of the AI Agent node.
- Search for If and select it to add an IF node to the canvas.
- The IF node opens automatically. You need to set up a condition that checks whether the agent's response contains the [ESCALATE] flag.
- In the Conditions section, use the data type dropdown and select String > contains.
- In the left value field (Value 1), click the expression toggle (the small fx icon) and enter:
{{ $json.output }}
- In the right value field (Value 2), type:
[ESCALATE]
- Close the IF node to return to the canvas.
What does this IF node do?
The IF node reads the agent's response text from $json.output and checks if it contains the string [ESCALATE]. If it does, the data flows down the true branch. If not, it flows down the false branch, which is the normal response path.
Now you need to add a Code node on the true branch that packages the escalation details into a structured JSON object.
- On the canvas, click the + connector on the true output of the IF node.
- Search for Code and select it to add a Code node.
- In the Code node, make sure the Language is set to JavaScript.
- Replace the default code with the following:
// Extract the agent's original response
const agentResponse = $json.output;
// Return escalation details for downstream processing
return [{
json: {
status: "escalation_triggered",
message: "This conversation has been flagged for human review.",
agentResponse: agentResponse,
timestamp: new Date().toISOString()
}
}];
What does this code do?
This Code node captures the agent's full response from $json.output and wraps it in a structured object. The status field marks it as an escalation. The agentResponse field preserves the original reply so a human reviewer can see what the agent said.
In production, you would connect this Code node to a Slack message, email, or ticketing system to notify a human agent.
The false branch is the normal response path. The Chat Trigger handles responses automatically, so you do not need to add anything to the false output.
Before you run this, think about what will happen if you ask the agent about a damaged item. Do you think the IF node will route to the true branch or the false branch?
- Click Chat in the top-right corner to open the test chat panel.
- Type the following message:
I received a damaged item and want a refund for order #12345.
The agent responds with [ESCALATE] in its text, because the system prompt instructs it to escalate damaged item requests. The IF node routes the output down the true branch, and the Code node fires with the escalation JSON.
- Close the chat panel and click on the IF node on the canvas.
- In the OUTPUT panel, confirm that the data flowed through the true branch.
- Click on the Code node and confirm the output shows the escalation_triggered status and the original agent response.
IF node routing to the false branch instead?
If the agent's response goes to the false branch, it means the response text does not contain [ESCALATE]. Check that your system prompt includes the exact instruction to use [ESCALATE] for unresolvable issues. Also verify that the IF node's left value expression is set to {{ $json.output }} and the right value is [ESCALATE].
Help me debug why my IF node isn't detecting the [ESCALATE] flag in the agent's response.
Create the Error Handler workflow
Escalation handles cases where the agent knows it cannot help. But what about cases where a node in the workflow itself breaks? A misconfigured URL, a downed API, or a credential error could silently fail with no trace. An error workflow catches those failures automatically.
- Click the n8n logo in the top-left corner to return to the workflows list.
- Click the + New button to create a new workflow.
- Name the workflow Error Handler.
- Click Add first step... and search for Error Trigger. Select it to add it as the first node.
What is an Error Trigger?
The Error Trigger node starts a workflow whenever another linked workflow fails. It receives details about the failure, including which node errored and what the error message was. You do not need to publish the error workflow for it to work.
- Click the + connector on the Error Trigger node.
- Search for Code and add a Code node.
- Make sure the Language is set to JavaScript.
- Replace the default code with the following:
// Extract error details from the error trigger payload
const workflowName = $json.workflow.name;
const errorMessage = $json.execution.error.message;
const lastNode = $json.execution.lastNodeExecuted;
const executionUrl = $json.execution.url;
// Return structured error log for review
return [{
json: {
workflowName: workflowName,
errorMessage: errorMessage,
lastNodeExecuted: lastNode,
executionUrl: executionUrl,
loggedAt: new Date().toISOString()
}
}];
What does this code do?
The Error Trigger node receives a payload with details about the failure. This Code node extracts four key fields: the name of the workflow that failed, the error message, which node caused the error, and a URL to the failed execution for debugging.
In production, you would connect this to a Slack channel, email alert, or logging service so your team gets notified immediately when something breaks.
- Save the Error Handler workflow by pressing Cmd+S (macOS) or Ctrl+S (Windows).
Do I need to publish the Error Handler workflow?
No. Error workflows do not need to be published. They run automatically whenever a linked workflow errors during a production execution.
Link the error workflow and verify everything works
The Error Handler workflow exists, but it is not connected to anything yet. You need to tell the AI Support Agent workflow to use it as its error workflow.
- Navigate back to the AI Support Agent workflow from the workflows list.
- Click the three dots icon (Options) in the upper-right corner of the canvas.
- Select Settings.
- In the Error workflow dropdown, select Error Handler.
- Click Save to close the settings.
Now you will verify that the error workflow actually fires when something goes wrong. To do this, you will temporarily break one of the tools, publish the workflow so it runs automatically, and trigger an error.
Why do I need to publish the workflow?
Error workflows only fire on automatic (production) executions. The built-in test chat runs workflows manually, and manual executions do not trigger the Error Trigger. Publishing the workflow makes it run in production mode, which activates the error workflow link.
- Double-click the HTTP Request tool sub-node on the AI Agent to open it.
- Change the URL from the JSONPlaceholder URL to:
https://invalid-domain-test.example.com
- Close the node.
- Click the Publish button in the canvas header to publish the workflow.
- Click the Chat Trigger node on the canvas.
- At the top of the node panel, switch to the Production URL tab and copy the URL shown under Chat URL.
- Open this URL in a new browser tab. A chat widget appears.
- Type a message that would trigger the HTTP Request tool, such as:
What posts has user 3 written?
The workflow runs in production mode. The HTTP Request tool tries to reach the invalid domain and fails. This triggers the Error Handler workflow.
- Go back to your n8n tab.
- Navigate to the Error Handler workflow from the workflows list.
- Click the Executions tab at the top.
- You should see a recent execution. Click it to view the details.
- Confirm that the Code node output shows the workflowName, errorMessage, lastNodeExecuted, and executionUrl fields populated with the failure details.
Don't see an execution in the Error Handler?
Make sure you published the AI Support Agent workflow before sending the chat message. Error workflows only fire on production executions, not manual test runs. Also verify that you selected Error Handler in the main workflow's Settings > Error workflow dropdown and saved.
Help me figure out why my Error Handler workflow isn't firing when my AI Support Agent workflow fails.
Now fix the broken URL before moving on.
- Navigate back to the AI Support Agent workflow.
- Double-click the HTTP Request tool sub-node on the AI Agent.
- Change the URL back to:
https://jsonplaceholder.typicode.com/users/{{ $fromAI('userId', 'The numeric user ID to look up', 'number') }}/posts
- Close the node and click Publish again to update the production version with the restored URL.
Unpublish when you are done testing
Published workflows consume executions from your trial allowance with every chat message. If you are not actively testing, unpublish the workflow by clicking Options (three dots) > Unpublish to stop it from running automatically.
Secret mission
Add a Code Tool for Structured JSON Output
Your AI agent can talk, look up data, calculate, and fetch policies. But downstream systems do not speak conversational English. They need structured JSON. In this Secret Mission, you will add a custom Code Tool that the agent calls to format its responses as machine-readable JSON for system integrations.
Clean Up Your Resources
Clean Up Your Resources
This project uses n8n Cloud (14-day free trial, no credit card required) and the OpenAI API (a few cents for testing). Decide whether to keep your resources running, pause them to come back later, or delete them entirely.
Cost warning
Your n8n Cloud trial expires after 14 days. There is no free plan after the trial ends, so continued use requires a paid subscription starting at 20 EUR/mo.
OpenAI charges per API call, but the testing in this project costs only a few cents. If you are done experimenting, delete your workflows and revoke your API key to prevent future charges.
Resources you used:
- AI Support Agent workflow in n8n Cloud.
- Policy Lookup workflow in n8n Cloud.
- Error Handler workflow in n8n Cloud.
- OpenAI credential stored in n8n.
- OpenAI API key at platform.openai.com/api-keys.
Keep everything running
No action needed. Choose this if you are still experimenting with your AI agent or plan to extend it further.
- Your workflows remain in n8n Cloud and only consume executions when you manually test them in the chat panel.
- Your n8n Cloud trial continues to count down toward the 14-day limit.
- OpenAI charges only apply when the agent makes API calls during testing.
Pause - I'll come back to this later
Reduce the chance of accidental API usage while keeping your workflows intact.
- Your workflows only run when triggered manually through the chat panel, so there is no background execution to stop.
- To prevent accidental OpenAI charges, go to platform.openai.com/api-keys and delete the API key you created. You can create a new one when you return.
- Your n8n Cloud trial timer continues to count down. If it expires before you return, you will need a paid subscription to access your workflows.
Delete - I don't want to use this again
Remove all project resources and start fresh. Your n8n Cloud trial expires automatically after 14 days with no charge if you did not add a credit card.
- In n8n, open the Workflows page from the left sidebar. Delete each of the three workflows you created: AI Support Agent, Policy Lookup, and Error Handler.
- Open the Credentials page in n8n. Delete the OpenAI credential you created for this project.
- Go to platform.openai.com/api-keys in your browser. Delete the API key you created for this project.
Nice Work!
Nice Work!
Nice work! You just built a production-pattern AI agent in n8n that reasons about customer questions and autonomously decides which tool to call.
You've learned how to:
- Built a multi-tool AI agent that autonomously selects from HTTP Request, Calculator, and sub-workflow tools based on the user's question.
- Created a reusable sub-workflow that the agent calls like a function, keeping business logic modular and independently testable.
- Implemented escalation branching with an IF node and a centralized error workflow using the Error Trigger node to catch failures across your main workflow.
- Completed an optional Secret Mission to push your skills even further.
Ready to quiz yourself?