WEBVTT

00:00.200 --> 00:00.720
All right.

00:00.720 --> 00:02.280
So we have the tool.

00:02.280 --> 00:04.720
And now we need to configure an LM.

00:04.920 --> 00:06.520
So let's go and do that.

00:06.520 --> 00:09.040
So let me initialize a chat open AI.

00:09.240 --> 00:11.200
And I'm going to give it GPT four.

00:11.600 --> 00:15.200
There's a reason why I'm using GPT four and not GPT five.

00:15.200 --> 00:18.680
And I'm going to reveal this reason in the end of this section.

00:18.960 --> 00:25.920
And now let's go and use the link chain hub to pull something, which is called a react prompt.

00:25.960 --> 00:29.160
Now before we run this, just a quick note here.

00:29.160 --> 00:36.400
In case you're using the EU endpoint for meat, you might encounter this error where it says that it

00:36.400 --> 00:37.920
cannot find this prompt.

00:37.960 --> 00:43.640
And the reason you're getting this, because the public prompt or the public prompts are hosted in the

00:43.640 --> 00:48.120
US instance of Lenox-smith, which is the default public hub instance.

00:48.280 --> 00:54.840
And if you're using the EU instance, then it does not automatically mirror all the public prompts from

00:54.840 --> 00:55.720
the US hub.

00:55.960 --> 00:58.880
So in case you're getting this, we have two options.

00:58.880 --> 01:06.430
Either you remove the environment variable of length underscore endpoint, or you can simply go and

01:06.430 --> 01:10.630
copy paste this prompt template and create a prompt template object.

01:10.790 --> 01:12.110
And let me run it in debug.

01:12.110 --> 01:13.910
And let me show you this react prompt.

01:14.270 --> 01:18.150
So this react prompt over here is going to be a prompt template.

01:18.310 --> 01:21.150
But it's going to be a very special prompt template.

01:21.350 --> 01:23.910
Those are going to be its input variables.

01:23.950 --> 01:27.910
It's going to receive an input which is going to be the user's question.

01:28.270 --> 01:30.990
It's going to receive tools and tool names.

01:30.990 --> 01:36.350
And those are all things that length chain is going to extract from the tool object that we built earlier.

01:36.790 --> 01:41.270
And it's going to have also the agent scratchpad, but ignore it for now.

01:41.270 --> 01:45.270
In the next section we'll be elaborating on this agent scratchpad here okay.

01:45.470 --> 01:48.830
So this is the variables that it's going to receive.

01:49.190 --> 01:52.750
Now let me show you the template that it's using.

01:52.750 --> 01:53.110
Right.

01:53.110 --> 01:56.590
So we can have an idea what's going to be sent to the LM.

01:56.870 --> 01:58.230
So the template here is.

01:58.230 --> 02:05.350
Answer the following question as best as you can, and let me open it in the prompt tab so we can review

02:05.390 --> 02:07.270
it in a much nicer UI.

02:07.310 --> 02:09.910
Okay so this is the actual prompt template.

02:10.270 --> 02:12.990
Now you can see here it's going to receive tools.

02:13.430 --> 02:14.550
The tool names.

02:14.750 --> 02:17.550
And then we have here the question is going to be the input.

02:17.550 --> 02:20.110
And we have here thought Agent Scratchpad.

02:20.150 --> 02:20.590
Okay.

02:20.910 --> 02:25.110
So in this react prompt we have this middle part over here.

02:25.350 --> 02:28.430
And this is actually what's going to be the magic.

02:28.430 --> 02:31.470
And it's going to be the secret sauce of our reasoning.

02:31.470 --> 02:33.110
And this is how it all started.

02:33.150 --> 02:33.350
Okay.

02:33.390 --> 02:35.710
It's simply everything is a prompt with LLM.

02:35.710 --> 02:38.670
And it really amazes me to really think about that.

02:38.670 --> 02:44.190
This is the basis for all of this modern technology that we have today, like cursor, Cloud Code,

02:44.430 --> 02:46.870
Devin, and all of those deep agents.

02:47.030 --> 02:50.750
And I'm not going to elaborate on this prompt for that.

02:50.750 --> 02:55.630
I have a dedicated video to discuss why did it came from, why it's useful.

02:55.630 --> 02:57.660
And this is called the react prompt.

02:57.900 --> 03:00.260
It originated from react paper.

03:00.260 --> 03:02.460
And this is really the basis for everything.

03:02.860 --> 03:06.980
But for this section all we need to know is that this prompt works.

03:06.980 --> 03:10.060
And for some reason everything would work with this prompt.

03:10.100 --> 03:12.420
Okay, so this is what we need to have in mind.

03:12.460 --> 03:14.100
We're not going to elaborate on this video.

03:14.100 --> 03:18.100
I highly suggest you check this theoretical part in case you want to dive deeper into this.

03:18.620 --> 03:19.420
All right.

03:19.420 --> 03:27.140
So now we want to go and we want to create our reasoning engine.

03:27.300 --> 03:27.980
All right.

03:27.980 --> 03:34.660
So for that we'll use the create react agent function which is going to receive the LM.

03:35.020 --> 03:39.820
It's going to receive the tools and it's going to receive this react prompt.

03:39.980 --> 03:43.180
Now this is going to create for us a chain.

03:43.180 --> 03:45.780
And this is going to be our reasoning chain.

03:45.780 --> 03:48.100
You can see that it's going to return a runnable.

03:48.100 --> 03:50.100
So this is an equivalent for a chain.

03:50.460 --> 03:56.570
And it's going to plug all of the values of of the tools, and the input that the user will provide

03:56.570 --> 03:58.930
is going to provide everything to that prompt.

03:59.210 --> 04:05.610
Now, hopefully when we're going to run this chain, then the model, the LM is going to reason on the

04:05.610 --> 04:10.690
input and it's going to say, hey, you need now to run the search with the following query.

04:10.810 --> 04:11.410
All right.

04:11.530 --> 04:15.290
So this is hopefully what this chain is going to return us.

04:15.450 --> 04:16.050
All right.

04:16.130 --> 04:18.730
So this is the reasoning engine right now.

04:18.810 --> 04:23.050
So we get that part really set up here we have the reasoning engine.

04:23.050 --> 04:26.010
And now we need the execution of the tools here.

04:26.530 --> 04:27.210
All right.

04:27.210 --> 04:31.890
So it's going to be here this agent executor that we imported from before.

04:32.210 --> 04:35.250
Now it's going to receive the chain from before.

04:35.250 --> 04:36.450
By the way I called it agent.

04:36.450 --> 04:37.650
This is not really an agent.

04:37.650 --> 04:39.090
It's going to be a simple chain.

04:39.450 --> 04:41.090
It's going to receive the tools.

04:41.290 --> 04:44.130
And I also added here verbose equals to true.

04:44.130 --> 04:46.010
So we'll be able to see when we run it.

04:46.050 --> 04:47.730
We'll be able to see the reasoning process.

04:47.730 --> 04:49.730
And we'll be able to see more logs here.

04:50.090 --> 04:50.490
All right.

04:50.490 --> 04:52.640
So this is going to be our agent.

04:52.640 --> 04:53.440
Runtime.

04:53.840 --> 04:56.320
I remind you, don't worry about the internal implementation.

04:56.320 --> 05:00.240
We're going to see this and we're going to implement everything from zero in the next section okay.

05:00.280 --> 05:02.920
So you know exactly how this thing is working right now.

05:03.120 --> 05:06.400
But what this is going to do, it's going to run in a while loop.

05:06.400 --> 05:10.760
And it's going to run this react chain over and over again.

05:10.760 --> 05:15.520
And every time there needs to be a tool call, it's going to call that tool, and it's going to feed

05:15.520 --> 05:20.400
the output of the tool back to the LM, and it's going to do this until it finishes the task here.

05:20.440 --> 05:21.080
All right.

05:21.080 --> 05:23.080
So this is basically what it's going to do.

05:23.600 --> 05:26.840
And don't worry about the arguments that it will receive.

05:26.840 --> 05:31.600
We're going to cover it in the next section when we'll implement everything here from zero.

05:31.800 --> 05:34.600
So I promise you you'll know exactly how this is working.

05:34.840 --> 05:38.760
Let me just show you a quick peek of the implementation of link chain.

05:38.760 --> 05:41.080
So this is the Create React agent here.

05:41.240 --> 05:42.880
And you can see what it's going to return.

05:42.880 --> 05:48.240
Here is a runnable object where it's going to take the prompt the react prompt.

05:48.240 --> 05:50.750
And it's simply going to send it to them.

05:50.950 --> 05:54.430
It has this output parsing which I'm going to discuss later.

05:54.430 --> 05:57.390
So please, please, please don't worry about this output parsing.

05:57.430 --> 06:02.350
Okay, I remind you what we're interested here is how to use the link chain interface.

06:02.350 --> 06:06.470
In the next section we're going to see exactly how it's implemented because we're going to be implementing

06:06.470 --> 06:07.270
it from zero.

06:07.550 --> 06:08.150
All right.

06:08.150 --> 06:13.630
So just to summarize what we saw so far, we defined our reasoning engine, which is going to come from

06:13.630 --> 06:19.350
the create react agent function which is going to return us with a chain which is simply going to receive

06:19.350 --> 06:23.950
the tools, or it's going to receive the user's query, and it's going to send everything to the LLM.

06:24.310 --> 06:31.430
Once we have that, the LLM is going to return us a response and the agent executor is going to be responsible

06:31.430 --> 06:34.830
to maybe call a tool or to run another LLM call.

06:34.830 --> 06:38.430
And it's going to be the orchestrator of this prompt over here.

06:38.870 --> 06:39.430
All right.

06:39.430 --> 06:41.830
So we are about to finish now the code.

06:42.070 --> 06:45.670
And let's now go and let's invoke our agent.

06:45.990 --> 06:48.030
So let me just create a new variable.

06:48.030 --> 06:54.390
And I'm going to call it chain, and I'm going to make it equal to the agent executor here.

06:54.430 --> 06:58.630
Now, I know this looks funny here, but this is actually preparation for something that we're going

06:58.630 --> 06:59.630
to be doing next.

07:00.110 --> 07:03.470
And now let's go and invoke this chain.

07:03.510 --> 07:04.070
All right.

07:04.070 --> 07:07.150
So I'm going to paste here this snippet.

07:07.190 --> 07:12.790
And here we have a variable called result which is going to be our chain when we invoke it.

07:12.870 --> 07:18.390
And here we're going to provide the invoke method the keyword argument of input.

07:18.390 --> 07:20.110
And it's going to be a dictionary.

07:20.270 --> 07:23.630
Now this dictionary is going to have the key of input.

07:23.830 --> 07:30.590
And this input right over here is going to be what's actually going to be populated in the prompt template

07:30.590 --> 07:31.830
that we defined above.

07:32.030 --> 07:37.550
And the query is going to be search for three job postings for an AI engineer using link chain in the

07:37.550 --> 07:40.430
Bay area on LinkedIn and list their details.

07:40.950 --> 07:45.510
And in the next video we're going to run, debug and examine the output.

07:45.510 --> 07:47.390
So hopefully it will be clearer then.
