WEBVTT

00:00:05.240 --> 00:00:19.540
Welcome back to the course on how to build an AI agent from scratch and I felt like this topic was so important that even though I had finished recording all the videos and even started editing them I went back to record this video because it's super

00:00:19.540 --> 00:00:32.700
important I thought it deserves its own dedicated video Today I'm going to be talking about prompt engineering Now first I want to define what exactly is prompt engineering Everyone says prompt engineering

00:00:32.700 --> 00:00:46.280
and a prompt engineer What does that actually mean If you take a look at the system prompt here this message gives instructions for how the AI ought to act So you know you can have a very simple

00:00:46.280 --> 00:00:59.240
prompt you're a helpful assistant that's just some basic instructions But you might want your AI to respond in a very specific way For example if you're generating SQL queries you

00:00:59.240 --> 00:01:12.560
have to give the AI what your schemas are If you don't give the AI your schemas your AI isn't going to know your schemas and you can't create an accurate SQL query You also might have some business logic rules

00:01:12.700 --> 00:01:26.780
You might define something which could be a little bit ambiguous and you want to clarify exactly what that means So let me take example right here building a system prompt So when you build a system prompt this is the OpenAI Playground This is my internal

00:01:26.780 --> 00:01:41.660
app that I named Nexus Gen AI So when you build a system prompt there are several things that you should take into account Number one is you want to give your AI some sort of role This is a more or less optional statement

00:01:41.760 --> 00:01:55.420
It helps your AI have some sort of flavor of how it's actually responding So I'm actually something like you know you are a nice feminine AI agent that offers trading advice You

00:01:55.420 --> 00:02:09.740
know it gives your AI some personality Something that it can mimic when it's creating responses So another thing that's really important for creating a system prompt is your actual instructions What

00:02:09.740 --> 00:02:24.400
the AI should actually do You give it a list of things The list of constraints that it should follow The output format Anything that's important for the AI to know before

00:02:24.400 --> 00:02:37.260
it begins You want to put it all within the system prompt Now if you just have a list of instructions Maybe you have an output schema If you just have that that is called

00:02:37.260 --> 00:02:52.060
zero shot prompting and is good for very basic very simple tasks However if you're getting into some more complex tasks like generating SQL queries then you'll find the AI isn't usually good enough at

00:02:52.060 --> 00:03:05.800
generating these queries You have to give it examples of what a good query looks like and what a bad query looks like That is the heart of prompt engineering We call this few shot prompting

00:03:08.260 --> 00:03:23.120
With few shot prompting we basically want to give the AI a bunch of examples of things that work and doesn't work So you can see in this example I have right here If I click here these are examples These are saved within the system prompts

00:03:23.120 --> 00:03:37.160
and just formatted for a nice easy consistency If you actually go here and you click export I'm going to just paste this into a terminal Create a new tab and you can see this is what the actual system prompt is

00:03:37.320 --> 00:03:49.560
It's just a very large detailed markdown You can literally think of it copy pasting this putting it over in the playground and putting it right here This is exactly what it is and you can see in my examples

00:03:49.740 --> 00:04:01.700
I have these same examples within the system prompt and delineated it I just have code to transform this UI into this markdown format

00:04:03.400 --> 00:04:16.380
You notice several things within the system prompt that are really important I've mentioned some One you notice these examples Two I have my AI identity and objective Three I have my JSON formats

00:04:17.480 --> 00:04:27.100
Four I have things like my schema My schema is here and it's injected at runtime It tells the AI the valid tables I have within my application

00:04:29.540 --> 00:04:43.000
You want to provide detailed rules You'll first start with something simple and then you're just going to inevitably build towards a strong system prompt Another thing that I really want to emphasize

00:04:43.000 --> 00:04:57.780
is this system prompt can respond with whatever you want You can tell your system prompt to respond with markdown You can tell your system prompt to respond with JSON You can tell your system prompt to respond with a technically valid SQL query It can really be whatever you want but

00:04:57.780 --> 00:05:11.200
you want to make sure it's accomplishing your goal in certain formats The model just has an easier time to generate If you tell your AI to respond with JSON it's going to do a lot better job than asking it to respond with some

00:05:11.200 --> 00:05:26.160
proprietary format nobody has ever heard of Finally there are some things that you should keep in mind For example within AI tools within the APIs you can ask it to respond with these formats but also when you

00:05:26.160 --> 00:05:38.980
want to create an account and use these APIs you'll see they have these little helper modules You'll see things such as an MCP server An MCP server is just an external API that is basically

00:05:38.980 --> 00:05:48.420
telling your AI to respond with a specific JSON so that a JSON object can hit an API That's more or less kind of what an MCP server is

00:05:53.080 --> 00:06:08.060
You have things like the output schema You know you might tell your AI to respond in JSON mode and then you might not have the response actually as text but it might be within a different part of the response API But the main point that these

00:06:08.060 --> 00:06:21.100
models are all doing is just simply generating text in accordance to the instructions that you give it In this next video I'm going to talk about the way to make your AI agent safe

00:06:21.100 --> 00:06:30.280
while still be able to do things automatically It is an extremely important part of building production AI agents I'll see you there
