This N8N AI Agent Can Query ANY Database (No-Code BigQuery Example)

8.01k views1974 WordsCopy TextShare
Ahmed Mukhtar | AI Automations
📆Work with me: https://cal.com/ahmed-mukhtar/discovery-call 📚 Access Full Source Code in my Skool ...
Video Transcript:
imagine having an AI system that can query a million rows of data what would that mean for your business I have built an AI data analyst using na10 to connect to any SQL database and in this example we're pulling insights from the Google analytics sample data set in big query and the best part is that you can plug this into your own database whether it's for marketing Finance or operations and getting instant insights from your data using natural language let's jump in and see how it works so first I needed some data and after doing
some digging around I found the public data set Google's analytics data set sample in big query it has around a million rows of traffic data from Google merchandise stores so it's a real e-com store and the data is typical of what you would see for an e-commerce website it includes information about traffic Source data where the visitors originated from the content data and how the behavior of the users on the website this includes like the URLs of pages the visitors looked at how they interacted with the content Etc and it also has transactional data so
now that we have the data let's jump inside of na10 and see what we did right so here we have the main big query AI agent and you can see that connected to a web hook because I'm using a front end to chat and communicate with the agent and we'll see that in just a second so straight away you might have noticed that we're not using the SQL built-in agent inside of na10 we're actually using a TOS agent here and I'll explain why in just a second looking at the top level high overview of what's
Happening we have a natural language query coming in from the front end that goes into this main agent and this tools agent basically has an overview of the schema of the database so it has all the different table columns and the kind of information that holds because the data set has multiple different columns and a bunch of different tables here we're basically splitting the responsibilities so that this main agent is basically tasked with only understanding the user's intent analyzing the query and identifying the different filters the tables that we should focus on when creating the
SQL query so basically enriches the user's query then it passes it to our database tool and generates the equivalent SQL query and then the response comes back from the tool to our main agent here which converts into a more userfriendly format and then we do some more formatting of the respon here before we respond to the web hook and it goes back to the front end and by using this structure and splitting the responsibilities between two different agents we're basically able to conversate with the agent because sometimes we might not even need to pull in
any database or call the database query and another benefit is that we're able to use a very simple and fast llm and here I'm just using the GPT 40 Mini model so when it comes to the memory I've just used the postgress chat memory and we're keeping the context window to five so this is how many past interactions the models receives for context and then if we look at our database query tool this is very simple uh we're just basically saying call this tool to convert the natural language query into SQL and fet a response
from the database so if we look inside of our database querol this is what it looks like and we're basically simulating what was happening with the build-in SQL agent so this first agent generates the SQL query and I found out the entropic model works really well for this so this is what I'm using here and after that we're doing some query validation so we're checking for things like deleting of tables or modifying of the data making sure that the agent hasn't included any destructive commands in the SQL query and then we're executing a query inside
of big query so here we just have to connect with our big query account using ool and just look at the documentation it's very simple to set up we set operation to execute query and then we just pass it the SQL query from the previous node I've included some more formatting of the response and I've also included a Google Sheets node here and the purpose of this is to Output the logs of what's happening and it makes it very easy to track what's going on so here I've got the Tim stamp the user query and
then the generated SQL query just so that we can monitor the agent and make sure it's actually outputting the correct SQL queries and that's pretty much it for the database query so going back to the main agent let's actually see in action and ask a few questions right so here we have the agent on our left hand side inside of na10 and on the right I've got a very simple streamlit application just as a front end to be able to communicate with the agent so just to get started I'm going to ask it hey to
make sure that it's all working and connect it up this is in test mode that's why I have to click test workflow before executing um and as you can see it comes back very quickly asking how can I assist you today if you have any questions regarding Google analytics data or anything else feel free to ask so I'm going to start by doing some data exploration questions very simple ones just to understand the data set a little bit better and the first one being what are the earliest and latest data points in this data set
so I'm going to click test workflow run that and as you can see this time it actually went and called the database query tool which will convert this into a SQL query and then execute that against big query and it will come back with a response and respond to us these types of Agents do take a little bit longer to respond because they have to do a lot of reasoning and actual execution of the query itself takes a bit of time so this is why you would see that they take a little bit longer to
respond but here we have the earliest and latest data points of the data set which are correct so this sample goes from August 2016 to August 1st 2017 so I'm going to ask you one more question just to get the number of row and make sure that's around a million um I think it's just under so it's around like 900,000 so I'm just going to let that one run here and we can see the Google sheet here with the logs um we can see the enhanced queries these were a very simple question so we can
see the SQL query generated and the enhanced queries so we have the total number of rows in a data set to be 9,600 we Rand up to a million right um so next step I'm going to do some real questions so I'm going to start very simple and then work my way up and do some more complex questions so first we have this one here count the total number of sessions per month and to be honest this is not even like a simple one so it has to aggregate by month and count the total number
of sessions for each month so let's see what that one does right so it came back with the data here so it's nicely laid out in table format um we can see that it went from 2016 to 2017 and for each month it's given the total sessions for that month awesome so next I'm going to ask it something to do about the traffic so here we have find the top five operating systems that had the most traffic and I'm just going to do test and let that go right so let's see what it does awesome
so the top five operating systems that had the most traffics were windows with 350,000 visits Macintosh Android iOS and then Linux that sounds about right let's check the logs and see what it did so what I asked was find the top five operating systems that had the most traffic and then it enhanced it by saying retrieve the top five operating systems by visit count using the device. operating system and count the visits ordering by highest traffic right so this is awesome it created the esql query but that so we can see here is looking at
the table suffs because the data set is splin to multiple tables where each table is a specific day and we have to basically look at the entire data set here so it's looking from the first table to the last table then it's grouping by the operating system and then ordering by the visit count and limiting to only five to get the top five operating systems so yeah awesome it's doing what it's supposed to do so let's do something a bit more complex I'm going to ask it about the bounce rate per traffic source so test
workflow awesome so here we have the bounce rate per traffic Source summarized as follows so we have a table of the traffic Source direct YouTube Google partners and then Google analytics and then for each one it's got the total visitors the total bounce rate and then the bounce rate percentages this is awesome and you can start to see the power of this so this is a very complex query and and the data set we're using is huge with multiple tables different columns so we pretty much have 365 tables because each day is a separate table
and we aggregate in all of that information and be able to get insights from it from simple one sentences in natural language and we get something like this and if you want to get your hands on this system including a database query tool I'll will leave a link down below to my school community and I'm dropping all the resources inside of there so we managed to build a system that this powerful without writing a single line of code everything is in no code except for the front end but you don't actually need that um you're
able to just connect this to a chat interface inside of na10 to communicate and chat with the agent and you can take this further so we can automate charts from these tables we don't have to look at it in tabular format we can input it into charts like I shown in a previous video where I had the voice AI SQL agent so not only that we're able to communicate with it and ask it insights about our data we're able to visualize that data in an automated way so the possibilities are truly endless I'd like to
see what you guys think about this what should add to this setup to make it more robust and test it out even more definitely let me know in the comments down below and with that being said that will be the end of this video I hope you guys found some value in this make sure you hit that like And subscribe button thank you and I'll see you in the next one
Related Videos
How to Build an AI SQL Agent with n8n to Query Databases Effortlessly
7:04
How to Build an AI SQL Agent with n8n to Q...
Eric Tech
3,271 views
8 Insane AI Agent Use Cases in N8N! (automate anything)
40:53
8 Insane AI Agent Use Cases in N8N! (autom...
AI Foundations
69,896 views
How to Chat with a Database Using AI - No Coding Required
15:42
How to Chat with a Database Using AI - No ...
Liam Ottley
36,269 views
LangGraph - SQL Agent - Let an LLM interact with your SQL Database
20:22
LangGraph - SQL Agent - Let an LLM interac...
Coding Crash Courses
12,413 views
Manus is out of control
44:33
Manus is out of control
Wes Roth
225,668 views
How to Get Your Data Ready for AI Agents (Docs, PDFs, Websites)
25:00
How to Get Your Data Ready for AI Agents (...
Dave Ebbelaar
46,799 views
Using Agentic AI to create smarter solutions with multiple LLMs (step-by-step process)
13:47
Using Agentic AI to create smarter solutio...
Don Woodlock
42,181 views
CHEAT CODE: Building AI Agents (n8n)
30:22
CHEAT CODE: Building AI Agents (n8n)
Stephen G. Pope
19,713 views
Creating no-code AI AGENTS that run locally on your laptop | AnythingLLM
17:05
Creating no-code AI AGENTS that run locall...
Tim Carambat
37,660 views
Make vs n8n—The Wrong Choice Will Cost You
49:30
Make vs n8n—The Wrong Choice Will Cost You
Stephen G. Pope
51,619 views
Build an AI Agent That Actually Remembers You (n8n Tutorial)
17:30
Build an AI Agent That Actually Remembers ...
Leon van Zyl
26,352 views
n8n Tutorial: 37 Tips and Tricks (Beginner to Expert)
1:27:43
n8n Tutorial: 37 Tips and Tricks (Beginner...
Productive Dude
16,025 views
Master Autonomous AI Agents in Microsoft Copilot Studio - Easy to Build & Extremely Powerful
22:47
Master Autonomous AI Agents in Microsoft C...
Collaboration Simplified
65,889 views
This RAG AI Agent with n8n + Supabase is the Real Deal
16:27
This RAG AI Agent with n8n + Supabase is t...
Cole Medin
155,947 views
AI Voice-Powered CRM (10X Sales)
1:32:57
AI Voice-Powered CRM (10X Sales)
Stephen G. Pope
24,609 views
I Built OpenAi’s Personal AI Agent in 1 HOUR using No code
12:44
I Built OpenAi’s Personal AI Agent in 1 HO...
Ahmed Mukhtar | AI Automations
29,638 views
N8N Foundational Concepts (AI Agents, JSON, Logic)
2:04:52
N8N Foundational Concepts (AI Agents, JSON...
Nick Saraev
15,442 views
The Ultimate n8n AI Agent Workflow for Financial Data FREE (Don't use RAG for Sheets & CSV!)
9:24
The Ultimate n8n AI Agent Workflow for Fin...
Leonardo Grigorio | The AI Forge
6,215 views
16 Things I Wish I Knew About n8n Before I Started
30:56
16 Things I Wish I Knew About n8n Before I...
Jono Catliff
20,524 views
n8n AI Agent Tutorial | Building Multi Agent Workflows
1:05:05
n8n AI Agent Tutorial | Building Multi Age...
Leon van Zyl
18,489 views
Copyright © 2025. Made with ♥ in London by YTScribe.com