SQL is Dead, Long Live SQL: Engineering reliable analytics agent from scratch
Reliable analytics agents can be engineered by combining an in-process analytical database with a structured agentic loop and semantic context. Using DuckDB as the core engine allows agents to execute SQL queries locally in memory, providing the fast feedback loops necessary for Large Language Models (LLMs) to iterate on query generation without the latency of client-server architectures.
The basic approach involves a "while" loop where an LLM generates a SQL statement, executes it via a Python tool, and analyzes the result. To move beyond simple query generation and handle real-world data ambiguity, semantic context is integrated through two primary methods: skill files (Markdown documents containing business logic and KPI definitions used as system prompts) and database comments (metadata attached directly to table columns). These additions reduce the number of tool calls required for a correct answer and enable smaller, more efficient models to perform as well as larger ones.
For deterministic results on critical metrics, the architecture incorporates specific tools using Pydantic AI. While the agent remains flexible for exploratory questions, deterministic tools ensure that complex KPIs are calculated using a fixed, verified logic. To scale and distribute these capabilities, the Model Context Protocol (MCP) is used to decouple the agent's logic from the tool implementation. By hosting tools on an MCP server, agents can dynamically discover and utilize a standardized set of functions, allowing for a clean separation of concerns between the agent's identity and the organization's analytical tools.
This description was generated by Open-Source AI using the transcript of the session and the original submission contents.
This session took place in track Data Handling & Data Engineering and was classified suitable for intermediate domain / novice python by the speaker.
Submission
The proposal as submitted by the speaker before the conference.
This session is a "reality check" for AI analytics. We combine theory with engineering to answer one question: Where are the limits of Text-to-SQL? Participants will experience the frustration of a hallucinating LLMs and the satisfaction of fixing it with a realistic minimalist local setup.
Learning objectives:
- Map the limits: Identify exactly where LLMs break (e.g., complex joins, specific business logic, non-standard schemas).
- Bridge the gap: Learn how a semantic layer translates fuzzy English into deterministic SQL.
- Modern architecture: Overview and hands-on on DuckDB Model Context Protocol (MCP) to give agents standard, safe tools to do analytics.
- The verdict: Understand why SQL is becoming the "Assembly Language" of the AI era, and why you still need to be fluent in it and what is still missing to just "chat with our data".
Prerequisites:
- Laptop with Python 3.10+.
- Beginner SQL knowledge (joins, aggregations).
- No prior AI/LLM experience required.
Transcript (auto)
Auto-generated from the recording utilizing Open-Source AI. Speaker labels (Speaker 1, Speaker 2) reflect diarization, not identity. Timestamps refer to the recording.
Speaker 1 [00:06]
mess we we don't bite and we have actually a nice seekers and nice swag after so Thank you. All right. Welcome, everybody. I'm going to start because we have a lot of things to cover. I think there was a bit of a rush with the keynotes, but I hope you all have a lot of energy. I'm super happy to be back here and also with Tom Key. we're gonna talk and build stuff entering physically analytics agent from scratch understanding how they work and the idea basically is really about you doing okay we're gonna show you how things works but for each exercise there is a little timer and this is where you get your hands you know in it that's the best way to learn right so please turn off your slide your Microsoft teams don't get distracted by work, you're here to learn. It's the best way by doing and not just listening. So we have roughly an hour 30 and the agenda is pretty packed. So I'm Mehdi, also known online as Mehdio. Been doing data engineering for more than a decade now. Started on premise big data cluster and then on the cloud work at tech company and now work as dev rel for i'm just curious raise your hands if anyone have seen my face online oh okay i'm sorry for that you're still stuck with me and i'm joined today with ducky which is also working with me at
Speaker 2 [02:46]
Hi, my name is Dunkey, I am a
Speaker 1 [02:48]
formerly a
Speaker 2 [02:52]
working on data platforms for less than 10 years setting up data warehouses and yes struggling a lot with the issue that we'll talk about today right how do you get the right metric the right TPI the right number at the right time and now I'm working at mother dark as a dev rel as well mostly on our
Speaker 1 [03:21]
is that things have been pretty crazy these past months. I did a talk actually at Pydata in Berlin in September and another in November, and it feels like a decade in terms of progress for LLMs. All that to say is that when you put a CFP out there and it's being accepted, there is quite like four or five months delay. The landscape of where we are four or five months ago is crazy, you're gonna see it, and I've seen that many times at conference, people actually submit talk and they say, well, actually, no, it works. Like the language model gets significantly better and of past last year and also the workflows in general. But we're going to try to go ahead and try to break it. But if it's too good, it's just because it has been really getting good this past month. And that's really just overall the same. So that's the agenda. So we're going to talk about DougDB first. That's the tool we're going to use in Python. I'm going to go over the setup. Who has been using already DougDB? Raise your hands. All right. Who has heard about DougDB? Raise your hands. Yeah. Okay. Two more. So this is what you'll need. Basically, Python, UV, and OpenCode that you can install here. You have the slides here and the slides are at motherduck.com back on the 2026. So you can go head over this link and then you have the slides with all the links directly. Okay, so it's motherduck.com back on the 2026. I'll let the site. You have also the QR code here if you want to join. If you're joining remotely, I'm not forgetting about you. So to set up your keys, you're going to need a keys you can bring your own keys if you have already you know anthropic or open ai keys and you have basically two variables to fill the operator return api key and the open router model if you don't know about open router it's basically a service that enable to route any model you want to use okay the good news is that we have for you a meter i'm not sure where is it it's here sorry i haven't get too fast so if you go to motherdog.com slash minter yes they're gonna be a key and you pick on this workshop you just sign up and you're gonna get a temporary key of two dollars that you can use on any those model uh you're gonna see the key don't don't freak out it's just 10 boxes yes i know it's there it's remotely but don't use mine you can get one for free okay come on so i'm just showing you this is when you sign up so you just go to motherduck.com slash minter and you can sign up you get a key and you have a sample of code if you want to use sun and we are mostly going to use gpt nano and gpt 5.4 nano and with those you can see you can get a lot already for this workshop is plenty enough this key is going to be available until the end of today so if you want to work more I don't know later at the hotel you can still leverage this one open air router has also free here
Speaker 2 [06:59]
with Ulama, if you...
Speaker 1 [07:04]
As the keynote spoke, there was a game app for that just released last week. And so you can also use Ollama locally and download it with just this. Just be aware, if you do it right now, it's around seven gigabytes of data through conference Wi-Fi. That's why we got you with our free API key. All right, so let's go into the nitty gritty of DAGDB. We're going to talk just about the data set. we have a dataset which is into a .db file. So it is in the repo. So you can go ahead and clone the repo, and you're gonna have all the information in the workshop. Please, if you have any question at any time, just raise your hands. We are the two of us, okay? If it's something more specific on your laptop, please don't hesitate. We are the two of us, so one can go help you. If it's just a question where you're struggling you want to raise your hands maybe other people are also in the same situation if you are already done your exercise go have the people next to you the best way to learn is to teach people that's why i'm doing this job by the way so all that to say if you're set up with the repo we can go ahead so the the tag db file is right there so it's a small file of 20 megabytes and yeah that's for our setup so we talked about the data set let's go now and play around the game first so the TV is an in-process analytical database you can think it as SQLite but for other analytics it's building C++ and it's really fast it can crunch gigabytes terabytes on the data easily it has a rich ecosystem so you can use the CLI so we're gonna show I'm gonna show you a few demo just the pure CLI or you can use of course Python this is where it's actually the most used but there is also Java Node.js packages and just for information so this was the download on just PyPI of in a week of TechDB so I I have actually this website that I built that pulls all the data from DuckDB downloads. And you see that's quite a lot of user. So it's not anymore just a side project. It's a really phenomenal, I would say, data framework, data engine for Python. So let's start. So you can either do this one to directly install DuckDB. You can also do brew install dougadb if you're on macOS. So if you do this one, you're going to get basically the CLI installed. I'm already installed. And then you can start to fire up this. So we're going to put the timer here. It's time for you to do just install dougadb. The CLI here, you can install it to UV. and just run this command in the workshop folder. So I'm here. Oops. That's better, huh? I'm here in the workshop folder, and you see that I have the DuckDB file, which is the Duck Coffee, sorry, which is about 4.8 megabytes. OK, probably won't be here. And see, if I do this, for example, I copy this one I'm just invoking the CLI and I'm doing directly specific sequel commands okay and I have the results so I can also launch interactively the CLI invite you to go ahead so now I'm interactive in the CLI and can I use attach the coffee and I'm gonna attach the database by default that DB is an in-memory database like SQLite okay so in person everything in memory to attach something which is on the disk you use the attach command alright so here I'm attaching I'm gonna use the duck Duffy data database and now if I do show tables I see all the table and I can do some query here we've just a front statement so I'm gonna come to that later I'll leave you one more minutes 30 I know it's short we have a lot of things to cover just go ahead and get started
Speaker 2 [11:52]
questions so far anyone struggling yeah you got a we got a first question there that deserves a little bit of swag
Speaker 1 [12:10]
asking question it can be there is no stupid question and yeah come out okay there is a question over there maybe you can yeah I'm just looking for the github repo yeah it's right over there in the slide you are you on this page yes so it's in the upper right corner right over there
Speaker 2 [12:45]
Okay, thank you.
Speaker 1 [13:12]
A few more things. I expect that you have at least DougDB installed on your machine, and you start to play with the CLI that you just invoked with DougDB, as I did. I want to show you some of particular query. This is impossible, as far as I know, to do with any other analytical engine with two lines of code. I'm basically creating data over S3. Would it be parked here? It's a CSV, and just returning the results. So it's a public S3 parking. CSV, sorry. That is because DuckDB is packed with its own extension. It doesn't rely on other third-party or community of Python package. It's built, everything is built in C++, and there is core extension that is supported by DuckDB. So when you download DuckDB, You have just one single binary with no other dependency. So let's see the magic I'm gonna just run this one. So that's it. I'm parsing a CSV We've just one line the two lines of statements with just a from so you see why is that happening? It's because as I said, they give me as extension. There is core extension and community extension and if you see Basically here. I'm just listing the extension that has been loaded and you can see there is HTTP FS because I'm loading over so right here over history and there is also Popom Jason parquet which was already loaded. So that's the core extension and you have also community extension, so this is the website where you can submit your extension and you have a lot of community extension that is available there. Doesn't need to be always in C++, there is other clients, but that's basically just a challenge here. So it's more for really hardcore software developers, but now you can vibe code it your way through if you know basics of C++, if you need basic, I would say, extension. But most of the things you need are there and they're being autoloaded for you. So we learned about the tagdb-cli, we learned about the PowerFold extension ecosystem, we're here at Python, so let's do some Python. So you can basically create your first Python file and try basically to do the same thing we just did with CLI. So, DuckDB does have a relational API that you can call with Python, but most of the people use the SQL. As you can see, there is specific dialects, which is, I'll show you a couple of them. So instead of saying select star from, you just do from, and that's basically first class citizen from SQL support. There is also the group by all, which is not adopted by all the cloud provider, like BigQuery, Snowflake, but was first to implement all that. So there's a lot of small syntax that makes just the things easier and more readable as SQL. And because SQL is portable, so you can do it in Python, you can do it in Node.js, you can do everything. If you want to refactor your project in anything, then that goes really fast. So yeah, we can't run this one. Let's do, I'm just going to copy paste this. So we have the attachment statement, which attached the Duck Coffee database. I'm just initiating DuckDB, and then I'm doing a couple of metric calculations there. And that's basically it. So, part one, where is it? I have a typo problem.
Speaker 2 [17:34]
Not the workshop fuller.
Speaker 1 [17:55]
So you see it's pretty instant. The data set is really small. I challenge you to do a one gigabyte market file It's gonna be the same speed. It's so really different kind of experiences You've been doing identical queries with the database. Why is that? So it's because it's a single note. Everything is happening in memory So that's really Architecture design which is significantly different from the all the distributed system We come from from big data and just a side note about that we have been designing for big data framework because we had limited hardware, right? Back then like 10, 12 years ago when I was building on-premise cluster, well the maximum on-server capacity were 64 gigabytes of RAM. Now we get that on those laptops and the maximum you can get on the cloud is more than a terabyte of RAM, okay? So that means that all the work around that we've But for distributed computes to divide and conquer large workload is actually most of the time not needed anymore And there is a lot of overheads with network coordination job coordination that you don't have if you have on a single node All right, so we did Python you can also run this query. I'm looking at the time and we are already running so I'm gonna skip this one but feel free to run also this exercise so this is a group by all example that I was telling you I guess the same data set you can try this is the from first class that month that we did you have many many there is a dedicated on tech DB or sequel friendly page there is this one where you have all basically specific syntax dialect at the DBS path
Speaker 2 [19:53]
Maybe one thing to if people were wondering like why should I put from? Table first the thing that I really love about this from a developer experience is that this will give you Autocomplete on your column names for examples. So if you write sequel normally you go like select What was the column name again? I forgot and then you need to type in the table if you start with the table first Your editor will know what columns you have
Speaker 1 [20:30]
So MotherDuck, we haven't talked about MotherDuck just quickly, so that you understand a bit the link and why we are here. So MotherDuck is actually a US VC-backed company, DuckDB is a project from Amsterdam, so which is built and maintained by DuckDB Labs, we contribute also to the OpenSource project DuckDB, and we have a tight partnership since the beginning, we've had as the creator of DuckDB for MotherDuck. And so the way that you connect to MotherDuck is just with an attach. So we saw that you can attach a database, and now basically if I do show databases, this is all my database in the cloud. And if I run a query now, it runs in the cloud. You see one command, and I'm connected to the cloud. I have my MotherDuck token in my environment variable, right? So that's how I'm authenticated to MotherDuck, and we have a free tier you can play around with. not going to use it today. It's pure DuckDB. So DuckDB works great for Python, but you need to know SQL. What if your teammate doesn't? So how many venues does Duck Coffee have? Does people have play around to the queries? We have also a beautiful duck umbrella. The first one to get it right. Yeah. any guess 20 20. there you go all right so now we're gonna get into uh to the loop we have introduced db uh what yes question thank you so much all right there you go So we've played with TuckDB a bit. We installed the CLI. Hopefully, you just read the Python package also from the workshop folder, okay? And the GitHub repo, as a reminder, is right there. You go to workshop. We have the dependency in the PyProject.toml. Here, we have TuckDB, and you can get started. Now, for agents. So why TuckDB for agent? Well, four reasons, maybe you already understand, is that it's in process. So when you have a process of an agent, it doesn't need to rely on a specific server, client server, like you would do with Postgres. You can just run it locally, in process. So it's run in the Python process. You just do pip install dugdb. So for the CLI, we installed dugdb-cli. But here, it's just DougDB for the core library. You have fast feedback. So that's really important for LLens to not bending on long queries. And you can read anything, CSV, ParkEdge, JSON, Iceberg, if you're on table format, and so forth. So just to come back on, I was saying at the intro where we are coming from in terms of models. Who was using, I don't know, ChatGPT a year ago? Raise your hands. OK. So you know the feeling where, basically, you go to the UI. There is no egetic loop, as far as I know. And you say, OK, here are my schema. So you copy-paste the metadata, right, file or the table information. So now there is, I think it's this one. This is going to take some time because it's on the cloud. So let me run. So you see the dot table gives me all the metadata directly of Duck Coffee. So typically, I would just copy paste this into JetGPT and then say, hey, here are my schema. I need to fix this query, or I need to find a query about that. Give me that. So there's a lot of back and forth copy paste. That was like a year ago. was really not that far right it's really crazy um now um so that's for your setup uh to today so we're gonna let me just uh the goal today is that we're just gonna try what can we do today with open codes and you know let's say nano chat gpt which was released when it was released I don't know if I put the information I think it was 5.4
Speaker 2 [25:18]
It was like March, late March.
Speaker 1 [25:24]
And this one, the 1.5.9.0 was August last year. So let's try to play with OpenCode. So if you install OpenCode, again, you have in the setup here just the one script install. And what you can do is put your credential, export from the meter right if you sign up and you have the key and you can pick up the model reference so if you pick up this model reference for example and we gonna go sorry we're just gonna ask a question like this with the tag if you file. So I'm gonna run here and then I think I have... So I'm launching OpenCode, it's a shortcut, and now I configure with GPT-5 nano. And let's see, so that's the model which is from August right so I haven't provided any context actually anything so he's looking and it's looping already okay so I'm just let you the goal of this exercise right is to show you where we coming from today even with this model which is a year old but what open code does is already all this looping that we're gonna learn okay so he's already doing all the thinking and all the loop and trying out yeah okay I found this I found this file let me try again so now he's writing Python codes with with Doug DB and he's he's gonna try to run it. You see the DB path, and yeah, it's going to run it. I'm going to say, can you run it for me? So this goes really far. There is the agentic loop, and there is the modeling loop. The model is from August, okay? So that's a pretty old model. So my prompt was really vague, right? But of course, if you get better at prompting, you can just say, hey, here's the DAGDB file. Basically, just run, use the DAGDB CLI. Because here, you see, that's the difference with specific models. It's trying to use my local Python. You see there is an error, so it's going to try again and again. I'm just going to stop it right now and do GPT-4, a new model. And I'm going to say, use the TugDB CLI to query TugCoffeeDB and TugDB in this tier, or TugDB in Python. Give me these insights. All right, while he's busy, aha, I'm giving it hard time. You know why? It's because I have a session which was open, I believe. All right. He's there. is the results you see so he's query directly from him create a various table and some results are getting in and then he's gonna get some some summary all right there we go so you see we just did an older model from August this one is for March but there is the improvement in the model and his improvement in the tooling right the agent ik and the thinking that he tried you fail, you try again, you will get the result. That's what you used to do yourself, I'm sure. You were doing copy-paste, you try, you redo your man-loop, then you go like that. So we're going much faster right now because of this. And so that's basically summarizing what we just play around. Of course, you can have also an MCP server. Who has been using any MCP server, raise your hands. Okay, just a few. So MCP server is just a protocol to talk directly, to let your agent talk to a specific tool, okay? So if you want to have an agent for, for example, Google has done for reading your mail, there is an MCP server for Gmail, and basically you can ask it. There is a MCP server for MotherDoc, And so instead of trying and error any SQL queries, the model is going to do the looping for you and just give
Speaker 2 [30:56]
quick thing in between. If you do have any questions about all this stuff, you can also submit them at talk.pydata.de I think we also have an online
Speaker 1 [31:07]
Is that right? Yeah. Yeah. Good. All right. So now we are aware of the improvements in terms of the models and in terms of the workflows, right? The thinking loop. What does it actually look like if you build it from scratch? So this is it. This is a wild loop. This is just a loop. How those models and framework works is that there is basically a tool that you define. So here we define a tool, query.db. And that query.db does basically just a .sql or executes here. So we have the .db connection. And we do a .execute with the query statement. So what the model is going to do is generate the SQL query and then execute it directly in memory using .db in memory. So basically, all the compute is happening locally. Here we are using Open Router to basically go fetch the remote SQL that is being given from the LLM and then execute it locally. So you can try this one. So that's the next step. So you can copy paste this one, or you can go, If you're too lazy, you can go into the solution. And then you do a loop. One thing that you should do over here, if you're still sorry, where is it? Yeah, sorry. So you see I have my .env here. Yes, again, I'm going to print it. But you can get the key for free, right? It's the same one. Don't be greedy. It's funny because it's things I never do live stream. But now I'm live streaming and in person. So you put your key there. And you put the model you want to use. So for example, OpenAI GPT 5.5 Nano. The instruction is on MotherDuck Minter, right? If you go on the Minter and sign up, you have SQL snippets. You have snippets over here. So if I do now uvran the agent loop, which is in solution, So in one shot, he managed to do it. So what's inside this code? Let's roll back a bit. We have the tool that we defined, which is query.db. Then we have the question. The question is basically doing the LLN thing, getting the SQL back. And so this is the question. What are the best five selling products? And you see that there he one shot directly the information. Now let's try to do a bit more hard And do, who is the manager of Duck Coffee? I believe this information is not in the database. Okay, so you see they treat two things now. That's the loop, it's just a while loop, right? He select Duck Coffee one and then show tables. So that's the schema that I showed you just before, right? And then he said, actually, I don't know that the database doesn't contain this information. That was the tricky information. So that's the loop. That's basically what we saw just earlier on the OpenCode demo with a recent model. That's mostly it. So now, if we go further than that, because of course, Nowadays, you don't build the loop yourself. So you can play a bit yourself around what should fail, like we just did. So there is different trap question. Because in the data set that we put there, it is a real data set, which means it's messy. There is ambiguity with column names. There is value amounts where we don't know if it's in cents or just regular euro. So that will push, basically, the model with challenge, because it just has the column name and the value, like you would as a human looking at the data. So you can try those things to make it feel like we did with who is the manager of that coffee, which was a simple one. That's the full trap sheet. You see the row order amount is in cents. For our customer, there were wrong joints, not location ID, the store ID. There is a bunch of traps.
Speaker 2 [36:35]
When we started this a couple of months ago, these traps were actually working, now even the tiniest models are getting so good that they just evade all these traps again.
Speaker 1 [36:45]
Yeah, yeah. It is starting to be really hard to kind of like, you know, put the model in difficulty for these kinds of things. But we'll see. Of course, we are just always in a small model, a small data set, sorry. We have put some traps, but in reality, in your company and so on, there is much, much more traps. and that's what we're gonna see actually right now with the next part of the of the workshop and talk about what is semantic context so we can switch and in the meantime yeah I would encourage you while we switching so you can go into this page so on the 7.8 part for the loop and try to basically do those things with the query I did so you just replace you do an uv run on the agent loop file and see what's happening change the model you have three models so SANE, NANO5, NANO5.4 it's really like we'll get you the you will get the feeling and seeing what fails what doesn't fails how the things are being better and what the the loop actually
Speaker 2 [38:44]
is still a thing that they are missing right and that is the context of your business and your organization so it can do a really good kind of educated guess but if you want to make your models work well in real life situations you need semantic context semantic meaning just the meaning the meaning of your business the meaning of your metrics the meaning of your KPIs of your stakeholders your manager etc and so there's this concept in in the data space in the analytics space that's been there for a while of the semantic layer and there's tools that call themselves the semantic layer for your organization and they require quite a lot of work like you need to put in the metrics that you need to specific calculations etc and what we want to show you today is that oftentimes you already have a lot of that context it's just in different different kinds of tools right and now with these models with the agents that you can build you don't necessarily need them in one tool you can bring in this context from all kinds of tools and and make it work for your situation and so where is this semantic context and well it's it's in your bi system for example all the dashboards that you have like normally you wouldn't go into these dashboards and look at like how are they structured what are people actually building with these dashboards but with an LLM you can just send them off on a mission to go over all your 20,000 dashboards and see which ones are actually used and which are no longer in use or you can have a look at the query history from your analysts and see which tables are commonly joined together if you're using tool like dbt for example there's a lot of very rich context for your organization in there and so we want to kind of show you the minimal work to put that into a model by yourself at the end of this workshop so for today we have two layers of context one that maybe people are familiar with is skills has anyone used skills here before in your lm yeah yeah i see a lot of hands go so a skill is basically a set of instructions that um your your model your agents if you're using let's say cloud or gpt they can call upon that and retrieve those instructions right so initially the model will just see a small description maybe the description is if you have any questions about our data warehouse or analytics or our company look at this file and so when there is a question from the user about your company what was our revenue what was our what are our top performing products the agent will grab that file and maybe it's like 500 lines of text or something and it will have a better understanding hopefully of your company and your products so that's one part the other part is that databases have this very interesting feature that we didn't use a lot before which is the common feature like maybe you add a description to your table but in my ten plus years of working with this I have very few people who really filled in all the descriptions on all the columns of your data warehouse
Speaker 1 [42:31]
at
Speaker 2 [42:37]
And so now you have something that you can verify as well. You can say, hey, this is actually the column that I want to use for my sales or for my orders. And please don't use this column because it's a legacy column or something like that. And so now everyone in your organization that uses these columns or these tables now has access to this information. Both the people and the agents that query them. And we can do this in our .db file as well. so remember remember this this piece of code the loop that we just metty just showed us we have a little bit of an upgraded version here and you can find this in the in the repo as well you can try it out for yourself and so the first thing that we do is we import the the os library because what we're going to do is we're going to open the skill md file basically and so our skill md file in this case is a description of what our duck coffee international business looks like and we're going to use that as a system prompt for our agent and so now what we do basically is that we say here there is a a system role instead of just the user role that we had before where we could ask the question but we have a startup prompt basically that is taken into account with every question whoops so going to our repo here let's say we take our our normal agent loop right and we would ask what's the average order value and it would do the loop look at some of the orders and and so to be fair I had to I had to go through like an even smaller model so as you can see here I'm using QEM 3.5 4p which one of the smallest models just to show you like when a bad I wanted to show you the difference of a minimal model with the right context can do
Speaker 1 [45:05]
Just for information, the fact that it's a bit slow, there is a warm-up because he's using the local model, right? So as a reminder, you can still, every example, you can use Ollama with a local model that you didn't load, right? Or if you go to modernlog.com, enter on the slide up, you get your keys. But yeah, there is a warm-up time of the model to load it up locally. So don't be judged by the slowness. Let's just look at what's...
Speaker 2 [45:50]
the average order value in the rounding that I like as well it knows that it's in euros now so just having that extra context in the skill file does a couple of things like for one it helps small models do a much better job at their just do a much better job the second thing is that what many kind of show you you at the beginning with OpenCode, for example, is that it does or tries all these different avenues to get the right answer, right? But it has to do a lot of tool calling. So it goes like 15 or 20 times, tries different avenues. Whereas if you provide it with the right context, it can basically get it in one shot. So if you think about what does my company need and how can I help agents and humans in my company to get a better answer faster. Basically, doing this with the right context makes it a lot faster. All right, so yeah, we're going to skip the skill file for now. You can look it up in the repository. So the other thing that we said is we can add comments basically to the tables. So that's the other thing that we can do. You can see that there's a, yeah, basically some information on what's going on in those columns. And so, whoops. Where did I put this? Here we go. Did I mess this up? I think I might have already put them in there. And so, like we said before, the comment on is really just zero infrastructure. You use your existing infrastructure.
Speaker 1 [48:47]
By the way, a lot of other database supports in some way, comments on metadata, and you could argue, okay, does that live actually in a catalog and so on? That could be also the place. Here, the point is, I think it should be as close as the data, and it should be, you need to think in terms of like the AI agent querying it, right? so if the data is somewhere and then there is another catalog with another permission that it needs to to get the metadata that's already too much work and it's also more you know tools to call so much token that you're burning here the beauty with that TV is that again everything is in the divi file right so it is local and you can basically add the comments there and and it's just a different SQL query for the agents, but there is nothing else different in terms of like tool calling. It's just another. Yeah.
Speaker 2 [49:50]
This is me as is always the case with live demo.
Speaker 1 [50:18]
Get the wait if it's They definitely needs to put Yeah, we are remove the comments because here it's a big screen
Speaker 2 [51:12]
Did I, oh maybe I did not get the link, look here we go, here we go. This is the problem if you do like last minute changes and then, yeah I am not sure what I did with this database file. All right, we can follow along from here because I think it does the same thing. So, what is the problem here, right? We still, we're doing a lot of manual work, that's one thing. The other thing is that you get different kinds of SQL each time. So while the model, the agent has a lot more information about what's going on in your company, you can still get the wrong SQL query out of that. So if you want something that is specific to your company, a specific metric, a specific KPI, you need something that is deterministic. And all these agents, all these LLMs, these models are non-deterministic. So, we can use the scale for flexibility and for context, but for a deterministic approach, we need a tool. And so, basically, the tool that we have can be very simple. We already saw this with the DuckDB connection that we had to the database. So it was a simple tool, a simple query that did all the jobs for us. Now we can add some extra tools, basically, and we're going to use Pydentic AI for that to give us some more deterministic features, right? So this is actually very simple. Again, it's also in the solutions folder in the repository. But basically, we were writing that whole loop ourselves, right? We had the while statement, while true is there, but there's nice libraries out there that do this for us. So in this case, Pydentic AI does what we were trying to do in just a single line basically. So we can have an agent, a model, and a system prompt with the skill path. And then the tool that we had before is just adding a decorator on top, and we use the same query.db tool basically that we had before. Now we're going to add in some additional tools that are more deterministic, right? So for example, if we want to know the revenue by venue, we want to have a very specific way to calculate that. So that's one tool that we have that will always return the quick order in this case. Another tool that we can have is our top customers. So we can basically say, what do we define as a top customer? Is that by revenue, by number of products bought, all these kind of things that you would normally have in a data warehouse with an analytics layer on top of that. We can define that for ourselves if we think that this is an important thing to have deterministic. And again, think of this not as you're running a coffee shop, but think of this as for your company, what are the crucial things that need a deterministic answer? How can we provide that deterministic answer to our model, to our LLM, and have the LLM that in its answer to you or to anyone who's using it the other yeah you can look at this yourself as well but just to show you we have a couple of different tools in here that are deterministic as well as the non-deterministic agent basically so now when we test them we can run the agent tools that's what this still works And so, basically, right, this is our Identik AI agent. This is a really nice framework to make this work. There we go. There we go. But again, it's, you know, it's a very similar scenario. We're getting very familiar with the duck coffee business here. But just to show you these different approaches of getting to a similar answer, basically. And each time we're abstracting a little bit away so that we have more flexibility to put in our own tools to do things the way that we want them. And now we can ask these other questions, right? And so this is basically the nice thing about having these separate tools in there that give us a deterministic answer, but we can just put in any kind of text that we want, right? We can ask about the manager again. We can ask about a recipe for my grandma, if you want that. So it combines these deterministic and non-deterministic elements in the model. You can add any kind of model that you like as well. And so we talked about tools, right? We talked about tools for querying, tools for getting specific KPIs or metrics. But there's also something called an MCP, as Maddy already showed you before. And I want to clarify a few things. So who here knows, people have been using an MCP, right? Who knows the difference between an agent and an MCP, for example? Anyone brave enough to answer that? Yeah, I got a sir in the back. Microphone, please. I can repeat your answer if you want. Yeah, MCP is a collection of tools that the agent can use that is offered remotely. Yeah, yeah, yeah. So MCP is a collection of tools offered by a server, and an agent can use those tools and descriptions, use descriptions to decide which tools to use, and the MCP hosts these tools and descriptions, like an API? Yeah, yeah, no, that's, I think you get all the parts there, right? And so I want to clarify a little bit of the confusion that you can sometimes get, right? So I was showing you Pydantic AI to create an agent, and then that agent had tools in there as well. And now we're talking about MCPs, and the MCP also has tools. Well, basically, you can think of the MCP, like you said, it's often a remote server. it's a protocol for interacting with tools so you can have certain tools in your agent directly if you want to because it's just Python it's just something that you put in there or you can have tools specifically in an MCP so with a specific protocol to interact with these tools and now the the funny thing that we can do is that we can have our agent discover tools from our MCP So if we really want to separate the different concerns, right, we want to have the agent that has a certain logic of take these steps, use this system prompt, use this context, and then we can have a different logic for tool X, take these steps, for tool Y, take these steps. We can combine the logic of the agent with the logic of the MCP server and have them as separate concerns that we can work on independently, basically. Is that clear so far? Any questions on MCPs versus agents versus models? All right, so we can build our own MCP server as well. and we build our own agent before now we can start building our own mcp server basically like i said the mcp server is again just a collection of tools so if we take these tools and we use something like fast mcp we can just quickly spin up a server here Right, so we have our, where do I put this, agent MCP. So this is our little runner server here. So the simple tools again, same tools that we've been using before, but now they're in these frameworks specifically for FastMTP so that we can run them from a server, right? Let me do this, and so I can spin
Speaker 1 [62:04]
at well you're trying to look at the there is two registry of mcp there is uh mcp.so there is tons of like community mcp first thing uh don't install mcp that is an open source or not by trusted vendors there is a lot of copy in there you have to i mean stay safe right so if you have an mcp for google gmail just check out if it's officially the one from you know google because there is tons of them there is mcp server there is the name server but there's a lot of them that can be run locally right so for example we at mother duck have our mother duck mcp server but we have also a doug db mcp server that front locally so you have a local server that your agent can query where wdb is available okay we have a bunch of tools so that's also a bit sometimes a bit confusing yes most of the i would say big third-party providers mcp slack google whatsoever they're always remote right but some of them are local and that's totally fine you install and there is a small web server that's being installed locally so that's why all of those rely on web server
Speaker 2 [63:44]
The nice thing about MCPs, as opposed to functions, is that you can do specific things. Yep, of course. So, there was a question here as to why would I use an MCP server when I can also use a simple function or, let's say, a CLI tool, for example. So, the thing is that MCPs serve a specific purpose with a specific protocol, right? And what that means is that they can do things to help your model go to the next step in a way that a CLI cannot or a function cannot do as well. So, for example, they can do something called elicitation, which is basically coming back to the model saying, hey, here's an answer, but here are four different options. Have the user select one of these options so I can give it a better answer, basically. So that's one thing. the other thing is that you can do like progressive discovery so you come back with an answer and you basically say like if you want to go in this direction call this tool if you want to go in that direction call that tool with that parameter right and so it's kind of possible with with a function or a CLI as well but the MCPs work a little bit nicer in that in a way that's being said it's still very like we're in the early days of this we still need to manage is very
Speaker 1 [65:17]
You write your business logic new function, right? We did that with the agent tool. We do the tool for DuckDB query That's the best way to get started with your LLM. You put a function there. It's for you It's not for somebody else to distribute, right? The MCP really has the distribution. We will show you quickly After the mother duck MCP, it's like it's two-click authenticate anyone can go and that's it you're ready to use all the power. But I feel like personally I'm improving my productivity around everything just by creating first bash scripts that then I package into an agenting framework with Bidentic. But then if I need to distribute it, you know, or to share it with others, package it to an MCP server which is...
Speaker 2 [66:14]
Exactly, so when you have that distribution method for let's say everyone in your company, they can just use something like Cloud to add the MCP to their model. So in this case I think it's already added, let me check, yeah it already exists.
Speaker 1 [66:32]
So that's basically the configuration for any other MCP that's running locally, I mentioned earlier, like some MCP server run locally. So sometimes you will have to say, okay, run, and then add this MCP to your agent. And those commands that works with cloud codes, it's the same process that with OpenAI or OpenCode. Don't be confused, though. if you spend a lot of time in the web version would it be clouds or chat gpt they have different needs because they like to make things confusing so on cloud web it's called connector it's just the mcp server but it's called connector and on chat gpt i believe it's apps okay so if you go to apps but also over there if you go to the web version it's not anymore something installed directly you know on your machine and it's by trusted vendors so there is an approval to be done or to entropic or open ai to get your mcp there so coming back to stay safe if you install stuff that is on the cloud web version or open child ipt and you go on the registry you mostly save because there is already like
Speaker 2 [68:03]
it knows that it needs to call the right tool.
Speaker 1 [68:10]
actually just push a fix for the comments and I update one slide on the context so there is no two database there is one that doesn't contain the comments and one that contains the comments so if you pull them you're gonna have a duck coffee and the score
Speaker 2 [68:38]
Something you can try at home as well play around with it use your own database for example But yeah, this way we have an MCP server it exposes the tools to our agents so now we can also use it in cloud in chat GPT wherever we like and Finally if we bring all that together Like we said we have this separation of concerns right we have our unique agent that has maybe a specific style of communicating with us you can have a talk like a pirate or have the business context that you need which is something that your unless you do like happy prompting and instructions in let's say cloud or chat GPT that's going to be harder so this is really about building your own agent and then discovering what you can see here so this is the same basically one line prompt one line piece of code that we had right we have the scale file that we're reading to create an agent with identity AI and now what we're doing is we're actually discovering the tools in our MCP server for the agents to use so this way we're kind of embedding the tools into the agent or like putting them into the agent without a user necessarily having to add that MCP server themselves so that's just the final piece I guess of bringing all of those things
Speaker 1 [70:23]
So just for information.