My AI agent is not going to the attached supabase tool to store the user information

Describe the problem/error/question

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

{
“nodes”: [
{
“parameters”: {
“promptType”: “define”,
“text”: "={{ $json.messages[0].text.body }} ",
“options”: {
“systemMessage”: “=\n\nYou are a specialized AI assistant. Your sole purpose is to function as a JSON API endpoint for a travel planning workflow. You will analyze user input and conversation history, and your ENTIRE response must be a single, raw, valid JSON object.\n\n**[CONTEXT PROVIDED TO YOU]\n\n* User’s Current Message: {{ $json.messages[0].text.body }}\n* User’s Chat ID: {{ $json.contacts[0].wa_id }}\n* Tools Available: save_user_info (Supabase tool), \n\n[OPERATING PROCEDURE]\n\nYour operational sequence is rigid and must be followed precisely.\n\n1. First-Time User Check (MANDATORY FIRST ACTION):\n * On the very first interaction with a new user (i.e., when the chat history is empty), you MUST use the save_user_info tool.\n * You must pass the User’s Chat ID ({{ $json.contacts[0].wa_id }}) to this tool to check for and register the user.\n * Do not proceed to conversational flow until this one-time action is complete.\n\n2. Conversational Flow (After User Check):\n * Adopt the persona of "TravelBot," a friendly and helpful travel assistant.\n * Your goal is to organically collect the key details for a trip plan: destination, duration, travel_dates, num_travelers, budget, and interests.\n * Engage in natural conversation, using the chat memory to understand context. Answer user questions and provide suggestions.\n * If the user wants to start a new trip, you must ask for confirmation before clearing the old details.\n\n3. Finalization:\n * Once all details are collected, present a summary to the user for confirmation.\n * After they confirm, proceed to the final output format (Case 2).\n\n[OUTPUT REQUIREMENTS & FORMAT]**\n\nTHIS IS THE MOST IMPORTANT RULE. Your entire output MUST be a single, raw, valid JSON object. Do NOT include any text, explanation, or markdown formatting like ```json before or after the JSON object.\n\n* Case 1: Information is still MISSING or conversation is ongoing\n * Your JSON output must follow this exact structure:\n json\n {\n \"is_complete\": false,\n \"ai_response\": \"Your polite conversational text or question goes here.\"\n }\n \n\n* Case 2: ALL trip details are collected and confirmed (FINAL ACTION)\n * This is the final output for a single trip plan.\n json\n {\n \"is_complete\": true,\n \"ai_response\": \"Great! I have all the details. I'm now forwarding your request to one of our travel experts, who will get in touch with you shortly. Thank you for using TravelBot!\",\n \"summary\": {\n \"destination\": \"Collected Destination\",\n \"duration\": \"Collected Duration\",\n \"travel_dates\": \"Collected Dates\",\n \"num_travelers\": \"Collected Traveler Count\",\n \"budget\": \"Collected Budget\",\n \"interests\": \"Collected Interests\"\n }\n }\n \n”
}
},
“type”: “@n8n/n8n-nodes-langchain.agent”,
“typeVersion”: 2.1,
“position”: [
272,
320
],
“id”: “9aa43a88-1a23-4a9b-aafb-5973d72b6d31”,
“name”: “AI Agent”
},
{
“parameters”: {
“options”: {}
},
“type”: “@n8n/n8n-nodes-langchain.lmChatGoogleGemini”,
“typeVersion”: 1,
“position”: [
224,
560
],
“id”: “710b5317-8de0-463d-a084-e5287871775d”,
“name”: “Google Gemini Chat Model”,
“credentials”: {
“googlePalmApi”: {
“id”: “FkJ5JZyd2kZVgXGh”,
“name”: “Google Gemini(PaLM) Api account”
}
}
},
{
“parameters”: {
“sessionIdType”: “customKey”,
“sessionKey”: “= {{ $json.contacts[0].wa_id }}”,
“contextWindowLength”: 30
},
“type”: “@n8n/n8n-nodes-langchain.memoryPostgresChat”,
“typeVersion”: 1.3,
“position”: [
400,
608
],
“id”: “279a6318-d6d7-43d2-831b-264efdf5e094”,
“name”: “Postgres Chat Memory”,
“credentials”: {
“postgres”: {
“id”: “0AfV3d0CavbIvqNW”,
“name”: “Postgres account”
}
}
},
{
“parameters”: {
“tableId”: “users”,
“fieldsUi”: {
“fieldValues”: [
{
“fieldId”: “username”,
“fieldValue”: "={{ $json.contacts[0].profile.name }} "
},
{
“fieldId”: “user_id”,
“fieldValue”: “={{ $json.contacts[0].wa_id }}”
}
]
}
},
“type”: “n8n-nodes-base.supabaseTool”,
“typeVersion”: 1,
“position”: [
608,
624
],
“id”: “b27f2a15-ab07-4df7-817b-ec319a86e9dd”,
“name”: “save_user_info”,
“credentials”: {
“supabaseApi”: {
“id”: “Zi0KdRCvZWifcYGr”,
“name”: “Supabase account 2”
}
}
},
{
“parameters”: {
“conditions”: {
“options”: {
“caseSensitive”: true,
“leftValue”: “”,
“typeValidation”: “strict”,
“version”: 2
},
“conditions”: [
{
“id”: “38b5e629-4e74-4eda-ba32-10c6388f7ff5”,
“leftValue”: “={{ $json.is_complete }}”,
“rightValue”: “”,
“operator”: {
“type”: “boolean”,
“operation”: “true”,
“singleValue”: true
}
}
],
“combinator”: “and”
},
“options”: {}
},
“type”: “n8n-nodes-base.if”,
“typeVersion”: 2.2,
“position”: [
912,
336
],
“id”: “1a1825ba-06a7-497c-80a1-411573e6c3d1”,
“name”: “If”
},
{
“parameters”: {
“jsCode”: “// Get the raw text output from the AI node\nconst rawOutput = $input.first().json.output;\n\n// This function will find and parse the first valid JSON object in the string,\n// even if it’s surrounded by conversational text or markdown.\nlet jsonString = null;\n\n// 1. First, try to find a JSON block enclosed in json ... \nconst jsonBlockMatch = rawOutput.match(/json\\s*([\\s\\S]*?)\\s*/);\nif (jsonBlockMatch && jsonBlockMatch[1]) {\n jsonString = jsonBlockMatch[1];\n} else {\n // 2. If no markdown block, find the content between the first ‘{’ and the last ‘}’\n const firstBrace = rawOutput.indexOf(‘{’);\n const lastBrace = rawOutput.lastIndexOf(‘}’);\n \n if (firstBrace !== -1 && lastBrace > firstBrace) {\n jsonString = rawOutput.substring(firstBrace, lastBrace + 1);\n }\n}\n\n// 3. If we couldn’t find a potential JSON string, throw a clear error.\nif (!jsonString) {\n throw new Error("Could not find a parsable JSON object in the AI output. The output was: " + rawOutput);\n}\n\n// 4. PRE-PROCESSING STEP: Before parsing, fix common AI mistakes.\n// - Replace unescaped newlines with escaped newlines (\\n).\n// - This makes the JSON string valid even if the AI forgets to escape line breaks.\nconst cleanedJsonString = jsonString.replace(/\n/g, ‘\\n’).replace(/\r/g, ‘\\r’);\n\n\n// 5. Now, try to parse the cleaned string.\ntry {\n const parsedOutput = JSON.parse(cleanedJsonString);\n return parsedOutput;\n} catch (error) {\n // This error triggers if the extracted text is still not valid JSON.\n console.error("Failed to parse the extracted JSON string. The cleaned string was:", cleanedJsonString);\n throw new Error("Found a potential JSON object, but it was not valid. Please check the AI’s output format.");\n}\n”
},
“type”: “n8n-nodes-base.code”,
“typeVersion”: 2,
“position”: [
688,
336
],
“id”: “fe1c0f5f-dbf6-41ff-be98-c9cdf772fe82”,
“name”: “Code”
},
{
“parameters”: {
“tableId”: “requests”,
“fieldsUi”: {
“fieldValues”: [
{
“fieldId”: “user_id”,
“fieldValue”: “={{ $(‘WhatsApp Trigger’).item.json.contacts[0].wa_id }}”
},
{
“fieldId”: “summary”,
“fieldValue”: “={{ $json.summary }}”
},
{
“fieldId”: “status”,
“fieldValue”: “open”
}
]
}
},
“type”: “n8n-nodes-base.supabase”,
“typeVersion”: 1,
“position”: [
1136,
240
],
“id”: “8d02f5f3-5e54-4317-8722-2eb25ef89cd2”,
“name”: “Create a row”,
“credentials”: {
“supabaseApi”: {
“id”: “Zi0KdRCvZWifcYGr”,
“name”: “Supabase account 2”
}
}
},
{
“parameters”: {
“chatId”: “=-4895185051”,
“text”: “=New Travel Request! ID:{{ $(‘Create a row’).item.json.request_id }} Details:{{ $(‘Create a row’).item.json.summary }} Click below to accept this request.”,
“replyMarkup”: “inlineKeyboard”,
“inlineKeyboard”: {
“rows”: [
{
“row”: {
“buttons”: [
{
“text”: “Accept Request”,
“additionalFields”: {
“callback_data”: “=accept_{{ $(‘Create a row’).item.json.request_id }}”
}
}
]
}
}
]
},
“additionalFields”: {}
},
“type”: “n8n-nodes-base.telegram”,
“typeVersion”: 1.2,
“position”: [
1792,
240
],
“id”: “9d938579-9c27-4cdc-a3c8-cdf189f511bb”,
“name”: “Send a text message2”,
“webhookId”: “bd2d2a6e-8561-4d22-a133-d2bd86c64be9”,
“credentials”: {
“telegramApi”: {
“id”: “Z0fH3xPSNS8Y79hd”,
“name”: “Telegram account”
}
}
},
{
“parameters”: {
“inputSource”: “passthrough”
},
“type”: “n8n-nodes-base.executeWorkflowTrigger”,
“typeVersion”: 1.1,
“position”: [
0,
0
],
“id”: “e10500ff-6f4b-418b-8fe3-b26f4ed47009”,
“name”: “When Executed by Another Workflow”,
“disabled”: true
},
{
“parameters”: {
“updates”: [
“messages”
],
“options”: {}
},
“type”: “n8n-nodes-base.whatsAppTrigger”,
“typeVersion”: 1,
“position”: [
0,
336
],
“id”: “9d8c48b1-d779-4ee6-87df-c0d98328244c”,
“name”: “WhatsApp Trigger”,
“webhookId”: “b0d61b79-7285-4e99-9b54-6ac15d7292c1”,
“credentials”: {
“whatsAppTriggerApi”: {
“id”: “xQhYMjOKhYamhuJX”,
“name”: “WhatsApp OAuth account”
}
}
},
{
“parameters”: {
“operation”: “send”,
“phoneNumberId”: “712578715277813”,
“recipientPhoneNumber”: “=918917584910”,
“textBody”: “={{ $json.ai_response }}”,
“additionalFields”: {}
},
“type”: “n8n-nodes-base.whatsApp”,
“typeVersion”: 1,
“position”: [
1184,
464
],
“id”: “bc20736f-32d7-4689-bc77-9de173299c76”,
“name”: “Send message”,
“webhookId”: “75bebf64-8a46-45db-9c9a-c0fc50a61e65”,
“credentials”: {
“whatsAppApi”: {
“id”: “oTwCrBVY6Q70tR7b”,
“name”: “WhatsApp account”
}
}
},
{
“parameters”: {
“operation”: “send”,
“phoneNumberId”: “712578715277813”,
“recipientPhoneNumber”: “={{ $(‘WhatsApp Trigger’).item.json.contacts[0].wa_id }}”,
“textBody”: "=So from our conversation , I am able to generate this summary{{ $json.summary }},I hwill notify the guides and You can ask keep asking me more if you have any more requirements ",
“additionalFields”: {}
},
“type”: “n8n-nodes-base.whatsApp”,
“typeVersion”: 1,
“position”: [
1344,
240
],
“id”: “dddda81a-f9cc-4b80-a3a9-7ad4bde22ba0”,
“name”: “Send message1”,
“webhookId”: “908cd09d-9e58-4d6e-836e-cd5a32f2d6bf”,
“credentials”: {
“whatsAppApi”: {
“id”: “oTwCrBVY6Q70tR7b”,
“name”: “WhatsApp account”
}
}
}
],
“connections”: {
“AI Agent”: {
“main”: [
[
{
“node”: “Code”,
“type”: “main”,
“index”: 0
}
]
]
},
“Google Gemini Chat Model”: {
“ai_languageModel”: [
[
{
“node”: “AI Agent”,
“type”: “ai_languageModel”,
“index”: 0
}
]
]
},
“Postgres Chat Memory”: {
“ai_memory”: [
[
{
“node”: “AI Agent”,
“type”: “ai_memory”,
“index”: 0
}
]
]
},
“save_user_info”: {
“ai_tool”: [
[
{
“node”: “AI Agent”,
“type”: “ai_tool”,
“index”: 0
}
]
]
},
“If”: {
“main”: [
[
{
“node”: “Create a row”,
“type”: “main”,
“index”: 0
}
],
[
{
“node”: “Send message”,
“type”: “main”,
“index”: 0
}
]
]
},
“Code”: {
“main”: [
[
{
“node”: “If”,
“type”: “main”,
“index”: 0
}
]
]
},
“Create a row”: {
“main”: [
[
{
“node”: “Send message1”,
“type”: “main”,
“index”: 0
}
]
]
},
“WhatsApp Trigger”: {
“main”: [
[
{
“node”: “AI Agent”,
“type”: “main”,
“index”: 0
}
]
]
}
},
“pinData”: {},
“meta”: {
“templateCredsSetupCompleted”: true,
“instanceId”: “47e05a7ffc7c9abfbe8f89ce76c1888c70b47bd88f9f5e6ca88304e1499a59c9”
}
}

Share the output returned by the last node

Information on your n8n setup

  • n8n version: the latest one ig , i am using the cloud one ,
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

can anyone tell me how can i share my workflow and be more precise

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.