You can build an n8n AI chatbot with four core pieces: Chat Trigger, AI Agent, a compatible chat model, and memory. Add tools only for actions the bot must perform, and keep side effects behind validation or human approval.
n8n's AI workflow guide explains the platform concepts behind the Agent, memory, tools, and human fallback used here. For the more general agent architecture, see the n8n AI Agent build guide; this page stays focused on a user-facing chatbot.
This guide uses LinkModel as an example OpenAI-compatible provider. Its current documentation lists https://api.linkmodel.ai/v1 as the API root and bearer-authenticated POST /chat/completions for compatible chat requests. The n8n editor and credential fields vary by version, so verify your instance's supported model connection before wiring the bot.
Use n8n workflow templates for AI media when the chatbot needs to launch image or video workflows. For a terminal-native media assistant, see LinkModel CLI.
The chatbot architecture
User → Chat Trigger → AI Agent → response
↑
Chat Model node
↑
Memory and safe toolsChat Trigger handles the conversation entry point. AI Agent decides whether to answer or use a tool. The chat model generates the answer and tool-call arguments. Memory lets the bot handle follow-up questions, but it must be bounded and must not be treated as an access-control system.
Step 1: Add Chat Trigger
Create a new workflow and add Chat Trigger. For an external frontend, use a Webhook instead and send a stable session_id with each message. Normalize the input before passing it to the Agent:
{
"message": "Can I change the delivery address for order 1842?",
"session_id": "customer-1842-session-7",
"customer_id": "customer-1842"
}The chatbot should receive the authenticated customer ID from your application, not infer it from the message. Keep the message and identity fields separate so a prompt cannot overwrite trusted context.
Step 2: Connect an OpenAI-compatible chat model
Add the OpenAI Chat Model node and attach it to the AI Agent's language-model input. Where the credential editor supports a custom base URL, use:
Base URL: https://api.linkmodel.ai/v1
API key: your LinkModel API key
Model: gpt-5.4-miniLinkModel's model reference currently lists gpt-5.4-mini and other chat models. Choose a model from the live catalog and verify tool-calling support for your exact use case. If your n8n version only sends to the default OpenAI host, use a supported compatible credential or an ordinary HTTP Request branch; a raw HTTP Request is not automatically a chat-model connection for the Agent.
Start with non-streaming output. Streaming can be added once you know how your client handles partial text and late errors.
Step 3: Write a chatbot system prompt
You are a concise customer-support chatbot.
- Answer from verified account or order data only.
- Use order_lookup before making claims about an order.
- Ask one clarifying question when an order ID is missing.
- Never issue a refund, change an address, or delete an account.
- Escalate those requests to a human with a short summary.
- If a tool fails, say the information could not be verified.The prompt sets conversational behavior; your tools enforce the security policy. Do not put private database rows in the system prompt. Retrieve only the record needed for the current question.
Step 4: Add bounded memory
Connect Simple Memory for a prototype and use a stable session ID. Set a context window so a long conversation does not grow without limit. For a production bot, define what is stored, how long it is retained, and how users can clear it.
Memory should not contain credentials, payment details, or irrelevant personal data. Each tool call must re-authorize the customer against the current request, even if the previous turn appeared legitimate.
Step 5: Add one tool
Start with a read-only order_lookup tool:
Name: order_lookup
Input: order_id
Purpose: return shipping and payment status for one authorized order
Side effects: noneTest normal, missing, malformed, and unauthorized IDs. The tool should return a clear structured error when it cannot verify a record. Do not return a fabricated status so the bot can “be helpful.”
Add an escalate_to_human tool only after the read-only flow works. It can create a review item with the conversation ID and summary, but it should not make a refund or account change automatically.
If the chatbot needs richer model selection or a different provider surface, compare the n8n Agent node tutorial and the Open WebUI API setup before adding a second integration layer.
Test the chatbot before launch
Create a test matrix:
| Test | Expected behavior |
|---|---|
| Known order lookup | Calls tool and cites returned status |
| Missing order ID | Asks for the ID |
| Unauthorized order | Refuses and logs an access denial |
| Refund request | Escalates to human |
| Tool timeout | Uses a safe fallback |
| Prompt injection | Ignores the instruction and follows policy |
| Long conversation | Retains relevant context only |
Measure answer accuracy, tool selection, unsafe-action refusal, latency, failure rate, and human acceptance. Keep the test inputs fixed when comparing model IDs.
Handle errors and cost
Configure timeouts and bounded retries on model and tool calls. A retry can duplicate a ticket or notification, so make downstream writes idempotent with a request ID. Add a rate limit to the public chat endpoint and a per-session or per-customer budget.
Track model ID, token usage when returned, tool calls, latency, and final outcome. Use a fast model for short routing decisions and reserve a higher-capability model for complex summaries. The correct choice is the one that lowers accepted-answer cost while meeting the support quality target.
Production security checklist
- Keep LinkModel and n8n credentials in managed secret storage.
- Restrict tool permissions by customer and operation.
- Redact sensitive prompt and tool fields from logs.
- Add a human approval step for irreversible actions.
- Set maximum agent steps and output length.
- Validate and escape data displayed back to the user.
- Add a kill switch and provider fallback message.
- Review n8n execution data retention for the deployment.
Troubleshooting
The chatbot answers but forgets context: check that the same session key reaches memory on every turn.
The model is not selectable: verify the custom base URL and model ID, then check whether the n8n node version supports the model connection.
The Agent cannot see a tool: connect it to the tool input, not the normal workflow output, and confirm the tool description and schema.
The bot invents order status: require a tool call and instruct it to say “unverified” when the tool returns no result.
The UI hangs: disable streaming, check timeouts, and return a bounded fallback response.
Next step
Launch with one read-only tool, bounded memory, and a human escalation path. Once the transcript and execution traces are stable, add business actions one at a time. Extend the workflow with n8n workflow templates for AI media only after the chat path has its own budget and approval controls; use LinkModel CLI for terminal-operated media tasks.
Sources: n8n AI workflow documentation, Open WebUI's compatible API guidance, LinkModel's first API call, and LinkModel's model reference.
