WEBVTT

00:00.080 --> 00:05.880
Let's start now by defining the list of tools we're going to give our AI agent.

00:05.960 --> 00:07.800
So it's going to be a search agent.

00:07.800 --> 00:13.880
And it's going to be a list containing only one tool, which is going to be the search tool.

00:14.280 --> 00:19.440
Now I want to discuss what is this search tool object.

00:20.000 --> 00:23.360
Now in the previous video I showed you the search API.

00:23.560 --> 00:26.320
So how to use it in the AI playground.

00:26.360 --> 00:29.200
Now they have an SDK.

00:29.360 --> 00:31.920
We can programmatically use their API.

00:32.120 --> 00:35.440
All we need to do is to generate an API key and to use their SDK.

00:36.320 --> 00:43.960
Now if we want to use an LLM as a reasoning engine and to kind of get this behavior where the LLM has

00:44.000 --> 00:52.960
access to this API, to this SDK, then we need somehow to communicate to the LLM that it has in its

00:52.960 --> 00:55.880
disposal this kind of capability.

00:56.000 --> 01:00.120
So the ability to use a API right.

01:00.160 --> 01:05.880
So we need to tell the LLM maybe what is this tool name to use it.

01:05.920 --> 01:07.840
What arguments does it received?

01:07.880 --> 01:10.240
How does the output of this tool look like.

01:10.240 --> 01:12.960
So we need to give all this information to the LM.

01:13.080 --> 01:16.760
And this is exactly why LinkedIn created the tool class.

01:17.240 --> 01:24.560
Now the LinkedIn tool is a component that will allow the LMS to interact with external utilities or

01:24.600 --> 01:29.160
APIs by generating structured calls to those tools.

01:29.280 --> 01:35.920
And they're defined with the schema that is going to specify the name, the expected arguments, and

01:35.920 --> 01:40.880
it will allow the LM to generate calls with the structured inputs.

01:41.280 --> 01:45.200
Now the model does not execute the tool itself.

01:45.600 --> 01:49.320
Instead it only produces the arguments for the tool call.

01:49.480 --> 01:57.720
And the system running length chain will execute the tool and propagate back the output to the model.

01:57.720 --> 01:59.040
And this is very important.

01:59.040 --> 02:02.320
And this is what's going to happen actually in the agent executor.

02:02.360 --> 02:03.840
This is this is a quick spoiler.

02:04.040 --> 02:11.930
Now we can convert any Python function to a tool using the tool decorator which then the model can call

02:11.930 --> 02:18.130
by generating the appropriate arguments for the tool call, and it's going to include the tool name,

02:18.410 --> 02:20.050
the dictionary of arguments.

02:20.050 --> 02:27.610
And it's going to enable structured and reliable interaction between the LM and the external API.

02:28.170 --> 02:33.290
Now how will the LM know how to use this tool and when to call it.

02:33.290 --> 02:38.410
And usually the tool description will tell the LM what this tool is doing.

02:38.410 --> 02:41.130
So it will know when to use it.

02:41.130 --> 02:46.250
And in that LM call will also provide what arguments that this tool receive.

02:46.450 --> 02:47.890
So what are the names.

02:47.890 --> 02:48.930
What are the types.

02:49.050 --> 02:54.090
So eventually the LM has all the information of what it has in its disposal.

02:54.130 --> 02:59.650
What are the tools when to invoke them and what are they expecting and what are they outputting.

02:59.970 --> 03:00.490
All right.

03:00.530 --> 03:02.170
So back now to the code.

03:02.450 --> 03:07.090
The search object is from the link chain to build integration.

03:07.250 --> 03:16.250
And this is where the team, they took their SDK and they wrapped it as a link chain tool and basically

03:16.250 --> 03:20.730
created an object that is going to hold the description of this function.

03:20.730 --> 03:26.370
It's going to hold the arguments that it needs and the return value of this function.

03:26.690 --> 03:29.490
And that's what's going to be communicated to the LM.

03:29.930 --> 03:30.290
All right.

03:30.290 --> 03:32.610
So let me now run this in debug mode.

03:32.610 --> 03:36.570
And I want to examine the tools variable here.

03:36.570 --> 03:39.130
And I want to show you this tool object.

03:39.730 --> 03:43.130
So let us wait until we hit that breakpoint.

03:43.650 --> 03:49.490
And when we hit it let's open now the local variables here sorry the global variables.

03:49.930 --> 03:53.810
And we can see now we have the tools list here.

03:53.810 --> 03:58.290
It has only one element and it's called search here.

03:58.770 --> 04:05.610
Now this object here if we'll check out its attributes we can see we have an attribute called description.

04:05.650 --> 04:11.770
And here we can see description is a search engine optimized for comprehensive, accurate and trusted.

04:11.930 --> 04:14.010
And this text goes on and on.

04:14.010 --> 04:16.770
And this is the description of the search tool.

04:16.970 --> 04:20.860
So this is one thing that's going to be propagated to the LM column.

04:20.860 --> 04:23.740
So the LM would have this description of this video.

04:24.020 --> 04:31.260
Now we need to tell LM what kind of arguments these two receives so it can create the tool call.

04:31.300 --> 04:37.780
So here we can see we have here a dictionary where the keys are going to be the parameters that the

04:39.460 --> 04:40.860
search is going to receive.

04:40.860 --> 04:47.300
So we can see we have here query include domains exclude domains and other business logic that really

04:47.300 --> 04:48.180
may require.

04:48.580 --> 04:54.980
Now it's super important to note that the description and the arguments description, it's super important

04:54.980 --> 04:56.580
for us to be explicit.

04:56.580 --> 05:02.660
So if this is going to be ambiguous, the LM is going to have a hard time to crafting with the tool.

05:03.220 --> 05:09.180
And this is, by the way, one of the reasons why I used the link chain integration instead of simply

05:09.180 --> 05:15.940
importing the search client with the SDK and wrapping it as a selection tool, simply because the team

05:15.940 --> 05:22.180
knows their product the best and they can write the description for their arguments and for their function.

05:22.420 --> 05:25.140
A much better than I can write.

05:25.140 --> 05:29.500
So here you can see a bunch of other fields and that are the arguments.

05:29.700 --> 05:32.180
And, uh, yeah, this is pretty much it.

05:32.220 --> 05:33.140
Let me go show you.

05:33.140 --> 05:36.580
Now, um, this is the rest of the tool description here.

05:36.820 --> 05:38.540
Let me go show you the tool name.

05:38.540 --> 05:41.860
The tool name is going to be right over here.

05:41.860 --> 05:45.580
So we can see tool name is underscore search.

05:45.940 --> 05:55.540
So just to conclude we can think about a tool as a wrapper of a Python function that's going to have

05:55.540 --> 06:01.540
the fields of name description arguments and maybe some extra metadata.

06:01.580 --> 06:03.300
But that's pretty much it right.

06:03.340 --> 06:07.020
So and this is what's going to be propagated eventually to the LLM.

06:07.420 --> 06:09.420
And we're going to see this in action very soon.

06:10.100 --> 06:10.540
All right.

06:10.540 --> 06:17.220
So let me now go back to the code and let's go and examine the actual implementation of the search class

06:17.220 --> 06:17.540
here.

06:17.900 --> 06:21.260
And we can see that it inherits from base tool.

06:21.260 --> 06:23.020
And this is a link chain object.

06:23.020 --> 06:28.870
And this is going to have the interface of a having the attributes of name description arguments that

06:28.870 --> 06:30.030
we talked about earlier.

06:30.910 --> 06:37.470
And here in this description we can see some examples of how we can instantiate this object here, which

06:37.470 --> 06:38.870
is going to be a link chain tool.

06:38.990 --> 06:42.110
So we can also fixate some of the arguments.

06:42.110 --> 06:45.870
So there will be fixed when calling a search API.

06:47.190 --> 06:49.510
And here we can see for example the name.

06:49.510 --> 06:53.030
We can see the description and we can see the schema.

06:53.030 --> 06:56.350
So it's going to describe what kind of arguments it's going to receive.

06:56.630 --> 07:01.630
And some other descriptions of the other arguments that it's going to receive.

07:02.070 --> 07:09.590
Now when it's going to be executed then it's going to execute this underscore run function.

07:09.990 --> 07:15.470
And it's going to use the SDK to make the API call to the service.

07:15.710 --> 07:19.990
I remind you, the LM is not going to make this call to the API.

07:20.350 --> 07:23.790
It's going to only reason and decide that we need to call it.

07:23.790 --> 07:29.950
So the actual call and execution of this method is going to happen in our link chain application.

07:29.950 --> 07:33.550
So that's going to be in the agent executor which we're going to check out later.
