Now inviting automation leaders: publish your playbook as a skill, under your own name. Publish yours →
Automation Skills
All skills/n8n ai nodes official/CHAT_SURFACE_PATTERNS
Reference · n8n ai nodes official

CHAT_SURFACE_PATTERNS

Part of n8n ai nodes official. Install the skill and your agent reads this page when it needs the depth.

Chat surface patterns: shell + core + sub-agents

For external chat surfaces: Slack, Discord, Microsoft Teams, Telegram, embedded webhook chats. The pieces (memory, tools, sub-workflow as tool, structured output) are covered in their own refs. This file covers the multi-workflow composition that production chat agents grow into, plus chat-surface-specific gotchas the other refs don't.

The shell is the same whether the core is an AI Agent node sub-workflow or a first-class n8n Agent called with Message an Agent. For the second, see "Core as Message an Agent" below. If the first-class Agent's own channel (Slack, Telegram, Discord, Linear) covers the need, no shell is needed at all: see n8n-agents-official references/CHANNELS.md.

Anti-loop filtering is required regardless of complexity. Any chat-triggered workflow that posts a reply MUST filter out the bot's own user ID right after the trigger, or it triggers itself forever. That's the minimum bar for every bot, not a reason to split. Some triggers may have built in parameters for this.

Beyond that, a simple bot (one trigger → one agent → one reply, with the bot-user filter) lives fine in a single workflow. The shell + core + sub-agents split is for production robustness, not the default. It earns its keep once any of these is true:

If none of those apply, keep it in one workflow (with the bot-user filter still in place).

The shape:

   [chat-surface workflow]    ──►  [agent core workflow]   ──►  [sub-agent workflows]
   ("the shell")                   ("the brain")                ("specialists")

   - Trigger from the surface       - Stateless                  - One narrow domain each
   - Anti-loop filter               - chatInput + threadId       - chatInput only
   - Routing / event types          - Memory keyed on threadId   - Their own tools + model
   - Loading + error UX             - Tools, sub-agents
   - Render the reply

Examples in examples/slack-router.json, examples/agent-core.json, examples/notion-ideas-subagent.json.

The shell

Receives chat events, decides whether to respond, manages UX, calls the core, renders the reply. No reasoning, no LLM.

Anti-loop filter (load-bearing)

The bot's own messages re-trigger the workflow. Slack, Discord, Teams all emit events for posts the bot itself made. Without filtering, every reply triggers another run, then another, until rate limits or n8n concurrency stops it.

Prefer trigger-level filtering when the trigger supports it. Some triggers expose user-ID filtering in their options so the loop breaks before any downstream node fires. Semantics differ per surface, verify against the version you're on:

Slack trigger-level example:

const slackTrigger = trigger({
    type: 'n8n-nodes-base.slackTrigger',
    config: {
        parameters: {
            trigger: ['message'],
            channelId: { __rl: true, mode: 'list', value: '<CHANNEL_ID>' },
            options: {
                userIds: '={{ ["<BOT_USER_ID>"] }}',
            },
        },
    },
})

channelId (getChannels) and the exclusion options.userIds (getUsers) are lookup values: resolve real IDs via explore_node_resources instead of hardcoding the placeholders. RLC values in this skill's examples/*.json are instance-specific, re-resolve before reuse.

When the trigger filters at its own boundary, you don't need a separate filter node.

When the trigger doesn't expose a usable exclusion filter (currently Teams, plus Discord via community nodes that vary), the first node after the trigger must filter the bot's own user ID out:

const filterBot = node({
    type: 'n8n-nodes-base.filter',
    config: {
        parameters: {
            conditions: {
                conditions: [
                    {
                        leftValue: '={{ $json.user }}',
                        rightValue: '<BOT_USER_ID>',
                        operator: { type: 'string', operation: 'notEquals' },
                    },
                ],
            },
        },
    },
})

The bot user ID is the API ID from your bot's auth (Slack bot_user_id, Discord application ID, Teams botId).

Switch on event type and identity

The same trigger fires for messages, reactions, threads, mentions, slash commands, button clicks. One Switch right after the bot-loop filter routes each event to the right handler. The shell stays thin: it classifies the event and dispatches, and the actual work happens in dedicated sub-workflows per case.

Example for a Slack assistant (your shape will vary by what you support):

Switch case                              Goes to
──────────────────────────────────────────────────────────────────────────
"owner message"               ──►  Execute Workflow: agent-core
"owner reaction"              ──►  no-op (or Execute Workflow: reaction-handler)
"unknown user"                ──►  Send canned reply (or 4xx-shaped equivalent)
"slash command: /summary"     ──►  Execute Workflow: summary-command
"slash command: /search"      ──►  Execute Workflow: search-command
"button click"                ──►  Execute Workflow: interaction-handler

Each case has its own sub-workflow because the routing decision (what kind of event is this) and the work (run an agent, run a one-off tool, post a follow-up) are different concerns and often need different models, timeouts, or memory shapes. Adding a new slash command or button means adding one Switch output and one sub-workflow, not a new top-level workflow with its own trigger.

Slack-specific routing notes (payload shapes evolve on both Slack's side and n8n's, so verify field paths against a live event before relying on the exact shape):

Loading-state UX

Users assume nothing is happening if they don't see acknowledgement. Pattern: add a loading indicator before the agent call, remove it on every exit path, including error.

[Trigger] → [Filter bot] → [Switch]
   → (owner message)
   → [Add loading reaction]                        # :chatgpt:, :spinner:, etc.
   → [Execute Workflow: Agent core]
        onError: 'continueErrorOutput'
        ├── (success) → [Remove reaction] → [Send reply]
        └── (error)   → [Remove reaction] → [Send error message with link]

The error path is the easy one to forget. Without it, the loading indicator sits forever and the user thinks the bot is still working. onError: 'continueErrorOutput' on the Execute Workflow node enables the second branch (see n8n-error-handling-official references/NODE_ERROR_OUTPUTS.md).

For Slack: slack node with resource: 'reaction', operation: 'add' and 'remove'. For Discord/Telegram, typing indicators are time-bounded, so for long agents, you could, for instance, send a placeholder message and edit it instead.

Threading as session continuity

Use the surface's thread primitive as the memory sessionKey:

workflowInputs: {
    value: {
        chatInput: '={{ $("Filter bot").item.json.text }}',
        threadId: '={{ $("Filter bot").item.json.thread_ts || $("Filter bot").item.json.ts }}',
    },
}

thread_ts || ts is the canonical Slack idiom: replies in a thread carry thread_ts referencing the parent, and the parent itself only has ts. Falling back to ts means the parent message becomes the session key for the thread it starts. Each thread is a fresh conversation, and memory doesn't leak across unrelated threads.

User ID, channel ID, and workspace ID alone are wrong: they cross conversations.

When sending the reply, target the same thread by setting otherOptions.thread_ts.replyValues.thread_ts to the same thread_ts || ts. Without it, replies go to the channel root and the thread context is lost.

Error UX: surface, don't hang

The error branch sends a short message with a link to the failed execution:

There was a workflow error. https://<n8n-host>/workflow/<id>/executions/{{ $execution.id }}

$execution.id is the live execution ID at the time the error fires. Parameterize the host if you ship across environments.

The agent core

A sub-workflow with two declared inputs: chatInput (the user's message) and threadId (the surface's thread/session ID). Returns the agent's final output: string, structured object, or surface-specific envelope (Block Kit, adaptive card).

The only chat-specific wiring not covered in MEMORY.md is plumbing threadId straight to sessionKey:

sessionIdType: 'customKey',
sessionKey: '={{ $json.threadId }}',

threadId flows trigger → (any pass-through nodes) → memory. Don't put it behind fromAi (covered in SUBWORKFLOW_AS_TOOL.md).

Per-execution context (user identity, attached files) goes in a Set node before the agent and gets templated into the system prompt, pattern in SYSTEM_PROMPT.md "File handling injection" and "Template + variables." Don't add a Set node speculatively for context that isn't varying yet. Inline in systemMessage is fine until reuse is real.

For Slack Block Kit, Discord embeds, or Teams adaptive cards, pair the agent with outputParserStructured (see STRUCTURED_OUTPUT.md). The general guidance to default to schemaType: 'manual' with a real JSON Schema applies even more strongly here: Block Kit and adaptive cards lean heavily on oneOf union types across block kinds, plus enums for fields like style and per-block constraints, none of which jsonSchemaExample can express. Examples will produce confidently-wrong block trees that the surface rejects.

Core as Message an Agent

When the brain is a first-class n8n Agent, the core sub-workflow collapses into one Message an Agent node (n8n-nodes-base.messageAnAgent) in the shell. The shell, anti-loop filter, loading UX, and error UX above stay exactly the same.

const askAgent = node({
    type: 'n8n-nodes-base.messageAnAgent',
    version: 3.1,
    config: {
        name: 'Ask support agent',
        onError: 'continueErrorOutput',
        parameters: {
            agentId: { __rl: true, mode: 'id', value: '<AGENT_ID>' },
            message: '={{ $("Filter bot").item.json.text }}',
            advanced: {
                session: { session: {
                    sessionIdType: 'customKey',
                    sessionKey: '={{ "support-slack-" + ($("Filter bot").item.json.thread_ts || $("Filter bot").item.json.ts) }}',
                } },
            },
        },
    },
})

What changes versus an AI Agent node core:

Full node reference: n8n-agents-official references/MESSAGE_AN_AGENT.md.

Sub-agents (agent as a tool)

A sub-agent is its own workflow with its own Agent node, called from the router agent via toolWorkflow. Use it when:

The contract is stateless. The router sends the full request in chatInput, with no shared memory and no implicit context. Reinforce in both the tool description (router-side) AND the sub-agent's system prompt (callee-side):

IMPORTANT: This tool is stateless. Send all relevant context in a single message. If you need to create an entry, include ALL required fields upfront.

Without that, the router assumes implicit context and the sub-agent guesses.

For everything else about wiring sub-workflows as tools (the toolWorkflow node, fromAi mapping, plumbed-vs-agent-filled values, return shapes), see SUBWORKFLOW_AS_TOOL.md.

Fresh schema injection

When the domain schema can change at runtime (Notion DB property options evolve, Linear teams add labels), refetch on every sub-agent call instead of hardcoding it in the system prompt:

[Execute Workflow Trigger]
   ↓
[Notion: Get Database]                       # fetches the schema
   ↓
[Agent]                                       # system prompt template includes:
    ## Database Schema
    {{ $('Get a database').first().json.properties.toJsonString() }}

One extra API call per invocation, and in exchange the sub-agent never returns "that property doesn't exist" because the prompt is stale. Worth it for low-call-volume chat assistants. For high-volume hot paths, cache the schema in a Data Table with a TTL.

Worked example: a personal Slack assistant

Three workflows demonstrating the full pattern:

Workflow Role
Slack router The shell. Bot-loop filter, event-type switch, loading reaction, error UX with execution link.
Agent core Stateless agent. Memory keyed on threadId. Native tools (web search, deep research, calculator) plus two sub-agents. Block Kit output.
Notion ideas sub-agent Specialist for a Notion ideas DB. Fetches schema fresh per call. Cheaper model (Claude Haiku 4.6).

Cross-references

Anti-patterns

Anti-pattern What goes wrong Fix
No bot-user-ID filter at the top of the shell Bot's own messages re-trigger the workflow, infinite loop Prefer trigger-level filtering when available (Slack: options.userIds is an exclusion list, put the bot ID there). Otherwise filter on $json.user !== '<BOT_USER_ID>' as the first node after the trigger
Putting the bot's user ID in Telegram's userIds expecting exclusion semantics Telegram's userIds is an allowlist, not an exclusion list. Only the bot would fire the trigger, which means no human messages get through. Workflow looks "fixed" until you realize it's been silent for hours Telegram bots don't see their own messages by default, so anti-loop usually isn't needed. If you need to restrict who can talk to the bot, use userIds as the allowlist of permitted humans, not as a place for the bot's ID
Loading indicator added but only removed on the success path User sees the bot stuck "thinking" forever after any error onError: 'continueErrorOutput' on the agent call, remove the indicator on both branches
Using user ID, channel ID, or workspace ID as the session key Conversations cross threads inside the same channel Use the surface's thread primitive (Slack `thread_ts
Stuffing trigger + UX + agent + sub-agent tools into one workflow when the agent already has multi-surface, sub-agent, or reuse needs Can't reuse across surfaces, UX leaks into reasoning, harder to test in isolation Split into shell + core + sub-agents (but only once one of those needs is real, simple bots stay in one workflow)
Sub-agent that reads or writes shared memory Caller can't reason about behavior, not safely retryable Sub-agents are stateless, full context goes in chatInput
Hardcoding domain schema (Notion properties, Linear labels) in a sub-agent's system prompt Schema rots, sub-agent picks invalid options weeks later Re-fetch the schema at the start of the sub-agent and template it into the system prompt at runtime
Set-before-agent context injection for static text "in case I want to reuse it" Extra node, no actual reuse, more places to update Inline in systemMessage until reuse is real, use Set only for per-execution variability
Calling the agent core synchronously without an error UX Worker fails, user sees nothing, debug requires opening n8n Error branch surfaces a short message with a link to the failed execution
<!-- Modified by Automation Skills on 2026-11-24: relative links to files that were not copied now point to the original repository. -->

Publish your skill

Copy this prompt into Claude Code, Codex or any agent. It walks you through your first skill in about 20 minutes, with you as the author.

Click to copy.