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

MESSAGE_AN_AGENT

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

Message an Agent

n8n-nodes-base.messageAnAgent (v3.1) calls a first-class Agent from a workflow and returns its answer as an item. Use it when a fixed pipeline needs the Agent's judgment, or as the core of a chat shell on a platform without a native channel. Its tool variant, n8n-nodes-base.messageAnAgentTool, lets an AI Agent node delegate to a first-class Agent.

The pattern: the Agent decides, the workflow acts. Ask for a structured decision, then let ordinary nodes do the exact, deterministic work with expressions (the part Agent tools can't do, TOOLS.md).

const triage = node({
    type: 'n8n-nodes-base.messageAnAgent',
    version: 3.1,
    config: {
        name: 'Triage ticket',
        parameters: {
            agentId: { __rl: true, mode: 'id', value: '<AGENT_ID>' },
            message: '={{ "New ticket from " + $json.email + ":\\n" + $json.body }}',
            useStructuredOutput: true,
            schemaType: 'manual',
            outputSchema: '{"type":"object","properties":{"action":{"type":"string","enum":["refund","reply","escalate"]},"reply":{"type":"string"}},"required":["action"]}',
            advanced: {
                session: { session: { sessionIdType: 'customKey', sessionKey: '={{ "triage-" + $json.ticketId }}' } },
            },
        },
    },
})
// then: Switch on $json.structuredOutput.action, and the refund node reads $('Webhook').item.json.orderId directly

Parameters

Parameter Notes
agentId Resource locator; mode: 'id' with the Agent id, or list
message The user message. Anything the Agent needs from the event goes here (or via the fetch tools below)
useStructuredOutput + schemaType (fromJson with jsonSchemaExample, or manual with outputSchema) The validated object lands in structuredOutput. Prefer manual with a real schema, same reasons as the AI nodes' output parser
advanced.session.session.sessionIdType fromInput: sessionId from a directly connected Chat Trigger. customKey: your own sessionKey
advanced.invokeMode allItems (default): one call for all input items. perItem: one call per item
advanced.enableStreaming Default true
advanced.allowOtherNodesData Adds a fetch_workflow_context tool so the Agent can read other nodes' output in this execution

The Agent always gets fetch_input_data, which reads this node's input items (JMESPath query optional). Both fetch tools are the model's choice to call, so they're for context, not for exact values.

Output

Verified live:

{ "text": "...", "structuredOutput": null, "usage": { "promptTokens": 2626, "completionTokens": 13, "totalTokens": 2639 },
  "toolCalls": [ { "toolName": "...", "input": {}, "result": {} } ], "finishReason": "stop",
  "session": { "agentId": "...", "projectId": "...", "sessionId": "my-key", "threadId": "workflow:project-<projectId>:my-key" } }

session builds the trace link (SESSIONS_AND_DEBUGGING.md). The execution log in the UI also links to it.

Behavior to design around

All verified live unless marked.

<!-- TEMPORARY: the inline agent source (agent config embedded in the node) is set only by the node creator's agent picker and isn't exposed in the NDV. Revisit when it's documented or settable. -->

The node also has an inline mode where the Agent's config lives in the node itself: no draft or publish, no Sessions entry, and memory only when a session key is set. It's set from the node creator, not through MCP; build a saved Agent instead.

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.