Make sure AI Agent Checks Supabase RAG before Answering

I’ve set up an agent that has access to my knowledge base via Supabase.

What I’ve found is that it will not check the knowledge database if the information can be accessed with general knowledge, even when there is more specific knowledge in Supabase.

How do I ensure the Agent will always search Supabase before returning an answer?

Here is the json I’m using:

{
“nodes”: [
{
“parameters”: {
“updates”: [
“message”
],
“additionalFields”: {}
},
“type”: “n8n-nodes-base.telegramTrigger”,
“typeVersion”: 1.2,
“position”: [
-1540,
-160
],
“id”: “c9f2d9b1-a53b-4ee5-b3fc-717c81d2b0ac”,
“name”: “Telegram Trigger”,
“webhookId”: “fdf2afe6-7af3-4ead-ab18-9e98cddeaa2d”,
“credentials”: {
“telegramApi”: {
“id”: “puR7DDs1uzKu8mEx”,
“name”: “Telegram account”
}
}
},
{
“parameters”: {
“model”: {
“__rl”: true,
“value”: “gpt-4o”,
“mode”: “list”,
“cachedResultName”: “gpt-4o”
},
“options”: {}
},
“type”: “@n8n/n8n-nodes-langchain.lmChatOpenAi”,
“typeVersion”: 1.2,
“position”: [
-1100,
60
],
“id”: “35497701-6e96-4d34-ba86-c08661edec7e”,
“name”: “OpenAI Chat Model”,
“credentials”: {
“openAiApi”: {
“id”: “DQ2g3lYveHVelyQH”,
“name”: “OpenAi account”
}
}
},
{
“parameters”: {
“promptType”: “define”,
“text”: “={{ $json.message.text }}”,
“options”: {}
},
“type”: “@n8n/n8n-nodes-langchain.agent”,
“typeVersion”: 1.9,
“position”: [
-888,
-160
],
“id”: “131042f8-030f-4d4f-beb9-e14b6ba2f210”,
“name”: “AI Agent”
},
{
“parameters”: {
“chatId”: “={{ $(‘Telegram Trigger’).item.json.message.chat.id }}”,
“text”: “={{ $json.output }}”,
“additionalFields”: {
“appendAttribution”: false,
“parse_mode”: “HTML”
}
},
“type”: “n8n-nodes-base.telegram”,
“typeVersion”: 1.2,
“position”: [
-124,
-160
],
“id”: “cfab799e-fadb-4ad7-b091-a7aa66a0596a”,
“name”: “Telegram”,
“webhookId”: “b730ab4f-317a-4b8b-a85e-e12aa46a7b1e”,
“credentials”: {
“telegramApi”: {
“id”: “puR7DDs1uzKu8mEx”,
“name”: “Telegram account”
}
}
},
{
“parameters”: {},
“type”: “@n8n/n8n-nodes-langchain.toolThink”,
“typeVersion”: 1,
“position”: [
-860,
60
],
“id”: “2a4f909a-5830-48c2-a733-09ed6db5d8fd”,
“name”: “Think”
},
{
“parameters”: {
“calendar”: {
“__rl”: true,
“value”: “[email protected]”,
“mode”: “list”,
“cachedResultName”: “[email protected]
},
“additionalFields”: {}
},
“type”: “n8n-nodes-base.googleCalendarTool”,
“typeVersion”: 1.3,
“position”: [
-740,
60
],
“id”: “600944ba-c439-47a5-9ebf-9eeeb2dad8ee”,
“name”: “Create”,
“credentials”: {
“googleCalendarOAuth2Api”: {
“id”: “ZGmxrhT9WhuigPVz”,
“name”: “Google Calendar account 2”
}
}
},
{
“parameters”: {
“operation”: “getAll”,
“calendar”: {
“__rl”: true,
“value”: “[email protected]”,
“mode”: “list”,
“cachedResultName”: “[email protected]
},
“options”: {}
},
“type”: “n8n-nodes-base.googleCalendarTool”,
“typeVersion”: 1.3,
“position”: [
-620,
60
],
“id”: “cd1cbcb2-02c5-4ae0-9083-704f427de7ae”,
“name”: “Review”,
“credentials”: {
“googleCalendarOAuth2Api”: {
“id”: “ZGmxrhT9WhuigPVz”,
“name”: “Google Calendar account 2”
}
}
},
{
“parameters”: {
“sessionIdType”: “customKey”,
“sessionKey”: “={{ $(‘Telegram Trigger’).item.json.message.chat.id }}”
},
“type”: “@n8n/n8n-nodes-langchain.memoryPostgresChat”,
“typeVersion”: 1.3,
“position”: [
-980,
60
],
“id”: “e55c2216-64bb-4501-8abb-9350fb934afd”,
“name”: “Postgres Chat Memory”,
“credentials”: {
“postgres”: {
“id”: “53lWYwT8vBIUiVT7”,
“name”: “Postgres account”
}
}
},
{
“parameters”: {
“mode”: “retrieve-as-tool”,
“toolName”: “KnowledgeDatatbase”,
“toolDescription”: “Use this to access proprietary knowledge about marketing, sales and business operations as well as information about my communication style.”,
“tableName”: {
“__rl”: true,
“value”: “documents”,
“mode”: “list”,
“cachedResultName”: “documents”
},
“options”: {}
},
“type”: “@n8n/n8n-nodes-langchain.vectorStoreSupabase”,
“typeVersion”: 1.1,
“position”: [
-500,
62.5
],
“id”: “4f472d00-9152-479e-a0a0-d5f9acaad8ff”,
“name”: “Supabase Vector Store”,
“credentials”: {
“supabaseApi”: {
“id”: “PDCr4QjjrXVlTPmd”,
“name”: “Supabase account 2”
}
}
},
{
“parameters”: {
“options”: {}
},
“type”: “@n8n/n8n-nodes-langchain.embeddingsOpenAi”,
“typeVersion”: 1.2,
“position”: [
-412,
260
],
“id”: “df5b95ad-2274-404f-ae75-5d8116d4bc02”,
“name”: “Embeddings OpenAI1”,
“credentials”: {
“openAiApi”: {
“id”: “DQ2g3lYveHVelyQH”,
“name”: “OpenAi account”
}
}
}
],
“connections”: {
“Telegram Trigger”: {
“main”: [
[
{
“node”: “AI Agent”,
“type”: “main”,
“index”: 0
}
]
]
},
“OpenAI Chat Model”: {
“ai_languageModel”: [
[
{
“node”: “AI Agent”,
“type”: “ai_languageModel”,
“index”: 0
}
]
]
},
“AI Agent”: {
“main”: [
[
{
“node”: “Telegram”,
“type”: “main”,
“index”: 0
}
]
]
},
“Think”: {
“ai_tool”: [
[
{
“node”: “AI Agent”,
“type”: “ai_tool”,
“index”: 0
}
]
]
},
“Create”: {
“ai_tool”: [
[
{
“node”: “AI Agent”,
“type”: “ai_tool”,
“index”: 0
}
]
]
},
“Review”: {
“ai_tool”: [
[
{
“node”: “AI Agent”,
“type”: “ai_tool”,
“index”: 0
}
]
]
},
“Postgres Chat Memory”: {
“ai_memory”: [
[
{
“node”: “AI Agent”,
“type”: “ai_memory”,
“index”: 0
}
]
]
},
“Supabase Vector Store”: {
“ai_tool”: [
[
{
“node”: “AI Agent”,
“type”: “ai_tool”,
“index”: 0
}
]
]
},
“Embeddings OpenAI1”: {
“ai_embedding”: [
[
{
“node”: “Supabase Vector Store”,
“type”: “ai_embedding”,
“index”: 0
}
]
]
}
},
“pinData”: {},
“meta”: {
“templateCredsSetupCompleted”: true,
“instanceId”: “aa95d60ce93447a03a5861f524d89e9ad8567e4274d8648f5860f706cd4e4191”
}
}

Hi @Jason_Stapleton

Would you be able to paste that workflow in a code block so it will render in the message? Here’s a video on how to do that.

Best,

Robert Breen
pasteworkflow

JSON workflow is not valid? I am not able to paste it in my n8n ;(

You can try adding a system message by clicking Add Options, then have something like the below, this may help it to always use.

1 Like

When you click the button </> just hit paste straight away, it normally loads okay then

Yeah. The problem was related with the ". Now it works :wink:

1 Like

did you add system message in? how it go? some people go more into details too, with what the actuals tool do and when etc.

1 Like

Hi @King_Samuel_David.

Add a system message to tell the agent what to do.

Tell it to use your tools to get the information.

Robert

I’ve applied a detailed system message and it looks like it’s working. Thank you so much!

2 Likes

I applied a detailed system message and it looks like it’s working now. Thank you all for the quick feedback.

2 Likes

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