WEBVTT

00:01.000 --> 00:05.040
So let me now go and accept all of the changes.

00:07.080 --> 00:10.640
And let me run everything in debug here.

00:10.800 --> 00:16.880
So I want to debug this to show you exactly what is going to happen with the intermediate results.

00:17.320 --> 00:20.440
So we can see first things first, the call to the LM.

00:20.480 --> 00:23.600
The first call is what is the length of the word dog.

00:23.600 --> 00:25.720
And I put a breakpoint here.

00:25.800 --> 00:30.960
So once the AI will return a message we can go and check it.

00:33.680 --> 00:34.120
Cool.

00:34.120 --> 00:35.480
So we got a response.

00:35.480 --> 00:41.000
Let me show you all the local variables and the variable AI message.

00:41.200 --> 00:42.960
Let's take a look at all the fields.

00:43.120 --> 00:47.360
And we're looking for the attribute in the field of tool calls.

00:47.800 --> 00:50.840
We can see it right over here in the middle.

00:51.720 --> 00:52.920
Let me go and open it.

00:52.920 --> 00:56.680
And we can see this is a list containing one element.

00:57.000 --> 01:01.600
And in that element we have all of the information about the tool call.

01:01.640 --> 01:05.720
So the function we want to invoke is get text length.

01:06.040 --> 01:12.730
The arguments is going to be dictionary containing the keyword text and the input dog.

01:12.890 --> 01:15.210
We can also see the tool called id here.

01:15.530 --> 01:15.890
Cool.

01:15.890 --> 01:16.650
So let's continue.

01:16.690 --> 01:18.410
Now the execution step by step.

01:18.690 --> 01:22.210
So the number of tool calls is greater than one.

01:22.210 --> 01:25.650
So we are going to execute this if statement.

01:25.810 --> 01:31.610
And first thing is we want to append to the messages list the AI message with all of the information

01:31.610 --> 01:32.650
about the tool call.

01:32.690 --> 01:35.290
So this is going to be our agent trajectory.

01:35.290 --> 01:39.010
And now we want to iterate over the tool calls which we have only one.

01:39.210 --> 01:41.490
And we want to extract from that tool.

01:41.490 --> 01:44.610
Call the name the arguments and the ID.

01:44.890 --> 01:49.210
So let me show you again a the structure of the tool call.

01:49.410 --> 01:50.850
So we're going to do that.

01:51.050 --> 01:56.490
And once we have that we'll find all the variables we need in order to invoke the tool.

01:56.850 --> 02:01.690
So now we want to get the actual Python function to invoke.

02:01.690 --> 02:05.050
So we simply use the helper function we wrote earlier.

02:05.090 --> 02:06.290
Find tool by name.

02:06.610 --> 02:13.810
And the tool to use variable is going to contain the structured invokable in class.

02:14.010 --> 02:16.650
So we can simply use the invoke method on it.

02:17.900 --> 02:24.460
And then we simply go and invoke that with the input and we get back an observable.

02:24.700 --> 02:29.500
So let me go and put a breakpoint in in the tool that we wrote.

02:29.500 --> 02:33.460
So let me go up here and this is here.

02:33.500 --> 02:38.860
Let me put a breakpoint here and let me continue the run and let me continue the run.

02:42.380 --> 02:42.900
All right.

02:42.900 --> 02:45.220
So we can see we got here.

02:45.220 --> 02:46.940
Let's go and run everything.

02:46.940 --> 02:52.140
And the result we get is the length of this text here.

02:52.420 --> 02:54.700
So let's go and continue.

02:54.860 --> 02:56.380
And the result should be three.

02:57.620 --> 02:59.980
And we can see here in the observation.

02:59.980 --> 03:02.220
Let's go and check out this observation here.

03:02.220 --> 03:03.500
This observation is three.

03:03.740 --> 03:04.260
Cool.

03:04.260 --> 03:08.980
So now we want to append the observation the result of the tool execution.

03:09.020 --> 03:11.180
We want to append it to the message list.

03:11.580 --> 03:17.580
And now we want to go and to continue the iteration on the tool calls which we don't have anymore.

03:17.580 --> 03:20.860
So we're going to finish the iteration in this for loop over here.

03:20.860 --> 03:25.500
And we're going to hit this continue and continue statement.

03:25.740 --> 03:28.470
So let's go and click continue.

03:28.750 --> 03:29.310
Right.

03:29.310 --> 03:30.590
So now we've finished.

03:30.630 --> 03:32.950
Now the iteration over the tool calls.

03:32.990 --> 03:39.110
Now we're left to do another iteration in the while loop with the message history containing the agent

03:39.110 --> 03:41.710
trajectory and all the intermediate results.

03:42.270 --> 03:47.790
So let me show you the messages here so we can see we have a list of three elements.

03:47.790 --> 03:49.790
The first one is the human message.

03:49.990 --> 03:55.150
The second one is the AI message with all the tool calling information.

03:55.150 --> 04:00.110
And the third message is a tool message containing the result of the tool execution.

04:00.470 --> 04:00.750
All right.

04:00.750 --> 04:02.550
So let's invoke the LM call.

04:03.030 --> 04:04.830
Now we're waiting for a response.

04:05.070 --> 04:09.350
And now the response should have zero two calls when we get it back.

04:09.630 --> 04:11.830
So let's take a look at the AI message.

04:11.830 --> 04:12.870
We get back here.

04:13.190 --> 04:15.950
And now let's take a look at the tool calls field.

04:15.950 --> 04:18.430
And we can see it's actually an empty list.

04:18.630 --> 04:24.110
And that's why we are going to print the answer and break and finish the run here.

04:24.790 --> 04:30.790
And we can see that the final answer of the LM is the length of the word dog is three characters.

04:30.950 --> 04:35.390
So we have our react agent working with function calling.
