WEBVTT

00:00:05.540 --> 00:00:17.320
In my last video on how to build your own AI agent from scratch I introduced several important concepts Number one is I introduced the idea of tools

00:00:18.180 --> 00:00:30.720
ways to allow your language model to actually do things These can be JSON objects API calls CLI commands SQL queries anything that allows your AI to

00:00:30.720 --> 00:00:44.600
actually do things and gain information Your tools are executed within an orchestration loop using the React reasoning action framework This

00:00:44.600 --> 00:00:58.300
framework tells your LLM how to reason and take actions in its environment and the tools are a key part of making this possible However a while loop and a bunch of tools

00:00:58.300 --> 00:01:11.700
is not enough to make a production AI agent In this video I'm going to be talking about another key part in making AI agents and that's implementing permissioning within your tools

00:01:12.700 --> 00:01:26.280
Not all tools should be executed autonomously Some tools are very expensive or potentially very dangerous and can't be undone So you want to think about how to

00:01:26.280 --> 00:01:39.080
make your AI agent autonomous but safe You can do this by introducing a white list or a black list So

00:01:39.920 --> 00:01:52.740
within the code on the screen I basically updated our AI loop to include a list of white listed tools and the way this loop works is

00:01:52.740 --> 00:02:07.020
if the tool is not white listed then you have to ask the user for approval If the user doesn't approve then you can't execute that tool

00:02:07.920 --> 00:02:21.820
Again you can think of tools that call expensive LLM calls or you can think of tools that might delete some files Those types of tools need the user's explicit permission to execute

00:02:24.240 --> 00:02:38.920
Now so far a lot of this has been theoretical I'm going to show a concrete example a real world example of an orchestration loop This is the Nexus Trade Agent Planner

00:02:38.920 --> 00:02:53.320
and it basically serves as the planning phase for the orchestration loop So essentially you can think of something before this loop I'm essentially using it to create a

00:02:53.320 --> 00:03:05.640
plan as a specialized prompt and within the prompt again it's basically giving it specific instructions on how to explore its environment In this case

00:03:05.840 --> 00:03:20.360
develop back tests and deploy trading strategies I have special rules for launching sub agents special rules for performing research and then creating a trading strategy I try to

00:03:20.360 --> 00:03:34.400
tell it to analyze current regimes and search for past historical examples I give this plan which again is generated before the main loop and I give it to the main orchestrating

00:03:34.400 --> 00:03:46.420
AI agent This is essentially the thinker the one that actually executes the actions Within this code is basically these two

00:03:46.420 --> 00:03:58.780
steps at once and we can see I have a bunch of instructions on how the agent should act You'll learn how to build these instructions with

00:03:58.780 --> 00:04:13.120
experience but these instructions tell the LLM how to act And I also have the schema let's scroll down to React V2 and we can see it's literally exactly what we

00:04:13.120 --> 00:04:24.440
talked about It literally responds with a thought an action or in my app I say an action or a command and there's some nuance but that's not important for you

00:04:25.000 --> 00:04:36.800
And it can also respond with a final answer And this basically signals to the LLM that it's done it accomplished the goal that the user asked

00:04:37.680 --> 00:04:52.400
Another trick for building system prompts not just with AI agents but just in general is you should provide a bunch of real world examples So let's see this plan as an example This is the plan and this is

00:04:52.400 --> 00:05:06.040
the action generated by the language model It responded with a thought and an action or a command Let's look at another example Given this example this text it

00:05:06.040 --> 00:05:20.140
responded with this thought and this action It used this tool called a quick screener with this input By providing these concrete examples the agent will know how to respond in the real world

00:05:25.720 --> 00:05:38.860
Now I'm going to show a concrete example of an AI agent in action and it's basically going to demonstrate this part of the loop whether or not a tool is whitelisted In

00:05:38.860 --> 00:05:51.960
this case in this implementation it's simply just a toggle You can switch between automated and semi automated mode I'm going to start with automated just to show you what that's like

00:05:54.340 --> 00:06:08.540
What's going to happen here is this text right here when I click submit it's going to go to this planner oops this planner AI agent Literally if I type in the same thing here

00:06:08.540 --> 00:06:20.760
and click submit the response here and the response here will be very similar They won't be exactly the same but they will be very similar We can

00:06:20.760 --> 00:06:33.080
see this is the plan It's going to create a buy and hold spy portfolio It's going to back test it across several periods and analyze the results It's literally

00:06:33.080 --> 00:06:47.540
just the same thing Because we're in semi automated mode I have to manually approve every plan and every action Again that's essentially this part of the loop We

00:06:47.540 --> 00:07:02.200
can pretend we have this saying plan equals generate plan and the generate plan is just of the user's input and then we can say user input is just I want to no let's use the same exact user input

00:07:03.160 --> 00:07:15.960
So next I'm going to go ahead and go back here I'm going to click approve and the AI is going to automatically move on It's basically going to start this part of

00:07:15.960 --> 00:07:28.640
the loop It's going to generate a thought and an action See the thoughts and the action This is what it's thinking It's on step one of the plan It's going to create this portfolio with this initial value

00:07:29.180 --> 00:07:43.540
Now we're basically stuck here because I haven't yet approved it I'm going to click approve and it's going to approve It's going to execute this action and basically create this portfolio

00:07:44.640 --> 00:07:59.340
Now when it's done it created this portfolio That's essentially this result equals execute action and then we appended that right here I'm going to reject for now just to stop it It appended it right here into the

00:07:59.340 --> 00:08:11.300
conversation state and then it repeated It did it automatically You saw I had to stop it It went back here It generated a new thought and an action and this time I just said no It's going to break

00:08:11.300 --> 00:08:25.660
the loop and it's going to stop Now let's switch gears and let's just switch it to fully automated mode so I don't have to approve it It's going to execute everything by itself This is also

00:08:25.660 --> 00:08:37.640
similar ish to dangerously skip permissions if you use cloud code but don't worry Within the app next this is safe I'm going to say actually yes let's continue

00:08:39.000 --> 00:08:53.240
Unlike before which I had to approve all the plans it's going to execute it autonomously because I changed it to fully automated mode I'm going to click switch It didn't register

00:08:53.240 --> 00:09:06.020
Click approve and now it's going to be fully automated I won't have to approve any plan at all It's just going to execute it for me and you can see it just executed it It's running the action It

00:09:06.020 --> 00:09:19.340
has a thought The thought you can kind of read it up here and it's just executing these actions on my behalf I don't have to approve it That is the important thing that makes an AI agent production

00:09:19.340 --> 00:09:29.840
ready You have to be able to toggle between whether you're going to approve it or whether it should execute commands automatically

00:09:32.320 --> 00:09:44.240
Now the agent is going to read and summarize these results Again this looks complicated but again this is just the result of a JSON In fact if I copy the message

00:09:44.820 --> 00:09:58.840
I go back here I create a new tab and I type paste you can see it's literally just a JSON object and I have some UI

00:09:58.840 --> 00:10:12.400
magic to make it work That's why you see all this but it's literally just this here in a loop and a lot more code That's pretty

00:10:12.400 --> 00:10:26.700
much it for this lesson So just for a brief recap I talked again about tools They're extremely important I talked about the orchestration loop and I talked about how do you actually get your agent to

00:10:26.700 --> 00:10:41.340
work automatically You might have a whitelist or a blacklist You might have a button that toggles between automated and semi automated mode All these are different strategies for implementing autonomy in your AI agent

00:10:42.280 --> 00:10:55.240
Finally I talked a little bit about the planner creating a structured plan for your agent to follow This step while it's semi optional makes your agent a lot smarter because it

00:10:55.240 --> 00:11:08.540
already knows exactly what it plans to do In the next course I'm going to be talking about how do you actually trigger an AI agent It's going to be short but

00:11:08.540 --> 00:11:22.180
important because there are a number of ways you can start an AI agent whether you type it in in the UI or you have something to start it automatically This is very important so stick around and I'll see you in the next video
