Modern Creator
Dave Ebbelaar · YouTube

AI Engineering Full Course: Build and Deploy a Real AI Support Agent

A three-hour build of a Gmail customer-support agent, from an empty folder to a Dockerized server, modeled on client work that has shipped six times.

Posted
3 weeks ago
Duration
Format
Tutorial
educational
Views
182.7K
2.8K likes
Big Idea

The argument in one line.

Reliable AI agents come from structure around the model, not a bigger model: typed outputs, a classifier before the writer, hard-coded business rules, and code-level guardrails that make unsafe replies physically impossible.

Who This Is For

Read if. Skip if.

READ IF YOU ARE…
  • You can write basic Python and want one portfolio project that covers the whole stack, not just an LLM API call.
  • You freelance or want to, and need a concrete system you can pitch to a small business that still answers support email by hand.
  • You have built agent demos but never deployed one to a server you control with Docker, SSH keys and a firewall.
  • You keep stuffing rules into one giant system prompt and want a pattern for splitting classification, retrieval and decisions apart.
  • You want to see evals done on a real pipeline, including how to let a coding agent tune prompts without overfitting to the test set.
SKIP IF…
  • You have never written Python; the course assumes you can read and paste Python and follows a companion guide at speed.
  • You want production-grade auth, HTTPS domains or webhooks; those are named and explicitly left out of scope.
  • You want deep theory on RAG, Docker or Linux; each topic gets the minimum needed to ship, with deeper material pitched as a paid program.
TL;DR

The full version, fast.

Most AI tutorials stop at the API call; this course builds the whole system around it. A poller checks a Gmail inbox every 30 seconds, logs every message into a Supabase events ledger with tickets and messages, and runs each email through guards, a cheap Claude Haiku classifier, then a Claude Sonnet agent that searches a sectioned knowledge base with tools. Both agents return strict Pydantic models, so a plain Python decide step can escalate on attachments, refund requests, missing information or any reply that promises an action. A golden email dataset scores the pipeline, Docker ships it to a firewalled VPS, and a React dashboard lets the client edit the knowledge base live.

Free for members

Chat with this breakdown — free.

Sign in and you get 23 free chat messages on us — ask for the hook, quote a framework, find the exact transcript moment, generate a markdown action plan. Bring your own key when you want unlimited.

Create a free account →
Chapters

Where the time goes.

00:00 – 06:57

01 · Introduction

Demo of the finished agent, scope of the build, the fictional seller Harbor and Pine with paddleboards and flat-pack shelving, and prerequisites.

06:57 – 20:37

02 · Project setup

uv init, app and scripts folders, dependencies, .env and Pydantic settings, a minimal FastAPI app with a /health endpoint. Includes a Glaido dictation sponsor segment.

20:37 – 36:23

03 · Gmail API access

Dummy Gmail account, Google Cloud project, Gmail API, external consent screen with a test user, gmail.modify scope, desktop OAuth client and a refresh-token script.

36:23 – 45:27

04 · Gmail client

A Gmail class wrapping list, get, label and reply calls, a check script that replies to a test email, and digging into what the API counts as a new message.

45:27 – 53:48

05 · The poller

Polling versus webhooks, a while-true loop that runs poll_once on an interval, and a pipeline that labels processed messages in Gmail.

53:48 – 1:10:36

06 · Database

Supabase project, CLI link, a migration creating events, tickets, messages and knowledge_base tables, a psycopg db client, and the ticket-to-messages data model.

1:10:36 – 1:18:14

07 · First reply

Guards that skip mail sent by the bot, from its own address, auto-replies and bulk lists, then a default acknowledgement reply tested from two accounts.

1:18:14 – 1:23:21

08 · Knowledge base

A coding agent scrapes the guide into sectioned markdown files and a seed script loads them into the database for agentic, section-level lookup.

1:23:21 – 1:55:31

09 · AI pipeline

Pydantic schemas, a Haiku classifier, a Sonnet agent with knowledge-base tools, hard-coded resolution rules, and a decide step with escalation guardrails. Ends with a Jupyter playground for testing without email.

1:55:31 – 2:08:41

10 · Evals

A golden email dataset with expected section and action, a pydantic-evals runner, and a coding agent that fixes retries and tunes prompts to 100% without overfitting.

2:08:41 – 2:23:41

11 · Server setup

SSH key, a Hostinger KVM VPS with Docker preinstalled (sponsored), an IP-locked firewall on port 22, fingerprint check and a deploy user.

2:23:41 – 2:44:48

12 · Deploy with Docker

Dockerfile, compose file with API and poller, a read-only GitHub deploy key, server .env, docker compose up, Supabase IP restrictions and the git pull redeploy loop. Includes a freelancing coaching pitch.

2:44:48 – 3:05:19

13 · Admin dashboard

New FastAPI routes with basic auth, a Vite React plus shadcn dashboard for events, tickets and knowledge base editing, built into the Docker image and reached over an SSH tunnel.

3:05:19 – 3:10:06

14 · Wrap up

Next steps: make the dashboard pretty, add a domain with Caddy and HTTPS, stronger auth, and iterate the knowledge base on real tickets. Pitch for the paid accelerator.

Atomic Insights

Lines worth screenshotting.

  • When an AI support agent makes mistakes, the fix is usually branching into narrower pipelines, not switching to a better model.
  • Making an agent return a typed Pydantic model instead of a string is what turns an LLM call into something code can control.
  • A boolean field called promises_an_action catches the hallucinated refund or callback promise that prompting alone never fully stops.
  • Email automation needs code-level guards that skip messages sent by the bot itself, or the agent replies to its own replies forever.
  • An events table used as a ledger is the foundation of almost every AI automation: something happens, you record it, you act, you can replay it.
  • You can launch a client support agent in two to three weeks by escalating every ticket except one narrow, well-tested question type.
  • Split a knowledge base into sections and let the agent fetch only the ones it needs, keeping brand tone permanently in the system prompt.
  • Hard-coded resolution rules like 'missing paddleboard accessory means ship the part' are more traceable than the same rule buried in a prompt.
  • Escalate any email with an attachment until you have actually built attachment analysis, rather than letting the agent guess.
  • When a coding agent tunes prompts against your evals, tell it to diagnose the root cause and never copy test examples into the prompt.
  • Polling is simpler than webhooks because it needs no public HTTPS domain, which makes it the right first version of an inbox integration.
  • A Gmail OAuth app left in testing mode issues refresh tokens that expire after seven days, so plan to re-run the token script.
  • An SSH key plus a firewall rule that only accepts port 22 from your own IP works like two-factor authentication for a server.
  • A GitHub deploy key gives a server read access to one repository instead of exposing your whole account if the box is compromised.
  • Tunneling the admin dashboard over SSH to localhost avoids putting it on the public internet at all until you add a domain and HTTPS.
Takeaway

Put the model inside a system that can say no

WHAT TO LEARN

A production AI agent is mostly plumbing: a ledger of events, typed model outputs, code-level guardrails, a test set, and a server you control.

02Project setup
  • Start with a minimal FastAPI app and a /health endpoint so every later layer has a known-good base to build on.
  • Keep secrets in a gitignored .env loaded through Pydantic settings so local and production config differ only by file.
03Gmail API access
  • Expect OAuth and API permissions to eat more time than the code, and use a throwaway Gmail account while testing.
  • Testing-mode Google OAuth apps issue refresh tokens that expire after seven days, so keep the token script around.
04Gmail client
  • Wrap every external API in one client class so all Gmail operations live in a single, testable place.
  • Read how the API defines a new message; here it simply means anything still sitting in the inbox, which archiving clears.
05The poller
  • Choose polling for a first version because it needs no public HTTPS domain, and move to webhooks when latency matters.
  • Label each processed email in Gmail so both humans and the bot can see what the system has already touched.
06Database
  • Record every action as an event, group conversations into tickets, and store messages under tickets for a replayable history.
  • Manage schema through migration files in the repo so coding agents can read the structure and changes stay ordered.
07First reply
  • Add code guards that skip mail sent by the bot, from its own address, auto-replies and bulk lists before any AI runs.
  • Ship a fixed acknowledgement reply first to prove the full loop works before adding any model calls.
08Knowledge base
  • Split the knowledge base into sections so the agent fetches only what it needs and token use stays flat as it grows.
  • Keep brand tone in the system prompt permanently and let product-specific sections load on demand through tools.
09AI pipeline
  • Use a small model to classify and a stronger model to answer, each returning a strict Pydantic schema instead of text.
  • Encode business resolutions like ship-the-part or exchange as Python rules so every allowed action is traceable.
  • Let deterministic code make the final send decision and escalate on attachments, refund requests or any promised action.
  • Launch with almost everything escalated and only one narrow ticket type automated, then expand as the client gains trust.
10Evals
  • Build a golden dataset of emails with expected section and action so prompt changes can be scored automatically.
  • Change one thing per eval run and re-run the whole set more than once, since model outputs vary between runs.
  • When a coding agent tunes prompts against evals, require root-cause fixes and forbid pasting test examples into prompts.
11Server setup
  • Lock SSH to your own IP with a firewall rule on top of key-only login to get two layers of server protection.
  • Create a separate deploy user and verify the server fingerprint on first connect instead of working as root.
12Deploy with Docker
  • Package the API and poller with Docker Compose so the same code runs on a Mac and an Ubuntu server.
  • Give the server a read-only GitHub deploy key for one repo, then redeploy with git pull and docker compose up --build.
  • Restrict the Supabase pooler to your IP and the server IP so a leaked connection string alone is not enough.
13Admin dashboard
  • Give clients an admin dashboard to edit the knowledge base directly so content changes never require a redeploy.
  • Reach an internal dashboard through an SSH tunnel until you add a domain, HTTPS via Caddy and stronger authentication.
Glossary

Terms worth knowing.

Poller
A background loop that asks an external service for new data on a fixed interval, such as checking an inbox every 30 seconds, instead of waiting to be notified.
Webhook
A callback where the external service pushes an event to your server the instant it happens. Faster than polling but requires a public HTTPS address.
Pydantic AI
A Python library for calling language models that returns validated Pydantic objects, so the model's answer arrives as typed fields code can branch on.
Structured output
Forcing a language model to answer in a fixed schema of named, typed fields instead of free text, which makes its decisions testable and machine-readable.
Guardrail
Deterministic code that checks a model's output and blocks or reroutes it, for example escalating to a human whenever a reply promises a refund.
Golden dataset
A fixed set of example inputs paired with the outputs you expect, run after every prompt change to catch regressions.
Eval
An automated test that scores an AI pipeline's outputs against expected answers, giving a pass rate you can track as you change prompts or models.
Overfitting
Tuning a system so tightly to its test examples that it scores perfectly on them but fails to generalize to new, unseen inputs.
Database migration
A versioned SQL file that changes a database's structure in order, kept in the repo so every environment can be rebuilt the same way.
Session pooler
A Supabase connection endpoint that shares database connections between clients, used here as the direct Postgres connection string for the app.
VPS
Virtual private server: a rented Linux machine in a data center that you control fully over SSH and can reuse for many projects.
Deploy key
An SSH key registered on a single GitHub repository that lets a server pull that one repo and nothing else.
OAuth refresh token
A long-lived credential an app trades for short-lived access tokens, letting a script keep reading a mailbox without a person logging in each time.
Resources

Things they pointed at.

08:08tooluv
08:58toolCursor
16:11toolFastAPI
15:28toolpydantic-settings
23:00toolGoogle Cloud Console / Gmail API
54:10toolSupabase and Supabase CLI
1:03:40toolpsycopg
1:26:08toolPydantic AI
1:23:26toolAnthropic Claude Haiku and Claude Sonnet
1:57:36toolpydantic-evals
2:14:53toolNordLayer (fixed IP via VPN)
2:24:45toolDocker and Docker Compose
2:41:12tool1Password
2:48:23toolshadcn/ui with Vite React
3:02:16toolCaddy (for a future HTTPS domain)
Quotables

Lines you could clip.

1:34:50
“Usually the answer is not a better model. It's branching off.”
contrarian, one line, no setup→ TikTok hook↗ Tweet quote
1:44:41
“The AI agent should never promise actions it cannot physically do.”
clear rule from real client failures→ IG reel cold open↗ Tweet quote
1:36:30
“They put everything into the system prompt while it could be so much better by just having a couple of if statements.”
names a common mistake bluntly→ newsletter pull-quote↗ Tweet quote
1:45:27
“Customers are weird and unpredictable.”
short and relatable→ TikTok hook↗ Tweet quote
1:17:13
“Something happens in system X, you save that into a database, you take action and you want to keep a track record of what happened.”
the whole automation mental model in one sentence→ newsletter pull-quote↗ Tweet quote
2:41:36
“This is what it means to deploy software in production. This is what it means to run software in the real world.”
payoff moment of the deploy section→ IG reel cold open↗ Tweet quote
44:39
“Nobody writes code by hand anymore. But these are the parts where it still matters to understand what are we doing here.”
timely take on AI-assisted coding→ TikTok hook↗ Tweet quote
The Script

Word for word.

Read-along

Don't just watch it. Burn it in.

See every word as it's spoken — crank it to 2× and still catch all of it. The same dual-channel trick behind Amazon's Kindle + Audible.

metaphoranalogystory
This is an AI customer support agent. A customer emails a question about their order. The agent reads the threat and then looks up the answer in the knowledge base and creates a reply.
Anything it isn't sure about, it escalates to a human agent in this dashboard. In this course, you will learn AI engineering by building this system from scratch. And the example comes from real client work at my AI development company, DataLumina.
We have helped six companies automate their entire customer support using this exact system. And we are going to build all of them. this, so no shortcuts.
The Gmail connection, the API with FastAPI, the agent and its tools with Pydentic AI and Cloud, a super -based database, e -files to test the agent, a React admin dashboard, and last but not least, a real deployment to a server via Docker using Hostinger. And most tutorials and courses that you'll find here on YouTube only really cover the LLM API calls.
but not in this one. We really go full stack end to end. And now quick background for if you're new here, my name is Dave Abelard and I've been studying and working in AI for over 10 years.
I did a bachelor's and a master's, started out in data science and for the past years, I've been working full -time as an AI engineer. And through Data Lumina, I've delivered more than 50 projects across many industries. We start with a project setup and access to Gmail.
Then we built a puller that checks the inbox every few minutes and a super -based database that stores all of the events and tickets. And once the first automatic reply works, we built out the knowledge base and the entire AI pipeline around it. It classifies each incoming email and lets another agent handle the replies, all with guardrails around it.
Then we write evals to measure how good the agent really is. After that, we set up the server, deploy everything via Docker. And then we finish with the admin dashboard where the team can oversee the entire process.
And now before we start a quick note on the scope, because each and every topic that I will cover in this course. could be an entire course on its own and you don't learn AI engineering through one video. But I have set up this course in such a way where I'm going to give you the absolute most value I can give in the shortest amount of time by building a full project from A to Z.
So you will learn by building so that by the end of this course, you will have a fully working project that you can add to your portfolio and can showcase in your next job interview. And everything that you need is in this free written guide that I also created. for you.
The link is in the description and I will keep it open as I go through the course. And I recommend you to do the same because from there we can get the code snippets that we need in order to start building. And in order to follow along, you at least need to be somewhat comfortable with the Python programming language.
So if that is also completely new to you, make sure to first check out my complete Python for AI course here on YouTube. All right, so let's get to work. I am really excited for this one.
So if you are going to watch this video. I have this companion guide that you can follow along with. So the link to this will be in the description.
And here you can see all of the chapters and all of the set of processes that we will be going through. Now, this is going to be super helpful. So you can not only see me going through it on screen, but you can also reference this guide.
And also you can point your AI coding agents to this website over here and specifically to this page. to help you with certain setup steps, because that's what I'm going to do as well. Now, we are going to build this for a fictional company called Harbor and Pine.
And this is an outdoorsy kind of seller, and they sell on Amazon. And it's interesting. So this project is actually modeled after a real client that we've been working with, like completely different domain, but also...
e -commerce and selling on Amazon. So a lot of the things that I am going to share with you is coming from the real world. So you can literally take everything that you learn in here, pretty much go up to any business that still has a manual support process, and you can implement this exact project in order to help them automate with AI.
So we are going to work around a series of products that they are selling. And mainly we're going to focus on... Inflatable pedal boards.
So yeah, you heard that correctly. Like I had to make up something right for this project. So inflatable pedal boards, because there are different sizes, different weight options, different colors.
So people will naturally have questions around that. And then next, we're also going to cover flat pack shelving. So imagine this is just like a general Amazon seller.
And for some reason, like the inflatable paddle boards and the shelving, those are the best -selling products. But you can see with these shelves over here, there are lots of options. So how high does it need to be?
How wide does it need to be? Usually you can configure those, right? So naturally, that gives us...
a lot of different options to pick between. Let's go for the high level flow of what we're going to build. So first of all, we're going to build everything around a Gmail inbox.
Now you can follow along with your own Gmail inbox, but if you don't want to connect that to AI, I recommend to create like a dummy Gmail account. That is also what I will do to showcase this process. And you should know that...
In the real world, usually companies use some kind of ticketing system already, something like Help Scout or Zendesk or Gorgias or any of the other platforms that you have. And swapping the Gmail connector that we're going to build with any one of these platforms is going to be quite straightforward. So that is why I wanted to do Gmail, just so everyone can follow along with zero cost.
So that is how it's going to work. So let me see what else you're going to need in here. Yeah, so following along, there are a little bit of like setups that you need.
So make sure you at least have Python installed, Node 22 or later Git and a GitHub account. Now, I also highly recommend, of course, to use some type of coding agent to help you with this. So you can either use Codex, Cloud Code or something like Cursor.
Okay, so later we're also going to set up a Superbase account. I will show you when we get to that point. I will also be using Entropic.
So we will create an Entropic API key. Now you can swap this with any model provider. So if you want to use OpenAI, if you want to use Grok, it doesn't really matter.
Any like LLM can really work. So I'll also show you how that works when we get to it. And don't worry too much about the costs.
Like this will be like a couple of cents to run in terms of like API costs. So no crazy costs. And then the last step in here, which is going to be, I think the most valuable part of this whole project is I'm also going to show you how to actually deploy this on a server and really like make it to production.
So for this, we'll be using Hostinger and I will show you the exact setup because this is the only way that you can learn how to deploy software, which is actually a skill that... people are looking for when they are hiring so now we can continue with the project setup all right so let's set up the project so the goal of this section is to work towards a first setup of the python project and we're going to set up fast api and we're going to get an health endpoint that pretty much validates that we completed this phase of the project so what i'm going to do is throughout this guide i will show you as much of like little tips and tricks and nuggets that will help you in your like development journey beyond just actual the actual project in here so what i'm first going to do is we're first going to set up the project and there are lots of different ways that you can do this so first of all make sure to check the differences between mac os and linux because there are some commands who might differ a little bit but also just so you know that whenever you're doing this you can also
Just you do this manually via the finder or via your IDE. So I will show both. So first, I'm going to start a new project.
So I have a repositories folder. You can see for all of the different domains that I am working on. And I'm going to go into YouTube repositories.
And what I'm now going to do is I'm going to click in here and I do open in terminal. So you can also do this on Windows by putting your cursor at the top of the Explorer and then typing CMD. That will open up a command prompt.
And then what I can do is if you have UV installed, which you should have by now, you can run the following command. So UV can actually help you to set up projects, Python projects. So I can do a UV init.
And then we're going to give the project a name. So we're just going to call it AI Customer Support. Keep it simple.
And then for this demo, I'm going to add the no package command. That is just a different setup on pretty much the template that Yuffie uses to set up the project. And we're also going to use Python 3 .13 just to all be on the same page.
Now, this project will work with pretty much all versions of Python, but... just so you can make sure you can follow along exactly with me, I recommend to copy this setup. So what we can now do if I hit enter on this, what you can see, we now get this folder over here, see?
AI customer support. And I can now change directory into that AI customer support, tap to autocomplete. And I have a path installed that I can do cursor dot to open this project inside cursor.
Now, if all of that... was way too complicated you could also simply go in here create a new folder inside cursor or whatever ide you're using you could also simply open up a folder so again i'm showing you multiple ways to do the same thing but these are the little tips that i know when i was just getting started as a developer and became more serious as a software developer like these were all the little tips that helped me the most to be more productive on a daily basis so we can now close our terminal over here and bring up our terminal inside cursor in this case.
So we're working directly in this project. And you can see Eufy now set up a basic Python project for us. So we got a bunch of git ignore things in here.
We got our Python version. We got a pyproject .toml setup in here for Eufy. And we got a simple readme.
Now, the next thing is we can remove that main .py in here. So again, you could simply hit delete on here or run the following command. Now we need to create two folders.
So we're going to create a folder called app and we're going to create a folder called scripts. Now I can simply run this in my terminal and you can see scripts and apps are created, but I could just as well create a folder like this. All right, and then we're going to create one file inside the app folder.
And this is going to be a Python initialization file. So let's put this in here. So we actually...
turn this into a proper module i'm not going to explain this video what this is about if you want to learn more about that check one of my other videos my python guide or ask your ai agent so now we have this set up and we can continue with the dependencies now here we're going to use uv in order to install all of the right like dependencies and libraries that we need for this project so i'm just going to copy paste this that's the simplest way to do this and what you should know is that we do a uv add and then have a list of all the packages that we're going to use and then here you can see we do a uv add dash dash dev so this means this is only going to be used as a development dependency so later then when we deploy this into production on our server our server doesn't need these over here because we're just going to use it locally all right so i will copy paste that in here and run that and what you now will see is eufy will now create the environment for us now i will also i also get a message from cursor in this case that says hey look we noticed a virtual environment in here do you want to use that as a folder and i'm going to say yes
So you can now see that we have the right virtual environment selected over here. And now one thing that I'm going to do as well, which is kind of like my way of working with Python files, I'm also going to do a uv add and then dash dash dev. And then I'm going to put in ipy kernel.
So this will install the... ipy kernel which allows us to run python in the interactive mode so this is optional for you to do if you want to follow along i highly recommend to do that so let's see that is step number two adding the dependencies so that's now all in here and we selected it so we know that visual studio code of cursor in this case uses that now i'm going to do one more cursor, visual studio code.
I keep saying these two things because they're like both the same, the same backend, really the same starting point. I'm going to save this as a workspace. Now that is only relevant for this particular IDE.
So it's just stores all the settings and we can easily open it again. If you're using any of like the JetBrains IDEs or any other IDE, there is a similar process for this. All right, now we're going to make sure that we're going to expand upon our git ignore file.
So there's already some information in here, but we're also going to make sure that we exclude the following items from our project. So let's set this up. So you can see right now we add the following.
So this is going to be our environment variables file where we're going to store some keys. We're also going to get some credentials from Gmail, from Google. And since this is going to be a full stack project later down the line, there will also be some node modules in there.
So we already put that in there. And now we're going to continue with step number four to set up the env .example. So what I'm going to do is I'm going to create a new file.
I'm going to call it .env .example. And I'm simply going to copy paste everything that you see over here. So clicking on the icon here and pasting that in.
All right. And then what we can do is we can run the following command to create a copy. So this is cp to copy on Windows.
You can call copy item. So we do that. We run cp env .example .env and look what happens right now.
Now we create a copy of that. Now you could also simply copy and then hit paste. But again, these are these little things.
So now we also have a setup where we're going to store our secrets. You can see there are already some default setups in here, which we might change later. And there are going to be some secrets that we actually have to later get.
Okay, so that is another step of the setup. Then we're going to create our app settings. So as you can see, it's all just configuration at this point.
Pretty much the same stuff that we need to do for most projects. So I'm going to add a config .py file in the app folder. And I am going to copy paste everything that you see over here.
And I'm going to set this up. So let's quickly go through that to understand what we're doing here. We're using the .env library to load our environment variables.
We're using Pydentic settings, which is for me, my favorite way of loading settings. So we can apply some of those validation best practices from Pydentic to our settings as well. So if you have never worked with Pydentic and you want to get deeper into that, I have an entire crash course on my YouTube channel for free, which I will link here below.
I will show it in the video here as well. So you can check that out. Just search Dave Abelard Pydentic, you'll find it.
And this is pretty much a way for us to get our secrets and then load them into a settings variable that we can then use inside our application. Okay, and now we're going to set up the most minimal way of our FastAPI app. And this is fast API is going to be really like the engine of everything that we're going to do here in the backend.
Fast API is a library of framework to build like web applications and endpoints that we can use. And that is essentially going to be the doorways into or between our app, our database and our front end. So let's come in here and create another file in app.
We're going to call it main .py. And we're going to copy paste the following command over here. So we'll import fast API, we give our app a title AI customer support, and we set up the health endpoint.
So again, I'm not going to go into all of the particular like setup and syntax on what to do with fast API, because that could be an entire course on its own. So with any of these things, if you think I'm going too fast, you can always like sidestep or simply ask one of your AI agents to say, for example, like, can you explain what this does?
You know, and then of course, this is how you can really learn what we're doing over here. So here you can pretty much understand why are we doing this? What is this doing?
You get it. Okay. All right, so that covers setting up the main .py and the basic app.
And now here's the next thing that I want you to try out and that is dictating your prompts. So typing is of the past, right? We live in an age where we let our agents do the work and we communicate via voice.
And Glido is really the best way for developers to do this. And if you're following along with this course and you use this link over here, you can get... a free month of pro for glido the dictation tool to like try it out completely for free with all the features for 30 days so i highly recommend to check that out and use that offer even if you're already using something else another dictation tool because it's free there's really no risk to trying it trying it out right and i can guarantee you that you will like this better than whatever tool you're using right now so one of my favorite things about glido is first of all it's not only like lightning fast and the app is very minimal which a lot of the other applications that do something like this are these like giant electron apps that take up a lot of memory but It also works with custom formatting rules per application that you can set up.
So I have different rules for Slack and for WhatsApp and for my coding agents, for email. You can also have a custom dictionary in here. And this is really going to be powerful because when you are talking to your agents, you want to make sure that you get every word and every instruction right, because that can make all the difference when you're prompting.
When I am here inside cursor again, let's say I'm talking to my agent and with Glido, I can simply press a single button and start talking here inside chat. It works in any application, any tool, any text field. And I can pretty much give an instruction here and instruct that this is inside cursor and I'm using Grog 4 .7 with high reasoning.
And when I let go of the button, the text just simply appears instantly. And that's how fast it is. You can see it understand Cursor, it understand Grog 4 .7 and it's lightning fast.
So you will see me using that tool quite a lot. So make sure to check it out. All right, and now we're going to do the final check for the project setup.
So we'll come to our terminal and we're going to run ufi run fastapi dev and then we'll do app forward slash main .py and simply run this. And now you can see that this is starting and booting up our server. And now what we can do is we can take this URL over here.
So we grab localhost port 8000 forward slash health. That's the endpoint that we created. And now if we go in here, we should get a status OK.
So that might seem not like a lot, but that's all we need. Like you can see status OK. If it works, we should see this.
So if you're seeing that. congratulations, you now have the most minimal Python backend application that you could ever create. All right, so let's continue.
And this is a checkpoint of what we should have at this point. So we have the AI customer support folder, and then we have the app in here and all of the files that we created. All right, so next we're going to set up API access to Gmail.
Quite frankly, what you'll probably figure out is that this is going to be the trickiest part of the whole project. Sounds simple, right? But usually setting up API keys, permissions, OAuth tokens, that's usually where most of the time is spent because we cannot simply...
one shot this with our ai coding agents now also depending on whether you when you watch this video the pro and where you're watching this video from the process might look a little bit different but let's go through this step by step so what i'm going to do is i'm going to open up a new chrome session in here let's stay signed out so i'm just let's see let's do this I don't want a profile.
I just want to say signed out. So this is already where it gets interesting, right? So let's just call this YouTube demo for me.
Let's see. Let's just use this. Okay.
Because what I'm now going to do is it doesn't really matter which browser you're using, but I'm just going to use a clean one where I'm not signed in. So you can see, look. If I now go to gmail .com, I'm not signed in.
That's why I created a new browser profile. So I'm then going to create a new account. And I'm just going to say this is for personal use.
And I'm just going to put in my name in here. And with your dummy account, this really... Doesn't matter.
So you can just create your own account. So, okay. And then it's going to show you which email address you want to create.
So this, because this is going to be a dummy account, it doesn't really matter. So for the sake of demonstration, I'm just going to set up dave .abalar .demo and then at gmail .com. So let's see if that is allowed.
Yes, there. So I created a strong password with my password manager and then we're going to continue. Cool, okay, now here we are.
So now we have our email. So now, no, we don't want this. Now we can also check, like if I now send a message to dave .abalar .demo at gmail .com and we do a test and we say, hi there, we can see that we now have a working email inbox in here and we can message ourselves.
So that is great. So what? we can now do next is let's see we have our account created now the next thing that we need to do is we need to go to the google cloud console so i'm going to open up a new browser google cloud console because this is where we can set up the integration for our api key so what i can do over here is we're going to start for free and in here again depending on where you're from You may see different setup points in here, but this should all be free.
So now we'll go through this. So now step two, we need to verify our account. And for this, they need some information from you.
But like it says over here, this is still a free trial, no charges. And even after that, Google will not charge you anything. So I will now go through this.
If you click on this, I have to fill in some basic information. So just follow along with that, do that as well. And then I'll come back to you.
All right, so you can see I just plugged in my information individual. I just put in a credit card. There will not be any charges right now.
So the thing is, I always try to make these videos and courses as like... free cost as possible. But if you want real learning at some point, you just need a credit card, right?
Even if just like a couple of dollars, whether it's for API costs, getting a VPS or verifying something like this. Unfortunately, there's just no way around that. This is what engineering and projects need in the real world.
All right, so now we're inside the Google Cloud Console. You can also see that we currently have our free trial. And also like, don't worry about this.
Google will not charge you anything after this trial. So they just give you free credits to start with. If you really want to be sure, of course, just delete your account afterwards, remove your credit card.
Okay, so now we need to create our first project in here. So what we're doing like right now, Google Cloud Console is Google's... cloud environment where we can set up API accesses and even do entire deployments and even also can set up virtual machines.
So we can do a lot in this platform, but we just need the API connection because we will be doing the deployment on Hostinger because the whole setup with Google Cloud, this is more for enterprises. Like it's probably like five to maybe even 10 times more expensive to do it in Google than it is going to be on Hostinger. Let's set up our project.
Click here on my first project. And then I'm going to create a new project. And I'm going to call this AI customer support.
And what you plug in here doesn't really matter. Let's see. Customer support.
It's just easy to follow along with me. Let's see. We have no organization right now.
I don't think we need an organization. So we can just hit create. All right.
So we got that AI customer support. And then in here, like this is now setting up, you see. So we should be able to switch to this in a bit.
Yeah, so you can see at the top, we now have AI customer support set up in here. And now we're going to need a Gmail API key. So what we can now do is we can go to APIs and services.
So let's find where that is. Like the things you can always search, right? So that's probably the easiest way.
to for me to do this so you can also follow along so you can see if i just type in api you see api and services so if i come in here you can see that first of all we can i believe we can enable this yes and again for me this i've done this dozens of times but it's always because you do this so little it's always a little bit of like tinkering around to see where is it the ui also often changes so In here, we enable it.
And then let's see what are the next steps. First, we enable it. And now we go for the Gmail API.
That's the one. So we do Gmail API. Let's search in here.
This is the one. This is what we need. Okay.
And now we hit enable in here again. All right. So that is now enabled.
Now, next, we're going to set up a consent screen. So what we're going to do is first, we're going to search for the Google Auth Platform. So let's go in here and then click on branding.
Click on get started. Now we need an app name. So we're just going to call this.
So AI customer support, I'm actually going to because this is an app name. And this is all internally, but doesn't really matter. Now, you also need to support email in there.
So you can just select your own email address. Why is this? This is for when you want to, you need to create an app inside the platform.
And even though we're only going to use it for ourselves, you need to set it up in such a way that it could hypothetically also be used by other people. So that's why you need this. So look, here you can see right now we do internal, right?
So we said, look, this is only, Let's see, what is it? Because you're not a Google Workspace users.
Yeah, okay. So this is one thing. So like I've said, the thing is, if you are on a Google Workspace subscription, which is the paid business version of this, that's where you can do this.
We just set it to external, but don't worry about it. This doesn't mean that your inbox or something like that will become available for others. And that's also why we use the demo account, right?
So here you can also read more about what that means. Internal means if you have an organization in a Google workspace, let's say, for example, I have one for Data Lumina. So we all have an at datalumina .com.
Google Workspace account. If I were to create an app like this, everyone with the at datalumina .com domain on Google in our organization would be able to access this. Because we don't have that, because this is a demo account, we use external.
And in the beginning, we're just going to only allow test users to be able to work with this. We can enable that. And as we start to work with this, I will show you what this means.
External sounds scary, like everyone can use it, but that's not the case. So let's set this up. Now we have our contact information again.
Let's just do our own email address again. What was it? dave .abelard .demo at gmail .com.
So fill in your own. I would recommend just the same email address that you set up for your demo account. And then we're going to continue and we're going to create that.
So that is setting up the consent screen. You'll see in a bit how that works and what that looks like. So now that we have that set up, we're going to add ourselves as a test user.
So what we can do is we can come over to audience and we do add test users. And in here, you're just going to add your own demo account. So that would be dave .ebelar .demo at gmail .com.
So we have that as a test user. let's see that is now set up in here yes so the way this is going to work since we're going to do everything like on a test application so we don't really have to publish it or put it on an actual domain the token that we will get will only stay valid for seven days but that should be plenty to go through this to test with things to really try it out and later if you then want to like really publish an app then you google requires you to have like an actual domain We'll get later into that.
And those are pretty much next steps beyond this project. So keep that in mind. We should right now have you as a test user.
Okay, so now we're going to add the Gmail scope. So let's say we go to, so that's still on the same page, data access. And you can already tell, right?
This is more complicated than setting up the Python project. So even for me, this is always like, okay, what do we do? There's so many steps.
Like the Google Cloud Console is just a... It's just a pain in the ass to work with. So data access, add or remove scopes.
And we need Gmail modify. So let's do this. Let's search for gmail .modify.
So this is the one. And then I'm going to select this. And I'm going to click update.
At the bottom, it should now say that it has that Gmail scope in there. All righty. Okay, so now we have that, we have updates.
So what this covers, this permission, it covers reading, sending and labels. So this is really all we need to go through the project. So now we're going to create a desktop client, right?
So we're going to create a new client in here. We can select desktop app and then we can just name this AI customer support and we can leave this off for now. Might even be useful, but...
i i don't think we need it so here you can now see our secrets now these are your very private secrets that you should not share on screen like i'm doing right now because with if you have these credentials over here you can now read write and access the labels inside my gmail demo account so make sure to download that because we need those into our project and we can click ok now we need to come in here let's say go to my downloads and you can call this credentials let's see credentials .json and let's see now we're going to put that into our project i'm simply going to drag it in here to make sure we have the credentials in here i'm going to delete it from my download folder and let's see you can have that all in here all right let's come back to Our steps.
So create JSON file. And then the git ignore is already correctly set up. So credentials .json is git ignored.
Meaning if we push this to GitHub. You can see. It's not going to show up in here.
So we haven't done much with version control really to begin with. So this now might also be a good. time to also like actual like git should already be in there but we can do just do we just call it like a project setup and we're just going to call commit so now this is all local if you want you can decide to publish this to like a private or public repository that you'll be working on but at least we can keep some commits and checkpoints going forward All right, so coming back to step number seven, that's now completed.
So now we're going to need our refresh token. We need a little helper script that's going to do this for us. So let's follow along.
Let's see, we're going to copy this code and we're going to create a new script. So in here, new file, and we're going to call it get underscore refresh token dot pi. And we're going to paste this in.
So we're going to use the Google OAuth library, which we set up in our development dependencies. Remember, right? So these are development dependencies.
And what we're going to do is we're going to use our credentials. So these are, let's see, did I set that up correctly? Credentials.
Yeah. Okay. So this credential should be in the root.
So that's correct. We're going to use those credentials. And we're going to get our Google client ID secret and refresh token.
So that's now what we need to set up. So how does this work? We now make sure we're in the root of our project and we're going to call uv run Python scripts and we're essentially going to run this script.
Okay, so we're going to run this command and then what will happen is it will show you this URL that we need to open in the browser. So it will probably open in your default browser as well, but we need it in our browser where we are logged into this account. Or you're just going to simply log in when your browser prompts it.
So what I'm now going to do is I'm going to select my demo account. And then this is important. Google says now Google hasn't verified this app.
And that's true because this is our own app and it's in a test mode. So now it's important to hear click continue. So don't be mistaken by this back to safety button.
Click continue. And now here you can see what this app essentially wants. So this is why we needed to set that up in the first place.
And it mentions the permissions that it has, right? Read, compose and send emails. But also remember, we set you up as a test user.
So only this account will be able to do this right now. So that's the whole internal, external thing that we talked about. Even though it is set to external, only this whitelisted account can get into here.
So we'll click continue. And now you can see the application flow has completed. And now you can see in our terminal and see, let me make this a little bit bigger for you.
You can see our terminal now prints out our Google client ID and our secret and our token. So this is really good because now what we can do, we can come into our env .example and you can see that in here, we can now, boom, paste this, get rid of this. And now we have the credentials that we need in order to communicate with Gmail.
And these will be valid for seven days. So let's see. Let's clean up a little bit and come back to our guide.
So these are all the steps that we did. We did the check and let's see. We should now be good to go.
So again, this could be a part where you might run into some issues. There are some debugging steps in here. Make sure to use your AI coding agents if you get stuck.
Like I've said, this was probably the hardest part of the whole course. All right, so now it's time to actually start getting into the fun stuff because access and setup is never the fun stuff. So now we're going to actually work with our Gmail account and we're going to set up a small...
email client that we can use to authenticate. And then we're going to send an email. And this is really where the first time you see this, like, wow, this is really cool.
Even though you might already be used to this, like using all of the AI agents and tools, whatever, but now you're building it from scratch. Like this is your own account with no external party in between. We're just using Google here.
So big, big lesson, learning how to build applications like that yourself. We're going to go in app. new file gmail .com .py this is where we're in the editor we're not in the browser gmail .py and we're going to simply copy paste this script so let's briefly go over what's going on here right so what we're doing first of all imports we import the settings so remember this was our settings file that we set up this now reads via load .env our client id secret and token which we now have set up then we set up our gmail class so we do a class gmail we do the initialization we have some some main attributes in here and then we have some functions that we can use with this class so we have labels new message id get messages get a thread and a label is escalated send reply so this is our client really around the gmail api to start working with this and pretty much everything that you want to do with gmail you should add to this class in here so if there's something else that the api can do but it's not in there we want to add that to our gmail client okay so again here you can read in more detail through what each and every element of the code is doing but again this that is not the purpose of this entire course i just want to show you how to build
And for deeper understanding, whenever you want to go deeper, take time, go through the code, which I would still highly recommend as a learning process. But yeah, let's continue. Now we're going to read and send one email.
So now we're going to back to our scripts folder. And here's also something interesting just to explain to you. You might be wondering, why do we have an app folder and why we have a scripts folder?
Well, the application folder is going to be all of the core logic that we also need on the server. So this is our actual app. scripts is primarily one of kind of like scripts that we run every now and then during development to testing so we have a clear separation so in scripts we can be messy we can change stuff in an app we know this is production code that we're going to put on the server so that refresh token that was just something we needed to run once now we have that and then like with this test setup we need to run it in like seven days or so and then otherwise we don't need it So now we're going to see if Gmail actually works.
So we're going to create a new file in scripts because this is check. I'm going to do gmail underscore check .py, right? So gmail check .py and I'm going to paste in this code over here.
So what are we doing? We import our Gmail surface that you can see. Then we gather any messages that we have and then we send a reply.
But in order to first do this, we first need to have an email sitting in our inbox. So what we can do is this should probably also just work from sending it in here.
So let's just send from our own email, demo email address. So daveabelaar .demo at gmail .com. And we say test and we say hi there again.
So this is now sitting in our inbox. and you can see we have a function that checks list new messages. So we will get the message ID, then we will get that message, we'll get the header, and this will then send a reply.
So that is how this is set up. So let's now see if that actually works by coming back to... our check over here and just running the following command.
So we do a UFI run and then we run this Gmail check in here. And I'm not even going to use the Jupyter interactive session in here because the one that we installed with IPY kernel, because for now, just to test things, UFI is still the easiest way to do this. So let's run this and see what we get.
Cool. Okay. So now we can see we are connected.
found the email you can see that right now oh wait like i need to make it a little bit bigger for you so you can see i run the command it connected it found the email and then it sent it as well so now let's double check and come back over here there we go thanks we received your email pretty freaking cool right this is really cool so now through this we can pretty much keep the tabs on our gmail inbox by checking whether there are any new messages so now what i now want to do and i might need to tinker here with some uh let's see with some imports let's see yes yeah there we go because this will now not work so what i'm now going to do is i'm going to import sys and i'm going to do sys .path .append I'm going to play a little bit with the paths in here to see, does this work right now?
Yes, there we go. Okay, so this is like one of the most annoying things with Python is managing paths and where you run a file from. So with UV, that's always really easy.
It can handle that. But what I want to do right now is I want to play around with this a little bit. So with Jupyter Interactive, I can explore, you can see what this looks like.
So I can now see, look, I'm connected. And then in here, I can list. any new messages so here you can see this is still considered a new message in here so let's also see what that message is now we can see the actual data model behind this so we can see everything that's in here we can even check what are the headers and then let's see we can print that thanks we received your email that is still considered a new message and we'll just have to check how this how this works right because when if i run this now again does it still it still considers it as a new message.
So that is something that we need to figure out. Like when does Gmail API actually say this is the new message? Then we probably need to look in here and we look at how is this API endpoint getting that information, right?
So we do users .messagesList and we do an execution on there and it returns everything. So the thing is, I now just pretty much want to know if I sent another test. So this is going to be test number two.
hi again we need to send this so you can see this is now in here just trying to understand when we see new messages right so you can also see in here we do max results is one and we take the first element so now if i get this we will probably have another message so you can see now we got the second one hi again so now if i uh let's say we don't put max results in here and we get all of the messages so this is it's called list new messages but i think even it'll just list all messages in the uh in the user account because we do users messages lists and we do unique me in an in inbox so the whole thing is set up so that there is no label so if i now for example come in here and say you know what i archive these So now they're gone.
They're not in the inbox. If I now run this again, you'll see it's empty. You see?
So I wanted to show you this because this is arguably the most important part of like learning how to build proper applications, the data models and the logic behind it. And you could just follow along with this tutorial and I could have like... just continue with this and be like over here so oh you run this command okay it works now continue but like like i said even for me i was like trying to figure out okay how was this set up again because of course like i'm also to a degree using ai to make these tutorials right because nobody writes code by hand anymore so but these are the parts where it still matters to understand okay but what are we doing here how does this function actually work and that's what you get by then digging into this and then here just reading That is where I could understand, oh, wait, it's actually looking inside the inbox.
Cool. So quick little sidestep there. So let's all put that back.
We get our results. Let's see. I can close this out because this is now correct.
So we set up our Gmail client so we can go to the next section. All right. So now we're going to set up a puller.
And a puller in tech terms is a process, a little script that on a given interval, checks if there's or pulls data from whatever you want to look into. So it pulls data on a certain rhythm.
Now, this is different from working with what's known as webhooks. So you can see pulling or webhooks. There's a little bit of an explanation in here.
And pulling is generally easier. Working with webhooks is generally a more production best practice. So a webhook is instant.
So a webhook would mean every time a new email lands in our inbox, the Gmail server would directly send a message to our backend. So we have that connection.
So it's like instant. We know it exactly. Pulling is pretty much stating every five minutes from our server, we initiate a call towards Gmail and check, did something happen in the last five minutes?
And if yes, we pull the data. So there are two different approaches. And why I wanted to go with pulling in this setup is because it's way...
easier to set up. And we also don't need an actual domain because if we want to set up webhooks with Google via the PubSub, we need a public HTTPS address and domain. And now this is a really big topic that could have an entire video or course on its own.
That's why in my GenII Accelerator, we have a dedicated week to just that. That's why I go all in on event -driven architectures. webhooks, queues, and background workers.
It's over seven hours of content on just that. So if you want to go deeper, link is in the description. So let's come back to our code base and we'll go to app.
We're now going to create a pipeline. So app pipeline .py. Let's see, pipeline .py.
And we're going to plug the code in here. So what do we do? We add a logging, we import our Gmail service again, and then we'll do handle message.
So you can see message, we do gmail .com get messages. We get the header, we log something in our application, and we add a label that in this case, we add, let's see, the process label. And the process label is because that is processed with AI.
So we're going to build to this step -by -step. So I'll share in a bit once we have the whole pipeline ready to see how all of this works. And so this is how we handle a message.
And now we write the puller. let's see we're going to copy this code again and we're going to go in app new file and we're going to call this puller .py and put this in and let me make this a little bit bigger to start with this first so again we have imports and we write pull once so this is what we do we use our gmail class our gmail surface It lists all of the new messages and for the messages that we get, so this is a list, it will loop over it and it will try to handle it.
And otherwise it will log and it will stop. And then in our main script in here, we create a loop where we say while true, try, we do pull once and then we count it and then we put it to sleep. So this is where the pulling functionality comes into play, right?
So we have our puller interval seconds. this goes back to our config and let me make it a little bit bigger for you in our config we now have set up that we we want to like we run this script it keeps on running we have a while loop so this just continues to run while true and we put the time .sleep in here for every 60 seconds so that's how we can create that mechanism that every 60 sec it will just keep on running and every 60 seconds it will execute this function It will count it and it will try to then execute it by running pull once, which is this function over here to get the actual messages.
You're still with me. I know this gets a little bit more complicated. So make sure you follow along and also like pause if you need to, to make sure you really understand this.
So now what we can do is we can run this. And now we need two terminals to do this because on one, we need the API. And on the other one, we need the puller.
So let's see what I'm going to do. I don't have my API running. I'm going to open up.
Let's see. I'm going to go in here and I'm actually going to do AI customer support. So what I'm doing, I am simply opening up.
Are we still good? Yeah. I'm simply opening up a terminal inside this project again, because this is where I want to continue running my fast API.
And then I'm going to execute scripts in here. This is just a little bit easier to check. So what I will actually do is I will tell my agent to add the script to start the API server in here again, because now I just need to scroll back because we were running this.
This was how we started up our fast API surfer. So see, so now our surfer is running again and then I can come to the puller again and I can come in here and I can, let's see, make sure you have this, just switching some windows around and run this. So now this is pulling, why is it pulling every 30 seconds?
Ah, I see. There's an override in here in the config that it defaults to 60 seconds. But let's see, we have an environment variable where we can change this.
So if nothing is set in here, it will use 60 seconds. But if we update this, this will be leading. So that's why we use the 30 seconds.
So now let's see, we are running our application. So let's see what this will now do. So we'll just give that a couple minutes.
And then we pretty much need to, if we send our emails, we should be able to see some stuff happening over here. So let's come in here because this is now empty. We'll do Dave and we'll do test number three.
And hi again, we'll do one exclamation mark. It's test three. And now let's see, we'll also do test.
Let's see, to Dave, we'll do test number four and we'll do hi again. One more time. Gotta be creative here, right?
Okay. So now we got some action going on in here. So let's see what is now happening.
So you can now see that we got our new emails, which are processed in here. We currently still do not really see anything in here right now. We haven't configured that so we can move that over to the side.
So now we're processing these emails. And now if we go into Gmail, look at this, we're adding labels. We can see this has now been processed by AI.
So this is getting really cool, right? So now we're starting to put these pieces together where you can imagine like different categories, different tags, escalation, all setting this up right here. Again, to recap, because this is the end of this section, I think it's important to understand.
The most important part is understanding this is a while loop, runs every 30 seconds. Every 30 seconds, it calls this, this function, pull once. It takes the Gmail surface, then it lists the new messages.
New messages is everything that is inside your inbox. It's a list. It's going into this loop.
So for message in messages ID is going to try to handle the message. Then what is handle message? Handle message is the pipeline .py that we have in here, meaning it will get the message.
So the actual content, it will get the headers. It will print the log, which is what it's doing over here, right? So this is the application log that we see.
And then it will do Gmail add label and it will add the process label, which is AI processed. So it's not really processing anything yet. It's not really doing anything.
It's just adding that label. All right, and that brings us to the next section, database, another part of any full stack project. We need a database in order to start working and saving all of the data that flows through our system.
So this is going to be a little bit of extra setup, but again, we have to just work through this, nothing that crazy. So we're going to use Superbase for this. All right, so we go to Superbase.
If you don't have an account, you can create a free account and then you can also in there create a new organization. So I have one which is called YouTube, which is completely for free. It's currently empty.
And in there, we're going to create a new project. So again, this is superbase .com. Make sure to follow along.
And quick, if you don't know what Superbase is, it is... At the core, it's a PostgreSQL database, but Superbase has just a really nice UI and functionality around it that you're seeing right now. That's going to make it super convenient to work with this.
You can even like fully self -host Superbase for all of the projects that we work on, even for Glido, our software, our SaaS. We use Superbase, but we use a self -hosted version for that. And Superbase is really all you need for like, I would say 99 % of you watching.
Superbase is going to cover all your database needs for all your projects, unless you're inside an organization and you need a specific database inside AWS or within whatever cloud environment you're using or Azure. If you're building stuff for yourself, use Superbase. So we can now give it a project name.
So let's just, again, keep things simple, right? Call it AI customer support. Now we need a database password.
This is going to be important. I'm just going to hit generate in here and I'm going to copy it. So this is now, let's see, a password.
And again, I will nuke this database afterwards. So I will just make it easier for you to follow along so I don't have to blur things. So I'm just going to paste that in here.
And this is now, you can see my super secret password to get into my database. Coming back. um let's see for security i always recommend enabling automatic row level security if you want to know what it is do a quick search but that's just the best practice um we can let's see we can i think we can all leave this for now and then let's create the project okay one more thing region you can decide where you want like just pick it closest to you doesn't really matter that much new project for us which means it's going to be become a new database so this will now be set up take some time so i can now also go into our table editor so here you can see we now have a we have a postgresql database but there's nothing in here now we could like click around here and do all kinds of stuff but superbase has a better alternative for that and that is using the superbase cli So you can install that on macOS and Linux with brew or in Windows using the following command over here.
So I already have that installed. So what I'm now going to do, like this is our fast API server that is still running. I'm going to, let's see, can I create a new tab in here?
No, just do new window. Let's just do new window. And then we can link our project.
So I have super base. You can see if the super base command works, the CLI is correctly installed. so let's clear this out what we need to do is we need to do super base login so let's run that and then it's going to open up the browser and log in for you so i will do that right now all right so you can see here a code like showing up on the screen with my account i'm already logged in i'm going to paste the verification code in here and we are now logged into super base via the cli all right so let's come back over here and then What we're going to do is we're going to link our project.
So we're going to do a super base in it. And then we're going to do a following. We're going to do super base and we're going to do link dash dash.
And we're going to call or put like a project ref tag in here. And now the project ref is a part of the dashboard URL after project. coming back to our browser, you can see in our browser, you can see it over here, forward slash project, and it starts with an F here.
I'm going to take all of this, but then I don't need editor. So I need this ID. So I'm going to copy paste this, come back to our terminal, and I'm going to put this in.
So that is super base link project ref, and we're going to plug that in. And now because I'm authenticated with my account, We can make that link, right?
So this is not public or anything. You're authenticated in the CLI. That's why we can create that.
So now we are going to create our first database migration. And database migration is pretty much we're going to make changes. We're going to create the initial series of tables.
and create our structure. And quick little note, once you run the super base init, you should see this folder showing up. But that also means, I forgot to mention that, that you should run that super base init inside your project, right?
So in the terminal, do it either in your IDE or in a custom terminal, but make sure that the super base folder is in here. Because then if we do the next step and we come over to our super base migration new table, this command, I can come back over here. Let's just use the same terminal.
you can see that right now it is creating an empty migration in here. Now, this is one of those things, managing databases and database migrations could be a whole course on its own, how that works. The only thing that you need to remember here is we're going to provide a script, a blueprint for how to set up the tables, which tables and columns we want in our database.
And through the SuperBase CLI, we can just... input plain SQL in here and then we keep that code also in our project so our AI coding agents also know what the database structure looks like and also when we want to make changes we don't just make a direct adjustment to a table or column but we apply what's known as a database migration which means there is a particular order of things similar to how version control and git works so you can always go back and understand what the differences are between different versions.
So we can now plug in a really big script or big, relatively big, because this creates or holds all the SQL commands. So you can see what we're doing right now is we do create table events and then we're going to create tickets, messages and a knowledge base and an events table. So this is the structure that I recommend.
This is also generally what we use in all of the... software products that we've built around customer support. It's not really that complicated.
This is just the foundation that we need. So now we can come back in here and we can actually push this. So we can do super base DB push, which again works with the super base CLI to pretty much say everything that we do in here, we can push that.
So coming back in here, we do super base DB and we run push. Boom. So.
This will now start to run. Do you want to push the migrations? You can use the arrow keys.
Yes or no? Yes, we want that. All right.
And now here's the fun part. Now let's come back to our browser. So this is the Superbase dashboard and I'm going to hit a refresh and boom, there we go.
We now have an events table. We have a knowledge base messages and we got tickets. So it looks like we are ready to start working with this.
So now we have our database, but still we have no way for our, in this case, first local project to connect with this database, right? We haven't set up the connection. So that's what we're going to do next.
So we're going to add the connection string. So in the Supabase dashboard, you can see over here, big green connect button. We're going to click on this and let's see what we need.
So this is what we want. We need a direct connection and we want the session pooler. This is important.
And let's see, I think. this is we can all leave that the same because what we now have is we can now get our connection string which is the following so what we now need to do is we need to go into our environment variables and you can see we have our database url so let me show you what it looks like it's this one i'm going to plug this in but you can see we have our password that we need to plug in there so coming back to the setup over here we need our password let's see uses the correct port we do a direct connection so what we need to do we get our database password remember right we stored that here and i'm simply going to like from the brackets over here i'm going to take this all the way to the other bracket remove it plug that in here So this is now a database URL that we can use to directly connect to our database via the session pooler.
Now, of course, this is all stuff that you should keep private because with this right now, again, similar to my Gmail, you could connect to my database. And then we're going to need our database client. So similar to what we created around Gmail, right?
We now also need a way to connect with or talk and communicate to our database. So I'm going to come to app. And I'm going to do new file db .py.
And I'm going to take this entire script that's in here. Now, this is a pretty big one. So again, let's briefly go through it.
We have imports. We use psychopg. That is the Python library to work generally with databases.
We have our connect. So this is how we connect to this. We need to test that in a bit to see if our connection string, if we set everything up correctly.
And then in here, it has a whole bunch of methods that we can use to work with the database. So we have like startEvent and everything has a doc string.
So you can see like what it does. FinishEvent, failEvent, upsert the ticket, update the ticket, save a message. So these are the things that as we process messages, we will call these methods in here to do the database operations.
And then you can see underneath that is just plain SQL. So all of these Python methods are SQL queries. that we execute and send over to our database using PsycopG, or however you pronounce this library name.
Okay, coming back, we now are going to expand our pipeline .py. So you can see I added some new lines in here to indicate what was already in there and what are we going to add to it. We can just keep it simple and we do a copy paste in here.
So let's come back to our pipeline .py. So let's see, open this up pipeline. You can see we had a very simple script in here, remember?
So this just added the labels. So now I'm simply going to replace all of that. Show one more time what's going on over here.
So now we also have our database that we import. So we have our database connection and you can see now the first thing that we do is Whenever we handle a new message, we're going to start the event.
And there is way more logic around this that covers all of the database operations. So start event, remember, what does it do? Claim a message, returns none, whether it's already handled or in progress.
SQL command, insert into events, Gmail message ID, and then the values. So what is that going to do? Well, if we come back to our database, let's see, we now have connected.
So we have an events table. So what this SQL query now does, it is going to insert into events with the following Gmail ID. So you can see that that is matching.
So that is now what we expect if we start to run our test again. We will handle the messages, but they will now also show up in our database. So let's see how we can check that.
So we can run our polar again, which I think might actually still be running. So you can see this script was still running. If it wasn't running, let's see.
I'm going to clear this one more time. Wait. Let's see.
Get the command again. In here, run this one more time. Okay.
So this is now pulling every 30 seconds. So now, let's see. Let's actually, this is now processed.
So our AI won't touch it anymore. Now we're going to do, what are we? We are on test number five, right?
Hi again. Times five. Gotta do something.
Okay. So now we send that message. Let's wait for our polling script to run this.
And now like depending on when it just hit or whether we were right on. Boom. There we go.
So now it handled one new message. So let's see if everything is already working together. So let's see if I now come to my database and I refresh this.
Boom. One shot. Okay.
Love that. Even during the demo and during the recording. Always love it when this happens because this means our connection is set up correctly.
So this is big. This is a huge, huge milestone. This is also a big unlock for you to really understand like what's going on inside here.
Like, so now whenever we like run that script, we process it, but we add it to a database. So now we can see all of the information in here. And if we come back to our, so probably if I just refresh this, yeah.
So you can see our test number five is also AI processed. So this is now handled. And let's see.
We also even have our messages and our tickets in here. So this is now already happening in all of the code that we set up. So this might also be, again, a good time to really understand what's going on in here.
So how to do that? You always trace the starting point, right? So remember our puller, while loop, 30 seconds, handle a message, come in here.
start event, we add it to the database. So we will process the event, right? We create that.
And if we don't get anything valid back, we just still add the process label in there because the AI is processing it anyway. And then here, this is where we're going to the try loop. So it's going to try and process that Gmail event.
So this is new, right? So, or extended, I should say. So we get the message, the header, the sender, and then here you can see.
we're upserting the ticket and we're upserting and saving the message. So this is why we not only have an event that is added to the database, but we also have upsert ticket. So in customer support software, you usually have like a ticket, which is the highest level hierarchy, really ID under which data can fall.
So a ticket can have multiple messages because if... Customer, let's say, is going back and forth with support, asking one question, then support is answering, the customer answers again. It's all the same ticket, but it's different messages.
So that's the data model behind it. And also, so why we create a ticket. So you can see there's a Gmail thread ID.
So we use that as the, so like internally we use an ID. So we have a key for the tickets and we also have a Gmail thread ID. But the primary ID internally in our database makes it unique.
So here you can then see the customer email address. And then there are messages underneath that that relate, that share a ticket ID. So this is how that mapping works.
So let me now actually show you if I now, let's say, come in here and let's say, hey, how are you? And I sent that. This is all still running, right?
So we need a couple more seconds for this to process. Now, if we come into messages, there should be one more message. See, we now have two messages.
Hey, how are you? But we still have one ticket. So this is all working.
And events, there should be more events because the event handles everything. Event is everything that pretty much happens. So every time there's an action going through the system, we want to save that and store that as an event.
All right, so we're already making great progress. So now let's look into creating your first reply. So now we're going to go through like a couple of Python scripts in order to set this up.
We're going to write some guards. All right, so guards, why do we need them? Well, guards are very important when you are working with anything email automation related because this is going to prevent our agent from going into this crazy loop where it's going to reply.
And then that reply is triggered as a new message and it's going to reply to that again. So it's going to like continue and spiral onwards. So we need some rules for when can a message be skipped.
And here is some basic logic that we can use for this. So let's see what this looks like. We have the guards in here.
Let's see. Let's make this a little bit bigger. there can be a skip reason.
So return why the bot must not answer in this message and then just return a none when it may. So here are a couple of conditions. So if sent in message get label IDs, it is sent by us.
So whenever we send a reply, we ignore it. So this will still show up as an event, but we don't want to process it. Like this is the first thing that avoids whenever we send a message, it doesn't count as a new message that the AI need to handle.
Now, then also we can set up from our own address. So again, this is also something that we can use for testing. So if our own email address, if we sent a message via that, what we're doing right now, we also don't want to reply.
And then the next conditions in here are just a basic setup, but this is anything around like out of office, newsletters, they'll use those internal tags. Now, again, this is just a setup. This really depends on your use case and what you're doing.
But even if you, for example, really want to connect this to your own Gmail, this really might be something interesting for you where if someone sends you an auto reply or you get an email newsletter that we're not replying to this. Of course, we can also later check that with the AI, right? So we can also have our, we can instruct our AI via prompts to say, reply to this, not that.
but we also really want some guards in there to have it like actually physically impossible for the AI to handle this. Okay, so that is the guard that we have set up. Now, then the next step is to expand our pipeline once more.
So we're going to add some more information to this and we're going to start with a simple acknowledgement. So this is the default reply. Hi, thanks for your email.
We received your message and we will get back to you soon. harbor and pine support great cool so now what we're going to do is two things come to the pipeline come in here just replace everything there we go okay so gar uh let's see guards did i yeah i made a mistake that should be guards with an s so that's my ide helping me a little bit so what do we do well first of all uh guards so here you can check we now get that reason right so remember we we return the reason so it's sent by us from our own auto submitted bulk or email list and if there is no reason to skip it we return none so that's why if reason we do this and we return this and if none it will simply continue with this part of the code all right so that is what the pipeline now looks like and we have the acknowledgement in here which will be sent let's see scrolling down if we send it we will send it over here the thing is now what what we what you of course should be aware of is if you are now sending from your own email address it's not going to reply because
we set that up as like a protection. All right. And then once we have all of the acknowledgement code in here, what I'm going to do is I'm going to restart the puller once more.
So let me show you, because the thing is, whenever something is not working, you might just want to restart that script again. I will see if I can make some changes in the script so that it automatically picks that up. So what we can now do is we can try three things, three things with our new changes.
So first I want to send and let's see i'm actually going to like flip this again for you and let's see scroll up ah you cannot see that okay i'll make it bigger we're going to test sending from our own email to our demo account from another email address so that's the first thing that we're going to do so first i'm going to come in here dave .abalar at demo .com and we'll do test from other account we'll do that We'll put hi there.
So this is the first test because this should now get the acknowledgement. So we'll run that. And then we're also coming back to our Gmail account, our demo account.
And we're going to do the same thing. This is going to be test from demo account. There we go.
So you can now see we already got that message in here. So this is from my Data Lumina email. And here's the other one.
Okay, now let's monitor and see what happens. There we go. Reason skipped, sent by us.
And another action acknowledged. That's, I was just in time. Perfect catch because that is exactly what we wanted.
So now we should have both. Let's see, let's refresh this. You should see both as AI process.
That is still the same, but you can see from my external account. hi thanks for your email we received your message now let's come back over here boom auto reply from an external account that's really good now our own email address so let me archive this our own email address no reply because this was from internal so we don't we don't want to answer this good good good so the guards are working cool so that wraps up the whole database section.
And of course we can, let's see, where is it? Database, you can see, we can now see some events coming in. Processed, skipped, recent, sent by us.
So this is another moment to like, really like take a step back and already acknowledge, pun intended there, acknowledge what you've learned already. What I'm showing you here, like having an events table that you could use as a ledger. and then processing messages and tickets separately, this is like big unlock.
Like if you understand how to do this well, you'll understand how to build pretty much all, or not all, but this is a big word, but like this is the foundation for almost any AI automation project. Something happens in system X, you save that into a database, you take action and you want to keep a track record of what happened.
So you can... reference it back you can redo it and that is all using a very simple setup over here and now messages and tickets can be applied to lots of domains right so this is just customer support but the same happens when you're let's say you're processing invoices the same can be invoice sent invoice received do we need to process it or is it already processed who is the invoice from you know so just giving an example of how this similar approach similar way of thinking can be mapped to other different projects as well.
Cool. If you're still with me, you are doing great. We are now getting into the actual AI engineering process.
So this is where we're going to tinker with AI. So let's set up our knowledge base. So what we're going to do right now is whenever you're working with AI for pretty much any company, usually you want to have some like custom data in there.
Because the AI needs to know what it needs to do. And in our case for customer support, it needs to like understand how to handle certain cases. So in here, I have a whole bunch of examples that we're going to add to our knowledge base.
Now, what we're going to do here is instead of like copying, pasting everything. So there's a bunch of knowledge. We're going to use our AI agents in there.
So let's see. It's all markdown files with rules. And then we're going to add a helper function.
in the db .py, the file that we already have, to get our data. And then we're going to write the seed script to get these documents for the first time in our database. So this is a one -time operation, right?
Because once they are in our database, then our application can use it. And we only really need to update it when we make changes to the knowledge base. So what I'm going to do right now is I'm going to take this one over here.
And right now I'm going to go inside cursor and let's see, I'm going to, first of all, I'm going to stop the polling surfer. We don't need that right now. I'm going to start a new session.
Doesn't really matter which model you're using currently. I'm on Grog 4 .7 high faster. I'm going to plug in the URL in here.
And now, of course, I'm going to use Glido for this. So I'm going to say, can you go through the instructions on this page and help me set up the knowledge base and the two scripts? to load the database and then seed the database don't run anything just yet just set everything up and then tell me when you're done all right so we're going to run that right now and because it's a let's see make sure to put the url in there because it's a public domain it will understand that it just needs to scrape all of this and it's going to put it into the knowledge base folder so what we can do right now coming over here let's see this will take a couple of seconds.
And after that, it will understand that it needs to create a new folder. So let's see how long grok 4 .7 high fast needs in order to do this. All right, there we go.
And now you can see it's getting to work. So it's creating the knowledge base folder and it's putting all of the markdown files in here. So we have the brand and tone.
We have the escalation rules, pedal boards, returns and warranty, all the logic on the shelving and then shipping. Perfect. Okay.
So this is now set up. So let's see, we can keep all. And let's see, we have our app in our DB.
It should now also have the helper functions. And let's see, coming back to our full guide. So what was it?
Was our helper function in that and then our seed script. So what this does is you can see if we execute this with dbconnect for path in sorted knowledge base, get all markdown files, get the rows for section title content in rows, insert it into the database. That's pretty much what it does.
So if we then come to our database, you can see our knowledge base is still empty. So if we now come in here, let's see one more time what was the command. We can copy this command, come over here, make sure we're in AI customer support.
We now have a script, scripts, seed knowledge base, which is the following. We're going to run that. It's going to create all of the entries coming back to super base, checking our database.
And now we should have all of these rules in here. So we have sections and we have content in there. So we really split it up dynamically.
Now, how to structure a knowledge base, again, depends on size, complexity. For a knowledge base this big, doesn't matter. Like, I mean, you could have, by all means, put it into like one markdown file and just gave it to the AI.
But this is already a little bit of a better setup so that as you start to scale, the agentic search that we're going to build can more dynamically go through this. So that will save you with tokens in the long run. Because instead of just always giving the entire knowledge base, we now just create an agent that's going to look into the specific sections only that it needs.
And for example, like just the brand and tone, we will always have that in the system prompt because that's something we always need. But if someone asks a question about pedal boards, we don't need information on shelving. And now retrieval augmented generation or RAC is yet another one of those topics where you could go super deep.
And here also in my Gen AI accelerator, we have an entire week dedicated to it. There are 12 lessons with almost seven hours of content covering everything from factor databases to hybrid search to building full RAC pipelines. So if you want to go deeper on that, link to the accelerator is in the description.
Okay, so now let's get into our AI pipeline. So what we're going to do is we're going to set up a multi -step pipeline. to first classify with Haiku from Entropic, a smaller model.
Then we're going to use Sonnet with a series of tools. Then we're going to use deterministic code in order to make the final decisions and handle the logic. So this is going to be a small tool loop, simple but highly powerful given the setup that we're building with.
So now what we need is we need our Entropic API key. So what we're going to do, let's see, is... open up project again come over here to our environment variables you can see entropic api key so what i'm going to do i already have it open here let's just create a new throwaway key so that was i don't know what this is i just want an api key and i'm just going to call this ai customer support and you know what i'm just going to say that this is going to expire tomorrow So that I don't forget removing this key.
So you don't get free tokens on my account. Let's set this up. And copy the key.
So AI customer support. Coming back in here. Bam.
Put that key in there. All right. So what are we going to do?
We're going to create a folder. And we're going to call it AI. Because this is where we're going to do the AI magic.
It's going to become in app. And we're going to call this AI. Are you with me?
Yes, you're still with me. So first, we're going to set up schemas .py. Now, this is a, let's see, in AI, schemas .py.
This is one of the most important things to do when you're building AI workflows and pipelines. When you're working with Python, which I recommend for AI workflows, use Pydentic and set up data models, very strict data models around your... like data domains.
So what do I mean with that? Let me show you what this is. So here you can see we're using Pydentic and we specify data models for how we want our AI to classify and reason about our data.
First, we have a section in here. This is just like a Python literal. So the sections currently can be about pedal boards, shelving, returns and warranty, shipping and other.
This is exactly the same that we have in our database, right? So that's number one. Then there's a language step in here, whether it needs a human, a reason, and an acknowledgement.
So this can now classify an incoming message based on this Pydentic data model. And you'll see we're also going to use Pydentic AI, which is my favorite library. lean library to work with large language models in the Python ecosystem that natively like builds on top of Pydentic.
So we can get structured output using these data models, which is really what makes the difference between like a half -assed AI workflow and just like robust structured workflow where we can, that we can programmatically control. Now, then there's also an issue. So we also have a data model around that.
So first of all, which product is this about? Is this a paddleboard or is this shelving? Now, of course, as you start to add more products to it, this list will grow, right?
What's the problem? Missing accessories, slow leak, seam split, missing hardware, damaged panels, categories. Again, domain specific.
What's the client you're working with? What's the project you're solving? We've got an order number, day since delivery.
So this is all depending on your use case. What do you want to put in here? What do we need to extract from the message?
And then we also have an agent reply. And here you can see, we also just don't let our AI reply with like a string, but we really want a structured data model to say, does it have enough information? Is it promising an action?
What's the issue type over here? What's the action? Do we reply?
Do we escalate? And then there's decision in here. You can go pretty deep on data modeling and how to set this up correctly, but this should already give you a really good idea about how to think about data that's flowing through your system where you want AI in the loop.
So once we start to run some examples through this, this will become more clear. But this is a really big and important step. So if you really want to get good at AI engineering, make sure you really understand this and go through everything line by line.
Make sure you understand Pydentic. Make sure you understand all of the data types in here. Because this is really where most of the work after the initial prototype happens.
Data modeling and then creating programmatic workflows around that. Okay, little sidestep on the data schemas. We now have those.
Now we're going to write our classifier. So this is going to be our first agent, if you will, that is going to classify the incoming requests. So what I'm going to do is I'm going to copy paste this one more time, come back to, let's see, let's close this to create a little bit more space.
And in AI, I'm going to create our classifier .py, oh, .pt, we don't need pt, we need py. We're not using PyTorch here. What do we have?
From PyIdentic AI, we import their agent class. Their agent class is like the wrapper that we can use to use pretty much any model provider that we want and create instructions, which is the system prompt around it. So now you can see this is the system prompt for our agent.
You triage customer emails for Harbor and Pine. Explanation. And then we set up our classifier.
And then in here, you can, first of all, I, let's see, I should put model in here. I like this better just to have that in here because the first argument here that we put in is model.
So it didn't have that field setup. So it would be maybe a little bit hard for you to understand, like, what is this? But look, in settings, we have already set up our classifier model and our agent model.
And in here, we're using the Pydentic AI notation. So entropic and then using a colon and then Claude Haiku 5 .5. This is the Pydentic AI notation.
So if you want to learn more about that, you can go to Pydentic AI. You can go to the docs. You can go to models and providers.
And here you can see all of the different providers that you can use. So if you, for example, want to use OpenAI, you would use something like OpenAI GPT 6 .1 Sol. And then it needs an OpenAI API key.
So that's how that works. And that's why we can already use this because we're using the classifier model. And that's already in here.
So let's see. Then we have our output type. This is also, let's see, this is the second most important one.
So we really need three things, right? We need the model. Which model are we using?
We need the instructions, which is the system prompt that we're using in this case. And then we have the output type. This is arguably the most important thing because this is where PyIdentic AI really shines because we have that native integration.
with the Pydentic library, meaning that we can set the output type to our classification data model. And remember, what is that? If we go in here, this is our data model.
We have a section, which is a literal. We have our language, which in this case is just a string. needs human is a boolean, yes or true or false.
We have a reason, which is a string, and we've been acknowledgement, which is also a string. So we now know for sure if we run our classifier, that haiku is going to give us back a pydentic model that will load exactly into this. And you'll find out why in a bit, why that is so important, because that is really the only way we can do like programmatic control flow.
So a lot of stuff happening. So let's see. We have our classifier.
Now we're also going to create the next step, which is our agent, which is the one that's actually going to handle the reply and the loop and decide what to do. So the first step is just classification. So let me come back over here.
AI, new file. We're going to create our agent .py and I'm going to plug this in. So there's a little bit more code in here, but the setup is the same.
You can see we create, again, we import our agent. We have our instructions. You can see you're our customer support agent for Harbor and Pine.
These are the steps that you need to follow. And now we're also going to allow this agent to use tools. So we're not only going to give it a model instructions and the output, but we're also going to give it tools.
So first of all, you can see over here beyond just the agent that is set up over here. We also use Pydentics AI notation to say this is our support agent, which is agent model. Remember, Cloud Sonnet 5 .5 in this case.
We set output type to agent reply, which is the data model that we specified over here. Action reply reasoning enough information promises an action and an issue. And then we do an instructions, which is this system prompt.
And then through the decorator pattern in Pydentic AI, we can use the add symbol. We do add support agent and we do dot plain tool and we can add tools. So what the agent can do is it can list sections, meaning it can do a db .listsections, meaning it can look into our knowledge base, into our database, and it can list everything that's in here.
So it knows like brand and tone, pedal boards, returns and warranty, shelving. And the way you should look at this is through this example, again, like coming back, let's see. coming back over here through this example, you might be wondering like, why not just do it all at once, right?
And for a project at this scale, you could, you could just take one LLM, take a powerful model like Sonnet and just dump everything into the system prompt and it would probably work. But that's not how you build real applications in the real world. Because first of all, you have no idea to track back, like why did an...
Did the agent make a certain decision? Also, it will be very token inefficient because you're always showcasing everything. And it's pretty much a recipe for disaster because as the project gets bigger, the brand gets bigger, more customers, more products, more issues, the whole system will fall apart.
And that's where the agent will start to hallucinate and make mistakes because everything is stuffed into the same context window. That's why we want to really break it up and say, look, we first want to classify. And in there, we already can decide, do we need to escalate it to a human?
And then our second agent will actually build upon the information that the first agent already classified. So it knows, oh, this is what we're dealing with. And now here's how to handle it.
And now you can branch off in. almost infinite ways and infinite branches based on how complex your project gets. So right now we keep it relatively simple, but you could even have entire different and dedicated pipelines for just questions about pedal boards and about the shelves.
So following through on this, you could say, look, if there's a classification, if it's about pedal boards, we go to the pedal board agent. If it's about shelves, we go to the shelves agent. That's how you branch off and make the most reliable applications.
So whenever you're working on something like this and you're running into issues, the client is unhappy, it's making mistakes. Usually the answer is not a better model. It's branching off.
Okay, so a little bit of AI engineering best practices in there. So let's see, we created our classifier. We have our agent.
Now we are going to write our replacement rules. So this can be really tricky for a support team because depending on a type of issue that a customer is experiencing, the company might offer like different ways to like replace certain parts, give money back, or maybe we need to ship a new product, right? So we're also going to create some rules.
So let's come back to our AI folder and we're going to do rules .py. So we have some rules in here. So we're going to capture some business logic.
So you can see this is hard coded on how to resolve an issue. So you can see these are next steps. Now, this is an example to see, look, if the issue or if the issue and the product is a paddleboard and there is a missing accessory, the next step, the resolution is we're going to ship that part, right?
Because if it's a missing accessory, Like we don't really need to refund or anything. You are allowed to ship that part.
So we need something like this. So the agent can also like programmatically check what am I allowed to do and what not. Again, could you all stuff this in the system prompt?
Yes, but right now you can exactly track. what was the issue? And given that circumstance, what are the options that the agent is allowed to do?
So this is, I can't stress this enough. This is how you build the most reliable applications. And it's what a lot of people underestimate.
They put everything into the system prompt while it could be so much better by just having a couple of if statements or cases in here. So same for shelving. If there's missing hardware, we ship a hardware kit.
If there is another problem, like the wrong finish, we exchange it. Okay, so let's continue in this. This is definitely like the biggest part in terms of like code files that you could potentially go through.
But in order to really understand this, first, we really just need to put everything together and then just run a couple of examples. And that's where really things will come together because I fully understand that right now, things can still be a little abstract. All right, and then we're going to add the decide node in here.
So that's going to be another script, Python decide, and then let's see. new file, decide .py. So what do we do in here?
The pretty much the first part, scrolling up here again, the first part of this is really decide and gathering metadata. That's pretty much all it is about. Gathering metadata, classifying, deciding whether to escalate.
The other agent can also still decide to escalate. And if not, it will write a message. Now we don't give direct control to our agent to send that message.
We still want to programmatically let that run that through a script that based on our structured data objects that we have identified in Python can still make some checks. So we have another layer of control in there. Again, just one of those things that really makes your applications more reliable at scale.
So let's see what is in here. Coming back to our decide function, you can see We have, first of all, our classification thread.
There is the escalation function in here. And here, for example, you can see this is something that we, for example, I actually modeled this from one of our projects that we worked on. Our agent cannot handle attachments, right?
So let's say someone attaches a photo or whatever. What we currently set up is we automatically escalate it if it has an attachment because we haven't built the attachment analysis functionality. uh right now so that still requires a human to then look at the picture and to like really see okay what what is this going on what is this about right now in our classification pipeline and then our classification you can see needs human so this was our our field true when an always escalate rule applies now when is that uh where is that rule right that rule was in the system prompt over here so you can see needs human set that to true when the customer is angry, ask for a refund, ask for the personal manager, ask about the status.
So whenever a customer question is related to any of these issues or cases over here, the agent will decide that it sets needs human to true. So this will then be true. So then look into our decide .py.
Now it will check needs classification. If that is true, we run our escalation pipeline. Are you still with me?
I know this is getting pretty deep, but this is how we programmatically set things up and still can have like a full hard stop in here. Even if the classification or even if the like the agent thought we could still reply, if the classification agent already said, like, we just need to escalate this, you know, it will not happen.
Same goes for all the other cases in here. So if the answer .action is escalate, we escalate. If it doesn't have enough information, It escalates.
So it's all these different steps in here. Another check, another series of guardrails really is what you would call this that we implement. And when you set something up like this, really this like this decide function, like this is what you would call the guardrail.
Because of this, this allows you to also go live with a client quite quickly because you can just decide like, look, we only do this right now. You could literally start with just one question. Only if this question comes in.
We reply with this agent and this prompt, or maybe it's like a default method. And in all other scenarios, we escalate it to a human. So this is like, we've done probably like six or so of these like customer, full customer care automation project for clients.
And this was the process that we used in order to go live in two or three weeks and actually start. onboarding the AI agent and working together with the human agents. So they would get confidence that, okay, everything is as normal.
Everything is escalated to a human. And only these particular tickets over here, that is what we handle with AI. All right.
So now scrolling all the way down, we have the rules. We have the decision in here. Now we need to connect this to the pipeline.
So what we're going to do is we're going to replace app .pipeline .py. And we're going to put all of this in here. So again, we can just copy paste this.
You can see this script is now getting longer. So coming back to our, we already have that. That's our pipeline.
So simply replace everything. So what do we have in here right now? We first of all have all of our Gmail labels.
We have more labels that we create. We have our max attempts in here and we have our process. So you can see this is now our process function.
where beyond the initial step that we had over there we now also let's actually see where we handle that we save it get thread and just need to check where we actually call the function because here we have to decide And then, yeah, this is the flow of how it goes. So like, this is also how you can follow the code base, right?
To see, okay, what is going on? So we know how to get in the process function because we showed this in our original examples, right? So this is all the same.
And then when we run decide, this is where we now kick off our new pipeline. So if we go into decide, that is where we start the classification, right? So we first run our classify thread, which is our agent or classification agent.
Okay, so then we run that. So then we go through all of these checks. If it has an attachment, if it leads to human, and then if it passes these two, we do write reply.
So in the write reply, that's now where we kick off our agent .py. And remember, this is the like the actual agent with the logic that can search the knowledge base that can go and retrieve certain parts of that and you kind of like loop through it. and understand how it needs to reply based on the instructions.
So that will then give the output back. That will land back into the answer. Then we do have one more round of guardrails because even though classification agents say, this is fine, we can reply.
It could also be that the agent that actually replies thought, no, I still cannot do this. I don't have enough information. I need to escalate.
Don't have enough information. Or the answer, the types of issues is in the list of customer steps that need to escalate. So again, these are all of these things.
Also another one, promises in action. This is also really like from the field. We, for example, found that during the initial launch of some of our agents, a customer would, for example, have a question.
like a product question and then it would also ask something else like can you also do that and then sometimes an agent would say it would reply and it would also say yeah i will also check with our like support team internally whether we can handle this or it would say yes i will also issue the refund for you you know like and this is all stuff that you can do with prompting but We found it's such a hard limitation that the AI agent should never promise actions it cannot physically do.
That we have a dedicated field in our agent, in our data model. Let's see, where are we? Let's come back to our schema.
In our data model, promises an action. True when the reply promises a refund, shipment, replacement, date, or a call. You know, this is like also like, for example, a call.
Like if a customer asks like, oh yeah, I got something with my shelves, blah, blah, blah. Can I also talk to someone? The agent might be like, okay, I can respond because this is a question about the pedal boards and I'm allowed to answer that.
So I will do so. And then it will also say, yeah, like someone from our team will call you back. You know, like these are like the weird types of hallucinations that even some of the more powerful models can still do.
And it's very hard to prompt against this because you never truly know what the customer is going to ask. Like customers are weird and unpredictable. So that's why you want something like this in here.
So it will generate a reply and it will also do another round of like self -reflection to say, did I actually promise an action? Okay, so. I know this is getting pretty deep, but this is also probably like one of the most valuable parts of this whole process.
This is really where we get deep into AI engineering. Okay, so coming all the way to the end. Now, how can we check this?
What we now can do is we can bring this all together and let's see, I'm going to open up a new terminal in here and we're going to start our puller again. so let's see i don't have the script anymore let's see puller let's run that again in here make sure we're in the root okay we start the puller over here so now what we're going to do let's see going back to our ai pipeline scrolling all the way to the bottom we have a couple of questions so we're going to say which paddleboard should i get i weigh 90 kilograms so let's open this and we're going to create a new email and we're just going to let's see where is that email address that I stored there we go oh shouldn't go there should go there I'm just going to do a question and then I ask which paddleboard should I get I weigh 90 kilograms so Let's send this and now wait for our puller to kick into action.
So let's see. This should now all be good. We have our events table.
Okay. And there you can see we now get a request two times. So you can see we had two.
Let's see, make this bigger for you. There we go. So you can now see the application logs appearing.
So we can see two calls to Entropic. First, the classifier and second, our agent. Then you can see the tool calls.
So we got the brand tone of voice, the escalation rules, and then it understood that it should get the pedal boards. And then you can see it action and it replied. So now if I come back in here, there we go.
Hi, Dave. There we go. At 90 kilograms, the 11 inch, is that inch?
I'm European. I don't know. I don't speak those kinds of things.
All round is the board for you. It is rated. Well, OK, I'm not going to read the full thing.
You get it. We get a message. We get a reply.
OK, so this is really freaking cool, right? So this is now the loop. And just getting that message here is now quite simple.
But you can see there's actually really a lot going on behind the scenes, right? In a bit, I will show you a little bit more in the next section about like the actual data models and the different cases that we can go through and even show you how you can set up some evaluations around this. But you should now know that it went through that entire process of first classifying, creating that data model, and it decided that it could answer this question and it replied based on the information that is in our knowledge base.
And now, of course, everything is... persisted we got the events we now should have a new ticket so you can see we got the question this is now a new ticket and that should also have two let's see ticket uh which is the ticket id so that is id number six and that should now have let's see what we have in here i should look at ticket id that now has two messages in there first the message from the customer in this case, which is this account, and then the reply.
So this is, you can see all the messages back and forth are stored at the ticket ID. Okay, so now you can go through this and also test a couple of more if you want to. You can also set this up programmatically in your code base.
Let's actually show you what that looks like. So what I'm going to do is I'm going to take this one. And I'm going to show you how we can create a little bit of a faster loop to also check what answers we get if we run this locally.
So one of my favorite ways of doing this, which it's not in the guide. So this is a little bit of extra that I'm going to share here. Let's see.
I'm going to open up a new agent in here and I'm going to point it towards this guide. And here's what I'm going to say. Can you set up a...
playground folder in the root of this project where I can test the data flow so make sure you set up the imports correctly make sure to also set up the path so that I can run them using Jupyter Interactive without the import errors and what I want is I want to be able to have a Python file where I can put in a question and then take for the entire AI processing pipeline without actually sending the emails.
I just wanna know, here is the question that I input and then what data models do I get back at the end? Can you set that up for me? So that is then the prompt that I would set up.
And here again, you can see Glido just perfect handling Jupyter, Python, even putting the quotation marks in here around the questions and of course being extremely fast. This is the first question that I wanted to try. I want to show you this kind of like trick as well because this is super helpful during development because otherwise you're constantly...
like using sending emails and then debugging and then waiting for the email to appear, right? Which can be a little bit annoying. So we don't really need the whole email part just to test our AI pipeline, right?
So we can also just like directly send it over to Entropic and just run this part of our code base, just the whole pipeline that is in here. So that is now going to set that up. So let's wait for that to finish and then we will continue.
Usually I always add this to my projects to make sure I understand the data models and I can have a little bit of a better insight into what's happening. So because we're running the playground outside the app, we again need to apply some Python black magic in order to resolve the pods. And you'll also see that we use nest asyncio and apply in here, which is just this kind of like annoying thing that we need in order to run asynchronous.
processes in Jupyter Interactive like the Pydentic AI agent loop. So don't want to get into how all of that works right now, but pretty much all you need to know is that with this and Nest iSyncio, by the way, is now also added as a dev dependency in here. So I will add that to the project as well when you go through this.
So no need to worry about this. So I can now run this. And here's pretty much what I wanted to show you, right?
So now we have a question. So my board loses air overnight. You see, I can now run this and we can take that question through our entire pipeline.
So it will actually go through classification, then through the agent, and then we'll get the output data model without actually sending email. And so what I can now do in here, if I look at the decision, that decision is now our decision schema, right? Remember?
Again, this is just a repetition that you need in order to understand everything that's going on. This is our decision model. So that is action, section, reply, reason, and proposed action.
So we can scroll through that over here, but that's a little bit hard to read. So I can also do a model dump JSON on this. So we get an actual JSON object in here.
And now you can see the final decision. So the agent decided to reply. Section is paddle boards.
Here's the reply. So it says, hello, losing, blah, blah, blah, blah. So that's the whole, and then also the reason.
So this is for internal use. So it also decided why it gave that answer. So this is super helpful to debug.
So because what we can do right now, if I now come back to, let's see our AI pipeline, scroll all the way to the bottom, you know, we had all of these questions. So for example, this question, there should be an acknowledgement and the label should be needs human. because this is apparently something that requires human attention.
So I can now simply go in here and run this and just update the question. You see, I'm just updating the question over here and I can run this again through our pipeline. And this is really how we can create that debug and optimization loop, which we'll take a step further in the next section when we're going to create the evals.
So again, this takes a little bit of time because we need two API calls to Entropic. And you can see right now escalating because this is returns and warranty. Why?
Because this is the next step is shipping panels. And remember our rules. See, where is it?
Boards should be somewhere in here. Should probably say, what is it? Ship panels.
There you go. If this is the case, we should escalate. So that's now the rule in there.
Okay. Now you can go through this for all of the examples in here, but I think you get the idea, right? So that was already a little bit of an introduction towards evals because we now have a simple loop.
We can send the message and based on a user query, we'll send the message. But how do we know that our pipeline is any good? And more importantly, how do we improve it over time?
That's where we get to evals. Now, again, this is another one of those topics where we could do an entire course on just evals, but here we'll get into the foundation. So what we're going to do is we're going to set up a series of checks where we know if a user asks this, we expect this output.
And let's see. We're just going to go through this together. So just to give you an idea of how to set something up like this.
So we're going to copy the script over here, golden emails. And we call them golden because this is essentially going to become our golden data set. So new folder, we call it evals.
And let's see, what was it? Golden, yeah, golden emails. I literally just said that, goldenemails .py.
And let's paste this in. What you can see right now is you can see we have a name. So this is just like a tag to give it internally.
We have the email itself. So this is from Tom and Tom asks which board. So this would be the subject.
And then hi, I weigh about 90 kilograms, blah, blah, blah. And then here you can see the section should be. pedal boards so this means like it this is the category that the agents should start looking into and the action should be reply so you can see we have many examples here pedal boards reply pedal boards escalate reply reply escalate you know so you can go on and on and on and add more and more examples to this to really make sure whenever you make changes to the prompt and you run all of these, you know that they should all still pass.
And we can actually create unit tests around this because we're using structured output. So we can actually test against if we put in this is section pedal boards and is action escalate. So this is really where we're going to bring all of that together.
Scroll down and we're going to create our eval runner. So run underscore evals .py. Put that in here.
So how is this set up? We're using the Pydentic E -files library that we can use for this. Again, I'm not going to go into the specifics of all of this, but the whole idea is we create an evaluator, we create our data set based on our emails, we create our cases, and then we can loop over that.
So you can see data set, evaluate sync, run our pipeline, and then we can also do the concurrency. So how much do you want to run at the same time? Coming back to this, we can now run this.
We now pretty much need to check, like, are all of the cases correctly set up? Do we get a full pass on everything? And if not, we can adjust the prompts.
And now the cool thing, the beauty of this is, if you create a loop like this in your project, you can also use AI to drive this. So you could literally use a more powerful model, like, for example, Opus 5 .5, and take actionable... actual production data so let's say you have like already hundreds of tickets that have been processed you create a data set around that and you can optimize the prompt around this super fun to play around with so what we are now going to do is we're going to run everything and also like as you follow through with this make sure that like model outputs can vary so of course you know llms are not fully deterministic so we now have our runner our evals runner we have to set up i'm going to open up a new terminal i'm going to run uv run python eval so let's see what we're doing right now so now we're going to run the evaluation pipeline so we do four concurrents so meaning we take four cases at the same time that we send in parallel to entropic it will go through classifier
If it doesn't pass, if it escalates, it stops. If it doesn't escalate, it goes to the agent, then runs that again. So you can see it now goes through and then it will wait a couple more times.
And let's see. Should take another, boom, there we go. So we got two errors on there.
But first of all, you can see that the board size, we got the output and we got two assertions on there. So this was the case that I shared, right? On this, we wanted to see two things.
We wanted to know that the category was panel boards and the reply should be reply. So you can see we have both of those assertions are checked. And now we can see all of them pretty much hold, but here is an error.
So we can see on this one. We can step into that. We can dig into that.
So here there was an error. So that is something we should adjust and see why this was wrong. And then let's see the case failures, connection error.
This might just be something related to, let's see, to the API where we may even need to like dial it down a little bit further. Dial it down. I mean, max concurrency.
We do max concurrency four. So it could be that it couldn't connect because what I'm going to do is I'm just going to run it one more time right now, because this is a process that we want to do often just to see if this still happens on those cases and also see if we maybe fix this one. And otherwise we need to do a little bit of optimization, which is the whole purpose of the evals.
So here you can see like fix a prompt and running it again. So you can open a failing case in the report and read the reason in its output. It tells you which rule the model followed and then change one thing, the classifier instructions, the agent instructions, or a knowledge -based entry and run the whole set again.
Like this is the loop that you want to follow. All right, so that is ultimately what we want to get to to make sure all of the checks pass all the time. All right, so I ran it one more time and you can see still occasionally we get like another error message.
But again, this is just mostly a model connection issue. So we may need to fix some timing in there. But then this wrong finish.
This is where we most of the time get a wrong answer because let's see, the action is escalate and the section is returns and warranty. So let's check what it says in our golden data set. So let's come to our knowledge base, sorry, to our evals and then our golden emails.
And then let's say where we have wrong finish. The section should be shelving. Let's see.
And it says section returns and warranty. So this is indeed where the AI might make a mistake where it says I'm going to look into returns and warranty, but it actually needs to look in a different section or a different category first. So it correctly identified that it should escalate.
But now what I want to do is now we can essentially create a loop over here. where what we can do is we can specify our agent to work on this loop and work with the runner evals. So I can even like just paste that in here and I can say the following.
All right, we have a basic setup for an evaluation script, but I noticed that sometimes when I run it, we don't get a perfect 100 % score all the time. And also sometimes we get a model connection error. Can you do two things?
First of all, check when the model connection error happens, why that is happening, and then maybe see if we need to handle the loop a little bit more gracefully around the Entropic API. And can you also adjust the prompting very minimal in such a way that we always get like a perfect score on the cases that we have over here?
This is important. Without overfitting on the exact examples, but rather diagnosing why the agent gets it wrong okay so i'm now going to kick off this agent again this is probably something we also could have accomplished by using our own human brain but hey why do that if an agent can do this so one thing i want you to pay special attention to i also mentioned it in the prompt right one of the tricky things that you should be aware of is pointing your agent at your data set your e -files and then say like make sure it passes like 100 even though I kind of like did that, but you should always say, like, don't give specific examples because otherwise the models will get lazy and you'll do something which is known as overfitting, which is a term that's coming from machine learning where you actually train custom AI models and you overfit them on the, like the testing data set to optimize your score.
So what that would mean in this case, the AI agent could... could do something like this it could literally say if someone asks about like a walnut a walnut model on like the paddle boards the section should always be shelving instead of this so meaning it takes the exact literal example and it puts it into the system prompt so it's very easy for then the model to get it correct the next time because it's the exact sample example you always want to make sure that the rules generalize.
So you want to find the underlying problem of why it decided to give a wrong section. And then ideally without mentioning anything from this ticket itself. Now, this is now running through this and it will probably recommend some changes.
So what I'm going to do is I'm just going to do a checkpoint in here and commit everything. So we can also keep an eye on what this is doing. So whenever it makes changes to our prompts, because this is now really the part where we do want to keep track of what our agent is doing because we're going beyond what is in the guide.
So that's why I want to see this. So let's run that. All right.
So our model is now done over here. And it says, look, now we have a 100 % score. And we can now see the changes that it made.
So first of all, if we look into the e -file runner. So this is great because this is outside of our application code, meaning I just adjusted the runner itself to check for... transient model errors and you can see it applies a delay so whenever it gets an error it just retries again so this is this is good this will catch the first error that we have and let's see i will keep all of that for now and then let's see what it did in the classifier so you can see it made a minimal adjustment to the prompts because the thing is it labeled it as returns and warranty right so that was where it went wrong and then it gave a little bit more explanation on okay so how a return a refund and warranty works instead of this and then it added this part a problem with a pedal board or sheriff belongs to that product section so that's really that's pretty much where we went wrong in the classification part so this is just an example of how you can create that like self -correcting loop right but i want to make sure that
This doesn't become over specific on the example that we had in our data set, but this is fine. This is like a general rule that we want to follow. So if I now come back to our terminal and let's see, I'm going to run our evals again.
What I now expect is first of all, no model errors anymore. You can see it's retrying because there was a connection error and then it's going to continue. And then I expect a 100 % score.
as well as all evaluation cases that ran. And there we go. Okay, interesting case.
We still have an error in here. So what I'm now going to say, I just ran the evaluations one more time and now we have the following error. Can you please also check that and know that the outputs can be a little bit different per model run.
So you may need to run it two times in order to be sure. All right. And with one more round of improvements and some minor adjustments to the prompt, you can see that we're now at 100%.
So that is good enough for now. And again, this is just like a shortcut, a speed run of how you can apply evaluations and optimizing your system. This is a whole process, heck, even a whole role inside an organization on its own.
But now you at least know. like the fundamentals and the gist of it. And also why it's important to build a very structured system so you can actually test this.
Because we can only run these evaluations because we have set it up in such a way. And you see how tricky it can already get on even this tiny little data set, right? Just two couple of runs, different answers, no idea why.
Now imagine scaling that up a thousand times. So that wraps up. the AI section so now we get into probably one of the most exciting parts that is the server setup and I highly highly recommend for you to follow along with this as well because the skills that you will learn in this section are really going to take you from I can just run demos and I can follow general like YouTube tutorials and videos to I actually know how to take this code and put it onto a production surfer.
So that's what we're going to dive into right now. So first step, we're going to create an SSH key. So an SSH key is a secure way of being able to connect with the surfer that we're going to create in a bit.
So just follow along with me. I will take you through this step by step, even if you have never done something like this. Depending on whether you're on macOS and Linux, let's copy the command.
Let's open up a new terminal and let's run the following command. And let's see, then it will ask for a passphrase. You can just leave that empty and I hit enter again and again.
And now we will have our SSH key in here. What I will now do is I will now copy that. So you, it is also printed over here, but what I can do is I can run the PB copy and then we'll point to that.
ssh key that we just created over here so i will do that right now and now it's copied to my clipboard so you can see i can now paste that So this is now on my clipboard. All right, so now let's actually set up our VPS, our virtual private server.
And we're going to use Hostinger for this. So you can go to hostinger .com forward slash DaveVPS or click on this URL or the link in the description. So if you don't have an account already, simply follow the instructions on the website, log into the portal, and then we're going to come over to VPS over here.
And then we're going to click on... get vps so we're going to do a kvm vps we'll click on this and then we're going to go through the walkthrough here together so first of all you can decide where you want to host your surfer now i recommend you setting or picking a location that is closest to you i'm going to go with the netherlands click on next Now in here, the search that we want to do is we want to set up a server with Docker already installed.
So this saves us a little bit of setup time on the server itself. And now what we're going to do is we can do two things. First of all, we can generate a root password for the actual Ubuntu user account on the server.
So we can hit generate on there. And then I'm simply going to... Take this right now and make sure you store this password somewhere so you can come back to it later.
And then now we're also going to add our SSH key. So I'm going to add my key. And then what I'm going to do is I'm going to simply add that key in here that I just copied, right?
So remember, I ran the pbcopy command of the SSH key. And that is what we need to set up in here. I'm just going to reuse that same name.
So I'm going to call it Hostinger Support. Again, it doesn't really matter which name you're using, but this is just a way to internally save that. So if this is the first time you're setting something up like this, there are just a couple of steps that we always need to do with this in order to securely connect to our server.
So make sure to just follow along and then it will get more clear as we go through this. You can skip the malware scanner and the daily backups for now. Let's hit continue.
So we can now check which one we want to choose, right? So this is where we decide how big our VPS is. So this is the surfer.
I would recommend at least setting up the KVM too. So I'll go with this one in here because the thing is with this Black Friday deal and discount that we got going on right now, you can lock in one of those surfers for like two years or 12 months. And the beauty of this is it's your surfer.
So you can do whatever you want with it, wipe it you can install another project so you cannot it's not only for this project that is very important to understand and so with this hosting our black friday deal that is live right now until the first week of december you can get up to 67 discount on the vps kvm to plant and then you can use discount code dave vps to get another 10 % discount on top of that.
And on top of that crazy deal during the campaign with every purchase, you also get a free spin at their wheel of fortune where first of all, everyone wins a prize and it can range from product credits all the way to a rare 99 % off jackpot. So there's literally no better platform or place out there where you can at a cheaper price, learn how to create virtual private servers and to how to manage software professionally.
I would really recommend to follow through on this and get that deal to follow along with this setup, all right? And then once the payment comes through, we can get into the setup of our VPS. So the first time you're doing this, it can take a couple of minutes for this to set up.
All right, and now that the surfer is set up, we can continue with our setup guide, right? So we now have the VPS and we've set up our surfer. Now, the next step that we're going to do, which is very important, is we're going to protect our server.
So we're going to set up a quick firewall rule to allow pretty much only access from our own IP address. So what I'm going to do right now is I'm going to take this curl command and again, check for Windows and macOS or Linux. I'm going to open up a new terminal and I'm going to do a quick ping to see what my IP address is.
Now I'm going to copy this. So this is going to be your IP address. And remember, like depending on whether you use a VPS or your internet provider, this can be dynamic.
So it can happen that tomorrow you have a different IP address. That is just something you need to be aware of. For real production environments, I always recommend getting a service where you can get a fixed IP address via a VPN, for example.
So at Data Lumina, we use Nord Layer for that. So grab your... ip address and then what we're going to do is we're going to do the following so on the setup over here we're going to click on manage vps and we're going to go to our hostinger panel and in our vps what we are now going to do is we'll go into security and we're going to firewall and what we're going to do in here i'm going to add a firewall and we can give that a name and you can for example do ssh my ip create that.
And then in here, let's see, we're going to edit the rules. And let's see if we scroll down in here, we're going to put in the following fields. So we do our protocol, we do TCP, then the port is 22.
So that's the range, 22 over TCP is the port that we're going to use to connect via SSH. And then the source is going to be custom. And then we're going to put our IP address in here.
So we'll plug in that and we do slash 32 in here. So this is what we set up right now. And then we click on add rule.
And then let's see, we can have that set up. And this pretty much means we're going to drop by default, we're going to drop everything. And we're only going to accept incoming traffic via TCP over port.
22 with my specific IP address in this case. So if we now come back, now we need to enable that rule. So we're going to activate this firewall rule on our particular VPS.
So now this pretty much means we first of all have our VPS protected with our SSH key, which is already a secret key. But now we also have that firewall rule on top of that, which essentially makes it... two factor authentication.
So only someone from your IP address with your SSH key can go into your server. So this is a very secure way to protect your applications. Now, the next thing that we're going to do is we're going to log in and we're going to access our VPS.
And we're going to do this via our terminal. So first we can do this via the Hostinger web console. So if we click on web console, a new window will open where we can log in into our server.
So the login, first we're gonna do root and then our password is going to be the password that we stored and saved during the setter process. So make sure you plug that in and that will now give us access to our server. So we are now logged in.
we're logged in as a root user using our password. So remember that password was during the setup of the hosting or VPS, which I said to you like that you should copy, all right? So make sure you still have that.
All right, so now we are logged in. And now what we're going to do is we're going to print our server's fingerprint. So we're going to run the following command in here and we're going to do SSH keygen.
And we're going to take the following key over here. And now what we're going to do is we're going to connect from our own laptop. So instead of using the web portal, we're going to connect via our own terminal.
And now why we want to print that is just as kind of like a safety precaution to make sure that when we connect with our local laptop via the terminal, we can check the fingerprint to make sure we're actually getting into our server. with the exact fingerprint. So now we can open up a terminal and copy the following command over here.
And now what we need to do is you see, we need to put that IP address in here, but this is not your own IP. Now we need to get the server's IP. So for this, we can come back to our server in the Hostinger panel and we copy our IP version four address.
And then we plug that in here. So what are we doing over here? we ssh we use our ssh key and then we're going to get we're going to log in as a root user into this server so this is just one of those commands that you need to then bookmark and shortcut so that we can easily get into this you can see the fingerprint so you can make sure that matches so and in in fc so that is good for me and then i'm going to say yes All right, so this is only something you have to do the first time.
So this is a little warning just to make sure like, is this actually a surfer that you want to get into? And now we also don't really need the Hostinger panel anymore. So what I'm going to do now is I'm going to pull this to the side.
So now, if this is the first time you're doing something like this, this can be quite abstract. But the whole process around what we did right now is we rented a surfer from Hostinger. And this server, for me at least, is sitting in the Netherlands.
So this is right now an Ubuntu server somewhere running in a data center that's dedicated for me, where I have now set up Ubuntu. Docker is installed in there. And I've set up a secure way for me to enter into that server.
And I can now, via the terminal, run commands on here. So we can now start to set up our server. The interesting thing about this is there's no GUI, right?
There's no desktop. So we need to work via the terminal over here. But don't worry, we just have to run a couple of commands and that's really all we need to get started for now.
So first of all, we already installed Docker, but I'm just going to run the following commands to make sure that we have the latest version of Docker. So we're just going to update Docker, check the version and get everything. So that is the first thing that we need to do.
Now we'll run through that. And then once that's finished, I will already continue with the next part in here. All right.
And now, so this is finished. So now we're going to create a deploy user. So this is optional, but it is kind of like a best practice in order to create a separate user beyond root with specific permissions in here.
Although it's going to be quite similar to giving root access. So I'm going to copy these commands. So add user deploy.
Here are the settings. Here's what we're going to install. And I'm going to run that.
On here, paste it. Now that will run. Now I'm going to create a password for this.
Now for the sake of demonstration, I'm just going to use the same password that I used for my root user. Again, this is not a best practice, but just to show you how this works. This could be another entire section on working with Ubuntu Linux, you know.
I also myself, I only know the basics. I know the foundation. I know just enough to set up users to deploy a solution.
And that's pretty much also all you need to know for now. You can go way deeper into this. All right, so we have now created the deploy user.
Now the next step here is optional. Again, you can save a shortcut in your ssh .config. And what this allows you to do is you can set up the following settings in here.
So you don't always have to like fully plug in this command, but you can just type support VPS and then you SSH into it. I'll let that up to you.
You can ask your agent how to set up that config. It's optional. But what I'm going to do right now, just to show you how that works, I'm going to run this command over here.
And now instead of root, I'm going to log in as a deploy user. And then what I'm going to do is I'm going to plug in that surfer. ip address here one more time now this is then a command that you want to copy right so if i go in here we need the password let's see that was this one okay so there we are so now you can see that i you can just also save this command somewhere safe and that way you don't have to put in the uh the shortcut so now you can for example run who am i You can see we are now the deploy user.
So now we have a little bit less permissions. Now, step number nine is also something that's optional. I'm not gonna do it right now.
This is setting extra permissions to basically disable login in via SSH as the root user. But the thing is our server is already really as safe as you want it to be at this point because we have the firewall rule. So only someone using our SSH key and our IP address can go into the server.
And for most, even production scenarios, that is good enough. So if you want to learn more about how to do this, you can look into it. But again, this is not like a full tutorial on Ubuntu and managing servers.
So with that, we have come to the end of this chapter and we can go to the deployment phase. So this was again, now all set up and tinkering, but now what can we do with this? How can we actually run our application?
onto the server so that we don't have to run our scripts locally, but it runs in the background while we sleep. So that's how we are now going to deploy this using Docker. So what we're going to do is, first of all, I'm going to create and set up a repository for this already, because up until this point, I've just worked locally.
So all the commits are locally. So I'm going to publish this branch. And I'm going to put it to a private repository.
Dave Abelard, AI customer support, private. Perfect. Okay.
Now, what we're going to do next is we're going to prepare our application to run on the server. And up until this point, of course, we've worked locally. Now, I work on a Mac.
You might do this on Windows. So for this, we now need to make sure that it also works on our server, which runs on Ubuntu, on Linux. Well, that's where Docker can play a role.
All right, so let's take this step by step and first set up our Docker file. So what we're going to do, we're going back to our editor once more, and I'm just going to create a Docker file in here and we're going to paste this in. So we can quickly check what's going on in here, but we have Python version 3 .13 on Ubuntu.
We have the configuration to work with UV. So we get UV in there. We specify the app folder and also how to install our dependencies.
So this is what is going to be installed on the server. And then here you can see the actual commands that we use to start up our application. So UVGORN app and we run under port 8080.
So that is, again, Docker on its own could be a whole another course. and different rabbit hole to get into but this is all you need to know for now to follow along then we're also going to create a docker ignore file so we do the dot docker ignore and we're going to put the following commands in there and now we need a docker compose file so again a couple of files that we need to set up docker compose dot yaml and then plug that in all right So that is now set up as well.
And this essentially instructs our puller to keep running. All right, now next, we need to set up our deploy key because what this essentially allows us to do, it gives the server read access to this one repository and nothing else. So that is another safety mechanism that we can put in there, right?
We could hypothetically go onto the server and authenticate with our GitHub account, but that would mean that it could grab everything. In the case of an attacker getting root access to your server, like your whole GitHub is exposed. So we don't want that.
So we just want to have access via a secret key that we can set up via GitHub to just this repository. Okay, so make sure that after you add all of those Docker files, you also push all of that to the master or the main file. So I'm going to push that.
And then let's continue with the instructions. What we're now going to do, we're going to add a deploy key to our repository. So let me show you how this works.
Now, this is important. We need to run this command, but we need to run it on the server. And now what I'm going to do is I'm going to run the following command.
So that's why this is also like the same for everyone. There's no macOS or Windows for this. because we run this on Ubuntu.
And then after you run that, hit enter one more time to run this final cat command, because this is the actual key that we need. The first one just creates it and this prints it into the right format. What we then need to do is we now need to set this up as a deploy key in GitHub.
So how that works is on our repository, we go to settings, we go to deploy keys, then we add a deploy key, we plug this in, And we can just call this support VPS. And now we can leave allow write access off because we only need to pull from this repository on the server and we add the key.
So this is now created. GitHub will also send you an email with this. So don't be alarmed.
This is a good thing. It will say, look, someone added a key, right? And then the next thing that we need to do, make sure you're in the home directory and we need to clone our repository.
And now here's the thing. You need to go to your own private GitHub repository, go to code, and then this is important. Make sure to grab the SSH one.
So not HTTPS, do SSH, because this is what we've set up. So we copy this one. Now we come back over to our server and now we can do a git clone and we can grab our code.
So if this is the first time you're doing this, type a yes. So this is now whitelisted. And now we have our AI customer support code in here.
So this is a huge step if you've made it to this point. And I understand that a lot of these things can be very abstract, right? Surfers getting access, SSH, firewalls, giving SSH access with a deploy key via GitHub.
But this is such a valuable skill. And the fact that I'm sharing this with you in like a free YouTube video is actually pretty wild to like show you this end to end. So make sure that you like...
Take some time to like really understand what's going on here. Take some notes because this is one of those things where you will come back to later in your career because this is not something you have to do a lot. But whenever you have to do it, it's really great to have like a guide to fall back on.
So now if we change directory into the AI customer support folder, we can see that we now have our repository in here where the whole goal is to work locally, then make the changes, we push them and there on the server, we can pull that code again. So our server has the production code. Now, the next thing that we need to do is set up our environment variables, because as you know, when we are working locally, we have excluded our secrets from version control.
So what we want to do is the following. So I'll do this step by step.
So make sure on the server, you're in your AI customer support repository. Then we're going to run a command to copy the env .example and create the .env file. And if I now run a cat on this, you can see that this is the default setup, right?
So this is the example because we haven't changed it. So now we can also set the permissions. So this makes the file readable only by deploy.
So a little bit of extra precaution in there. And then the last step that we need to do is we need to edit the file and we can do that with nano. So we can do nano .env on the server.
And now we get into this editor. And in here, you need to be aware of the commands that you need to use for this. So I can first of all do command K or control, I should say control K to get rid of everything.
And now what I want to do. is I'm going to grab all of my secrets, come back over here, and I'm simply going to paste this in. And now what we can do is we can set our pull interval to, let's set it to 600 or really any value that you really want, because this is going to be the pulling interval of how frequent the server checks the Gmail server again.
So for the sake of demonstration, I'm still going to leave it to 30 for now, just so we can go through this a little bit faster once we set it live. But here is how you can have different settings, for example, on your development server, where on your system where you're working versus what you want in production, where every 10 minutes, for example, would be totally fine to check the new emails.
Now, important thing in order to save this, you first want to do control O in this case, and then control X. And then let's see, we'll write the file, do that and then hit enter. There we go.
And now make sure that we do a cut cat .env. So make sure all of the information is in there. So I know this can be a little bit tricky to work with sometimes.
There are also like shorter commands where you can copy it straight from your local machine to the server via SSH. Again, if you're struggling here, just ask your AI to help out. All right.
So now that we have our environment variables set up, we can actually start the server. So make sure you close any terminal that you were running locally or had open. So make sure to clear all of this up.
And then what we can do on our server, coming here one more time, make sure you're in. your project folder what we are now going to do is we're going to run docker compose up we're going to do it with a detached flag over here and then we're going to build it so let's boot this up or sorry let's build this first and if you run into any permission errors or anything that says look you cannot do this which i had just before recording this clip I noticed that I apparently missed a step.
Let's see, where is it? When we were creating the deploy user. So if you follow along exactly with all the commands that I did, it could be that you may have to go back to this setting over here, but make sure you do this as the root user because the root user can change these settings.
So if you run into any issues there, you can also ask your coaching agent to do a little bit of debugging. So that is what I had to do as well. You know, the thing is, these are one of these things, usually like one -time setups, and then you set it, forget it.
This is also really the trade -off that you're getting from using managed services, right? So if you've watched some of my other guides, for example, I've done a lot of builds here on YouTube where we deploy via railway or via render, but... For example, last week, there was this whole security incident on railway.
So I am generally really not a big fan of using all these managed services that make it really easy to like one click deploy, right? But at what cost? You are now sharing your data with a third party.
You're usually paying literally 10 times more than you would if you would go directly to a VPS like this and all the big cloud platforms like Azure. AWS, GCP, they also have these like Docker deployments, but again, that usually comes at 10x the price. So this is the cheapest way to do it, but that does come with a little bit of server management.
All right, so this command, the docker -compose up, will start everything up, will build everything, and this will actually start our server. So our application and our polling script is now running over here. Then once that is all finished, you can run a Docker PS to also see what is running right now.
So you can see our application is running and also our Poller is running. So what we can do right now, let's see, here's some extra information on this. We can now, first of all, check if this is actually working.
So let's come over here again and let's see, we'll do, I don't know, question. We'll do question number two and let's see what do we have in here. Let's grab one of the questions we already had.
So let's ask which pedal board should I get? So let's see. Right now, the same script.
that we were running locally is now running on our server so if we now send this and then come over here you can see that right now this is sitting here in our inbox so now we still have the polling time set to 30 seconds so it should be quite quick before we'll see some action happening here hopefully if everything goes through so what we can also do let's see we can also start watching the logs in here.
So I think, look, we can already see a message in here. So this already came in. So that should probably mean that if I go in here and I refresh this, we got our AI processed and we have the reply in here.
Let's validate that. Boom. If it's loading, this is just my email client being slow, I guess.
There we go. So. Right now, our application is running on the server, which is really freaking cool.
And you might be wondering, okay, we ran so many commands, but what is all going on right now? And we'll do one more thing and then we'll do a little bit of a recap to see what was one -time setup, just a one -time thing, and what are now the commands that we just need to run if we want to make changes or when we want to restart our Docker containers, for example, because it's very simple once the initial setup is done.
But now there's one extra thing that we're going to do, and that is we're going to add a IP restriction to our database. because we've already protected our surfer. But now that we're actually collecting data in our database, we want to do the same thing for super base.
So we also want to put an IP restriction in there. And we pretty much want to say, look, there are two IP addresses that can interact with our database. One is our own IP address.
And the other IP address is the IP address from the surfer. So let's come over to super base again, make sure you are in your project, then we go to database. And then we go to settings and then we're going to scroll down somewhere in here.
Let's see. And then we want to come over to network restrictions. We're going to add a restriction and we do IPv4.
And we're going to add two IP addresses in here. This one over here. And we're going to add one more.
And that's going to be the server IP address. So let's see. All right.
And that would be this one. So we're going to save those restrictions. So we have two ranges to add.
So you can see over here, this... adds IP addresses ranges to the list of allowed ranges. So you can see these are now allowed and the others are not.
So from now on, only these IP addresses can interact and connect with our database. But make sure this only is true for the pooler that we created. So not via...
any like apis that you would use with superbase for this project we are not using that and we haven't set that up but just so you know this is just using the session pooler and the access that we get via that So this is another extra layer of protection that we add to our project. So now you can start to run some more tests.
You can even look at the database table to see all the events are coming in, right? So we have our tickets and let's see, question two was the one I just sent. So we'll do another one to, where was it?
Dave at demo and we'll do question three. See, hi there. Just to do a quick check to see if all of this is still working, right?
Coming over here, because we now have our new IP restrictions, we want to make sure that it still ends up in the database. And testing it the other way around would also be a good check right now. So for example, turning on a VPN or temporarily...
Yeah, using another IP address or removing the one from your own laptop to really like make sure and understand that this is working. Those would all be checks that you could do right now. But what I wanted to show in this case is, let's see, coming back over here.
Yeah, so having the application logs, then we need to, of course, go into our customer support folder. And let's see, do we have a... message over here yes so you can see that right now probably do we already have a reply in here let's see if this there we go so now you can see i say hi there hello dave so this is still working and let's check the database so we can now see question three and what we pretty much got was our default reply in here so the thing is you can see the categories other it escalated But it still gives a message.
That's how we currently set it up. So this is just the default one. Pretty much escalating like or indicating like, hey, a human will come back to you later.
All right. So that almost brings us at the end of the deployment phase. But there's one more thing that I want to show you.
Because right now, what is a really good test for you to do is let's just close out your terminal. Let's just like really close this. What happens right now, your server is still running.
and the script still runs so now you need to get comfortable with getting back into it and again i just keep him here at my clipboard history right now well this is something where just usually store this in like a credential manager or para project like have these commands that you know how to quickly get into your servers right so i use one password for this so i can get in here and then again i would use my password and then once i'm in here what i can now do First of all, we can go into the AI customer support folder and I can now run a Docker PS to list what is running.
So even if I make this a little bit bigger, as you can see here, you can see this is still running. We got our fast API app and we got the polar and you can see this is already running for 17 minutes right now. This is what it means to deploy.
software in production this is what it means to run software in the real world and this is also what every other tool you use whether that's railway render azure whatever you're doing under the hood at least if you're using docker this is what's happening you create code you package it in docker and in there are instructions on how to run that on a server So this, again, like I've said, this is now regardless of whether your terminal session is open, whether this laptop that I'm recording this on is on, that doesn't matter.
This will just keep on running unless something's either wrong with the server. So like a reboot or it shuts off or something is happening inside your code that makes the Docker container crash, then this will go down. Now, if you want to close it down yourself, what you can do is you can do a Docker compose.
down so instead of up we do docker compose down so you can see now we're shutting down the services so right now this would mean that currently the application will not do anything so if i now get the message in the support folder or in the support email nothing will happen so how do we start it up again we do docker compose up dash d and then it's a good practice to just do dash dash build to also make sure Anything related to the new builds is also put in here.
So now this is now starting up again. We can run Docker PS and we're live again. Now, what happens if you want to run or pull changes, right?
So let's say I now want to go back to my code. I make some changes and I want to update something. Well, because we now have the connection with GitHub, that is all very simple.
I can just simply push that to main or to master in this case, make sure that that is... then available on the remote repository, any changes you want. And then in order to make that available on the server, what you do is you run a git pull.
So what the git pull does is it's going to pull all of the latest code, and then you simply run the command again to restart the Docker container. So if I now do a git pull, it will say it's already up to date. You can see, already up to date.
But if I were to pull some changes, you will see that right here and then right now this still runs so now i don't have to do anything but if there's new code or new changes that you want to do that's when you would run the docker compose up d again and there we go it's restarting and then your application is working with all of the new logic so whether you want to change different prompts add more logic This is how you do it.
And this is the whole development flow. And now what we've been building so far is the exact same process that we use for our own clients. So if you've made it this far, you really already have the skills required in order to start freelancing.
Because this is exactly what small businesses need help with right now. So if you've been thinking about freelancing, but just don't know where to start or how to find that first client, make sure to check out the link in the description. Watch the short video on that page, then click book a call, fill in a couple of questions to see if you qualify, and then pick a time.
On that free call, my team helps you to map out your 90 -day plan. And if it's a good fit, we'll show you what working together looks like. All right, so now it's time for the last like true chapter, which is building the admin dashboard to truly make this a full stack AI engineering project.
So we're now going to create a portal where users can work with the knowledge base and update it. This is exactly the same that we did for our clients. So they have an environment where if they want to make changes to the rules, to the knowledge base, or they have a new product or something like that, they can just manually update.
updated in there without having to send us an email to then do a new deployment. So that's going to be uploaded directly to the database. And as soon as we hit save there, the changes are adjusted.
So let's work through this. And the first thing that we're going to do is we're going to make some adjustments to our main .py because we are now going to add our API routes. So first of all, what we want to do is we want to have a basic login in this web page this admin dashboard that we're going to create now authentication and how to log in and authenticate is again one of those things where you can go deep in right now we're just going to set up a very basic protection so that when we ship it at first it's just not public later we can also even add more to this like another ip protection but let's get started so coming over here we are in our app there we have our main .py which is now very little.
And we're going to paste everything in here. So now it's a little bit more. So you can see next to only our health endpoint, we now have more endpoints in there.
So we can pull, we have the knowledge base, we have our tickets. So we can create all of the... different routes really that we need for our admin dashboard to start pulling the information from our database.
We're also going to add an pull request so we don't really have to wait for the 30 second interval so we can also trigger it from the dashboard. And next, we're going to also update the database so that we can also connect that, right? So then we come over to the database and here are new functions that we need to append.
So make sure that we do not replace all of this, but scrolling down, we need to append them. So we now have a couple more operations that we can do. So we have all of our list, messages, sections, events, all of that to read that from the database as well.
Because before it was mostly writing to the database, right? Because we did not have any mechanism where we would also have to read from it. But that's the purpose of our dashboard.
Oh, there's one more thing. Read the tidy lines. Don't forget this.
We need a dashboard password. So make sure that when we go to, let's see, go to our... environment variables i put the database password remember like when i stored that when superbase generated i already put that here because i thought this was the page or the the variable to put the database password but it's the dashboard password so now our both our database and our dashboard have the same password not a best practice But in this case, it's actually quite helpful and you might also already have that.
We'll check that in a bit on the surfer. Well, that means that we will use the basic authentication and we'll get a browser pop -up and we can just do admin and then we'll use this password and we'll be able to log in there. All right, so you can also easily change that.
So just for you to show, look, if I now do a cat .env, this is on the surfer. So you can see this is already set, right? And remember, you could do the nano .env.
And now we could come in here and let's say you want to change that. You could change that over here. So now we're going to create the React app.
So this is the first part of the project where you actually need Node installed. And we're also going to be working with ShadCN. So ShadCN is one of my favorite front -end libraries.
It's pretty much the foundation of your design system. So as you can see, They have all of these pre -built components already in there.
So you don't have to worry about what does a menu look like? What does a bar chart look like? You can just use these building blocks.
So you can see all of these components that they have all the way from, where should we start? Like an avatar. So this is what an avatar looks like.
This is what a card looks like. So we can create these beautiful pages and we can just decide. What colors do we want to use?
And you can go pretty far in customization, but especially like for internal tools, usually we just build off of this and just add the client's logo and their colors and they're usually happy with it. So what we're now going to do is we are now going to come back to our project. So locally, not on the server, make sure we're in the root and we're going to create the project in here because we're going to set this up as a mono repository, meaning that we're just going to use a...
single GitHub repository. And we're going to use the same server to get all this code on just to keep things simple. Now, quick sidestep.
Usually for all our production environments, we have a dedicated server for our backend. Then we have a dedicated server for our frontend applications. And for more serious applications, we may even have a staging environment for those two as well.
But then you can see, then you already need four servers. So that is also four times the cost. So for this course, That's not really needed, but just so you know and understand how that works in the real world when you encounter this, when you're working with clients, for example, or you're doing this in your job.
Okay, so let's start running this. And let's see, we do MPX. So this is why you should have Node installed.
If you get an MPX error, ask your AI agent to fix that. We're going to run the chat CN command. So now you can see we're creating that dashboard.
Okay, so this takes a couple of seconds and then we're going to run the following and we're going to do this. So this is going to remove the .git from the dashboard. So when we set this up using this command, there's probably already like a git set to it, but we already have that because we're using a monorepo.
So this is now our dashboard folder that we created inside our project. It creates a Vite React app using TypeScript in dashboard with Tailwind and ShadCN UI. Just simple black and white right now.
So what we are then going to do, we're going to CD into that dashboard. Let me clean this up for you. And then what we're going to do is we're going to get some extra components in here.
So we'll run this other chat CN command. We'll have that. And now we need to do a little bit of configuration.
So now when we go into the dashboard, into the fight config. Let's see. Let's close this.
You can check this out. And we need to replace the default setup because we use a template, right? Replace fightconfig .ts, the highlighted server blocks over here.
So let's see. We can pretty much just take this and I'm just going to copy everything that's easier. Put it in like this because now our server first is going to be the API in here.
We're going to proxy it through that. All right. So proxy the API in development.
And then we're going to add the API clients and types. So this is now in, let's see, source lib. We go in API .ts, which is not there.
So we're going to create that, API .ts. And we're simply going to plug this in here. And what this is going to do is this is going to...
configure the other end of our API configuration. So a couple of steps before we set this up in fast API, right? We changed main .py to have these extra endpoints.
And now we're going to make sure that our front end can also communicate with those. So scrolling down now, also, we're going to create some types. So in libs, again, we're going to create some types .ts.
So this is similar to how we worked with Pydentic AI, right? But now we're just doing this in TypeScript. So you can see the different types of data models that we can work with, similar to how we have that stored in our database.
So we plug those in there as well. So these are the components where we have everything related to our UI and also where we import a whole bunch of stuff from ChatCN already. Now we're going to create a new component and we're going to call this statusBatch .tsx and copy this.
All right, so now coming into the login page. So we go to source, we go into, we create a new folder. We call pages in here and we're going to create a new file called login .tsx, tsx.
And we're going to create that login page. All right, so we get that. And then we have another one we call events.
So this is going to be the events page. So we're literally making the pages for our dashboard right now.
Events .tsx, plug that in here. Make sure we grab this. We got tickets.
Make sure to get that as well. And let's see, we're almost there. Let me just copy this.
Knowledge base, tsx, save that. And let's see, now we're just going to put that all together. So let me also show you what this looks like.
So let's see what it was before, right? So before, this is just... a simple setup you can see project ready this was from the chat cn starter kit you can now add components here so we're going to replace all of that and here's also how you can see how an app like this is built up so we do the imports at the top and then this is pretty much where we export our entire app and here you can see how the page is built up so you can see The headers over here, you should see Harbor and Pine support.
So I expect that to show up. We can see a button to like where we can log out. And then we have the header.
So in there, we can see the different pages probably. So we'll have to see what this is going to look like when we first open it. So let's see, we're putting it together.
Yes, okay. So now what we can do is we come back to the terminal again, make sure you're in the dashboard folder, right? So you need to be...
in this folder, and now we can run npm run build. So this is going to build the project for the first time. Let's see if everything is working.
So this completed. And now what we can do is the next step would be to run it. So npm run build is just to check the build to see if it builds and see if it compiles.
All right, so next, what we need to do in order to run it locally, we're going to need three different terminals because we need to run the API, the puller, and then also our development server. So what we're going to do right now, You can do this in multiple different ways, but right now for this purpose, I'm just going to create the different versions here.
So what we can do is let's say we'll rename this. This is going to be API puller. And then in here, this one is going to be the dashboard.
Okay, so we'll do it in this order where first we'll do UV run fast API. So this is to run. our api so let's see we got everything going then we need to puller so we're going to do uv python m puller so we'll make sure that runs as well so that's going to pull every 30 seconds and then coming back to the dashboard we're going to do um let's see in the dashboard we're already in the dashboard so we here we can just do npm run def all right so we got api running we got polar running we got dashboard running and then when we open this in the browser we should be able to go admin and then take the dashboard password over here and log into our application so we are now in if you run into an error or something like that make sure to maybe like restart your fast api app and if you really get stuck as your ai agent i had a small little hiccup i had didn't change any code but just restarting fast API made it work.
So sometimes this can be a little bit tricky because we're having multiple terminals run. So what we can see right now, let's see, we have a very simple admin dashboard where we can first of all, see all of our tickets or sorry, all of our events. So this is everything that's flowing through the database, right?
So this is now an exact copy. It's not really copy, which is literally directly pulling this from the database. So whenever something happens here, It's also in here.
We can even check the inbox right now. So for this, make sure that if we start testing this, it's not running on the server anymore. So what you can do, mine, you can do like a Docker PS to see what's running.
If it's still running, you could do Docker Compose down. Mine is already down, so nothing will happen. But otherwise, we'll have it run in two places and both will trigger and it can get a little bit funky.
We don't want that. So now, because now we have everything running locally. So if we now come over here and let's do dave .abelardemo again, we can do, let's do a dashboard test.
Will this come in? So this is now in here. This is now a new event.
So we should now be able to come in here and instead of waiting for 30 seconds, we could do check inbox. Let's see. There you can see, we got a new event.
We skipped this one. So that is now as expected. Same in our database.
So from the event, we can also go here to the ticket. So again, this is not going to win a design prize just yet, but you can see the basic foundation is in here where we can even read all of the messages. Now, then we also have the knowledge base in here where we, again, just in a very simple setup, we can see all the records that are in here.
So what's the sign off? What's the brand tone and voice? Here are all the sizes.
So this is now really the foundation to it. And now making this better looking, making this pretty is literally just one prompt to your favorite AI coding agent to say, hey, make this a full and pretty. support dashboard but you get the idea right now the test to really check out is let's say uh let's do let's change the sign off so and every email with harbor and pine i don't know let's say we do a capital s in here let's try and save this so this is now saved so let's see if we now come over to our knowledge base and we make this bigger let's see we have to sign off you can see this is now directly updated in the database.
So that's the most important thing here that we now have an admin panel that we can give people access to where they can manage all of this. Now, next, what we're going to do before like tinkering with UI and all of that, this is all still running locally. This is running on local hosts.
So what are we going to do next, right? How is this going to work together on our server? So what we're going to do, if we're going to scroll down all the way, to where are we running it locally we did that now we're going to put this into the docker file as well so we're going to take this snippet uh let's just copy the whole thing because there's another line in here come back to our project so now we go into our docker file let's see let's let's close this out uh this is not our docker file where's the docker file this is our docker file so this is the instructions for docker in order to do all the python related stuff but what we're now going to do Right, so now as you can see, we also add the dashboard part to this where we install Node, we run all of the commands that we need in order to build it.
And now bringing that all together, that now makes sure that we can also run our dashboard on our server. So let's see what now the next steps are. We can now deploy this.
So first of all, we need to make sure that our dashboard password is set. So we checked it already. We already had that, right?
So again. I don't have to change anything here because it's already set up. Now, the next thing that we need to do is we need to, of course, push this all to our remote.
Let's see, let's actually save this. So this also shows up. So make sure all the changes from your dashboard are on GitHub.
So they need to be on remote. I already did an intermediate commit. So you can check this out.
You pretty much need to make sure and test if you go here that all of the changes. you can see now are in here. Because what we can do next is we can come back to our server.
We can come in here. Let's see, we already have this. And now we can run a git pull.
And now you'll find that, look, we now have all of the dashboard code in here. So if I now run this, you'll find that, you see, we also have that dashboard. And now what we can do is we can run our command again, docker compose up dash t dash dash build.
We're going to boot that up. All right, so that is now running. We can do another Docker, let's see, not a Compose, but a PS to see, okay, this is now running.
Now, the next step that we're going to do is we're going to access the dashboard that is now running on the server. So how we are going to do that, we're going to do that via an SSH connection. So we don't go over the public internet.
So there's multiple different ways to do this. But if we actually were to put it on the public internet using HTTPS, for example, we would need a domain and we would need caddy.
And that is, again, one of those steps that is just beyond what I'm going to cover in this course. Right now, I'm going to show you how you can connect to this, which is very secure, by the way. So you could even let your clients do this if you give them one command pretty much to run this, right?
So they don't really even have to remember that. It's just like, hey, open a terminal, run this command. And then you can access it.
So let me show you what that looks like. Again, depending on whether you set up the shortcut, I did not have that. I'm going to open up another terminal here.
And I'm going to, let's see, come in here. And now we just need our IP address from our server again, which is this one. Make sure.
You have the add symbol in there. So look what we're doing extra right now. So now we're doing an SSH, but we are going to put the local host and the port in here, right?
So now also let's get the password once more. So now we are one more time into our server in here, but what we can now do now, we can, if we keep this terminal open locally, what we can do is if we now, let's see, we close everything. locally here so we do this so now nothing is running here anymore which means if I go to this localhost this will now be gone that's now gone but now if I go to localhost 8080 let's see there we are now able to access our website so we can now do admin in here and again grab let's see where is that password again I think it was this one.
We can now log in here. All right, so you can see we are now inside local host and we can now access the dashboard on the production server. Okay, so if you made it this far, again, amazing progress.
Now, the final thing that we really need to do here is we need to check if everything is still working. So let's come over to... the inbox again.
And let's actually, let's see, let's take one of those previous questions that we had, like one from the paddleboard. So let's just use this one again. And now I'm going to send that.
So let's see, coming back over to our application and first having this over here. So now we can check. Okay.
So in Gmail, of course, this is always instant. This should work. But now if we check our inbox and we run the poll in here, let's see what we got.
So this is now checking everything, but it's checking it through the server. If we come back over here, did this already update? There we go.
We have the reply already. And now we should also, let's see in my inbox. And let's see now also in our inbox, we got that same reply.
So you now officially have an application running in production. on your own server. This is actually a huge, huge milestone for you to get to.
And with that, we have come to the end of this full stack AI engineering course by actually building a project. I hope you found it helpful. I tried to put as much value as possible as I really could in a video here that I could put on.
youtube and now if you want to go deeper on this right so what are some extra things that you can now do with this because this is a serious project and you can actually you can sell this you can go into any business that still runs manual support via a ticketing system or what have you and you can suggest to help them build a system like this now of course there is the part around the admin dashboard right so this is of course A very simple setup.
And with a couple of prompts, you can already make this better. So that is something that you can play with. Use something like Opus 5 .5 and just go at it.
Just literally first, like the first prompt for me would be make it pretty. Literally, like just make this a proper admin panel given all of the information that we want to see in here. Like that prompt alone will turn this dashboard into something really cool that you could actually already demo to a client.
Okay, then next. Generally, people expect to be able to go to some type of web browser, right? So currently, we are tunneling this through localhost, which is actually very secure.
It's one of the most secure ways to do this because we're not going over the public internet. We can only connect to our server, remember, with the whitelisted IP and the SSH key. So it's impossible really for people to access this information, even if they have the credentials to log in.
But if you want to... actually use this for a client project the next step that you would need to look into is getting an actual domain then you would need to set up caddy in order to make that domain available and apply https to that then you probably also want to have a little bit more strict authentication method in there so maybe not username password but maybe log in via google or log in via microsoft or at least have two -factor authentication in there And from there, you already have a really solid setup that you could ship.
Now, what then happens in the real world with projects like this, this is just the foundation. And now you need to just pull and move data through it. So whenever you're working with a client on this, they are going to have lots of cases, right?
Because they have an active support inbox. They have a whole team working on it. So every day there will be new examples.
So you'll go through... lots of trial and error in the beginning, optimization, you could call it, in order to really dial in, first of all, the knowledge base. So what really goes into the knowledge base and how does the agent search for this?
But also potentially, coming back to our AI pipeline, also potentially this whole flow that you see over here. And I've set it up in such a way that this is already really flexible. And for most...
support inboxes, you're probably not going to need more than this if you're using a model like Sonnet, for example. But like we've covered, right, it could be that you need to branch off and have dedicated agents for certain specific scenarios. So those are just a couple of ideas that you can follow up on in the course wrap up.
But you now have a full stack AI engineering project with a backend as well as a frontend. Put it together in Docker. deployed it on a server, and we've even applied a small evaluation loop with a golden data dataset to really showcase that you also understand how to make a system like this better.
So like I've said, this is going to be a huge portfolio project for you. And now, if you want to go deeper on this, if you want to learn more, like I've said, our GenAI Accelerator is the next. best thing that you can do where for all the things we covered right now at the high level we have dedicated videos and even entire weeks on a specific topics we go super deep into ai system design design patterns retrieval augmented generation and anything data related everything related about monitoring and logging of your applications that involve llms And then also way deeper into the deployment, how you can actually work with domains, caddy and really ship things end to end.
So if that sounds interesting to you, make sure to check out that link. And if you're already quite comfortable at the level where you think, hey, I wanna take the next step and I wanna start freelancing, there's another link for that to check it out as well. So that's it for this video.
If you made it all the way to the end here and haven't done so, please leave a like and also consider subscribe. And then I wanna thank you for... going through this entire course with me and then i hope to see you in the next one
The Hook

The bait, then the rug-pull.

The course opens on the finished product: a Gmail inbox where each email is tagged ai-processed or needs-human. It then promises the part most tutorials skip, which is everything around the LLM call, from OAuth and a database ledger to evals and a Docker deploy on a real server.

Frameworks

Named ideas worth stealing.

1:23:26model

Classify, then answer, then decide

  1. Classify with a small model (Haiku) into a typed Classification
  2. Answer with a stronger model (Sonnet) using knowledge-base tools into a typed AgentReply
  3. Decide with deterministic Python: escalate or send

Three-stage pipeline where the cheap model triages, the capable model drafts, and plain code holds the final authority to send.

Steal forany AI workflow where a wrong action is costly
1:38:25list

Escalation guardrails in the decide step

  1. Attachment present
  2. Classifier set needs_human (angry, refund, manager, order status)
  3. Agent action is escalate
  4. Agent lacks enough information
  5. Issue type is on the always-escalate list
  6. Reply promises an action (refund, shipment, replacement, date, call)

Any one condition routes the ticket to a human, regardless of how confident either model was.

Steal forclient-facing agents that must never overpromise
1:11:27list

Skip-reason guards

  1. Sent by us (SENT label)
  2. From our own address
  3. Auto-submitted / out of office
  4. Bulk mail or list headers

Rules that make it physically impossible for the bot to answer its own replies or newsletters.

Steal forany email or messaging automation
1:17:13model

Event ledger data model

  1. events: every action through the system
  2. tickets: one per thread
  3. messages: many per ticket
  4. knowledge_base: section, title, content

Record everything that happens, group conversation into tickets, and keep a replayable history. Maps to invoices and other domains.

Steal forany automation that needs an audit trail
1:40:47concept

Narrow go-live strategy

Start a client deployment with everything escalated to humans except one well-understood question type, then widen as trust builds. Used to go live in two to three weeks.

Steal forpitching AI automation to cautious businesses
2:01:07list

Eval improvement loop

  1. Run the golden set
  2. Open a failing case and read the model's reason
  3. Change one thing: classifier prompt, agent prompt or a knowledge-base entry
  4. Re-run the whole set, more than once

The iteration loop for improving a structured pipeline, which can be handed to a coding agent with an explicit no-overfitting instruction.

Steal forprompt tuning on any structured-output pipeline
CTA Breakdown

How they asked for the click.

VERBAL ASK
2:44:11product
“If you've been thinking about freelancing, but just don't know where to start or how to find that first client, make sure to check out the link in the description.”

Placed right after the deploy payoff, when the viewer has just proven they can ship. Repeated at the end alongside the GenAI Accelerator, with mid-video plugs for the accelerator at the webhooks and RAG sidesteps.

FROM THE DESCRIPTION
Storyboard

Visual structure at a glance.

finished agent demo
hookfinished agent demo00:01
ticketing-system swap motion graphic
promiseticketing-system swap motion graphic05:16
Glaido sponsor
sponsorGlaido sponsor17:51
Google Cloud Gmail API
valueGoogle Cloud Gmail API27:07
poller running with env
valuepoller running with env59:27
skip_reason guards graphic
valueskip_reason guards graphic1:13:53
classification schema + agent logs
valueclassification schema + agent logs1:50:07
golden emails evals
valuegolden emails evals1:57:25
VPS section card
valueVPS section card2:16:32
dashboard API routes
valuedashboard API routes2:49:31
dashboard built into Docker image
payoffdashboard built into Docker image3:03:25
Frame Gallery

Visual moments.

One-click upgrade to your Google

Get more breakdowns in your search results

Add Modern Creator as a preferred source and Google shows you more of our breakdowns in Search, Top Stories, and AI Overviews. It only changes what you see, and you can undo it in your Google settings anytime.

Add to Preferred SourcesOpens your Google source preferences with us pre-loaded. Tick the box and you're done.
Watch next

More from this channel + related breakdowns.