WEBVTT

00:00.240 --> 00:00.760
All right.

00:00.760 --> 00:03.120
So now we want to invoke the graph.

00:03.440 --> 00:05.640
So let's write app dot invoke.

00:05.680 --> 00:07.360
And let's give it the input.

00:07.800 --> 00:11.960
The input is going to be a dictionary with the messages key.

00:12.200 --> 00:17.960
And this is going to be a list of human messages in the content here is going to be for example what

00:17.960 --> 00:19.600
is the weather in Tokyo.

00:19.920 --> 00:22.200
List it and then triple it.

00:23.200 --> 00:29.680
And because we need here some real time information here, we're expecting that the agent will first

00:29.680 --> 00:35.280
deduce that it needs to call the search tool to search for the weather in Tokyo.

00:35.520 --> 00:40.280
And then after we get this result, it needs to invoke another tool, the triple tool.

00:40.440 --> 00:44.600
So after it invokes both tools, it will be able to answer the question.

00:44.920 --> 00:46.880
So this is what we're expecting here.

00:47.560 --> 00:52.840
So let's go now and let's print the result and let's go.

00:52.960 --> 00:56.400
And we want to take the last message and to take the content.

00:57.760 --> 01:00.680
Let me change the index here to last the const.

01:01.000 --> 01:02.920
And this should run.

01:02.920 --> 01:04.400
And let's see what happens here.

01:13.920 --> 01:15.800
We're still waiting for our result.

01:17.240 --> 01:20.000
So far it looks like it's running and boom!

01:20.000 --> 01:21.920
Let's take a look at the output here.

01:22.160 --> 01:24.400
So this is the current weather in Tokyo.

01:24.640 --> 01:29.560
It listed a bunch of metrics and then it took the humidity which is 69.

01:29.560 --> 01:33.240
And it multiplied it by three which is 207.

01:33.560 --> 01:35.480
So I wasn't that explicit.

01:35.480 --> 01:38.840
So let me write what is the temperature in Tokyo listed.

01:38.840 --> 01:39.760
And then triple it.

01:39.760 --> 01:41.080
Let's see what we get there.

01:53.520 --> 01:54.760
So it's still running.

01:54.800 --> 01:59.080
Notice it runs a bit long because it makes a bunch of tool calls.

01:59.080 --> 02:01.720
So it first needs to reason which is an LM call.

02:01.760 --> 02:03.120
Then it needs to call the tool.

02:03.120 --> 02:04.480
Then it needs to reason again.

02:04.920 --> 02:05.680
And we got here.

02:05.680 --> 02:10.840
The current temperature in Tokyo is 15 Celsius and triple it giving 45.

02:11.200 --> 02:14.910
So the line graph agent is working as expected now.

02:15.110 --> 02:22.230
And I think now in order to understand a bit more about what's happening with the flow, let's go and

02:22.230 --> 02:29.830
open Langschmidt and let's check out the traces of the graph execution, and let's see the nodes execution.

02:29.830 --> 02:33.590
And the tool calls to really see it with our eyes.

02:34.030 --> 02:37.030
So I'll go here to the react function calling project.

02:37.030 --> 02:39.110
And you see we have here two traces.

02:40.190 --> 02:42.110
Let me go and open the second one.

02:43.510 --> 02:46.030
So here we see something actually very interesting.

02:46.030 --> 02:51.070
Right from the get go we see that the search tool was called twice.

02:51.230 --> 02:54.550
And maybe we should expect it to be called once.

02:54.550 --> 03:00.110
But for my experience, this kind of behavior is actually quite regular because because this is a search

03:00.110 --> 03:03.950
result, then sometimes we don't get the right result.

03:03.950 --> 03:07.670
And sometimes the information that we find online is not enough.

03:07.950 --> 03:14.350
So in that case, the agent is smart enough to detect it and to run the tool again until it gets the

03:14.350 --> 03:14.870
answer.

03:14.910 --> 03:20.590
And by the way, from my experience, a technique if you want to save those tool calls For example,

03:20.590 --> 03:24.590
in the cavity search tool we can add an argument of max results.

03:24.590 --> 03:27.510
So this is the number of results that will return us.

03:27.670 --> 03:33.590
So we can configure it to not be only one result but to be five results for example.

03:33.590 --> 03:37.430
And then one of those results for sure is going to have the answer that we want.

03:37.470 --> 03:38.830
I mean that's the heuristic.

03:38.830 --> 03:40.830
It's not for sure, but it's a heuristic.

03:42.350 --> 03:46.710
So let's go and check out the trace one by one from the beginning.

03:47.030 --> 03:49.630
Let's go and check out the agent node here.

03:49.630 --> 03:50.670
The agent reason.

03:51.030 --> 03:55.790
So we can see now that we have here um our system message.

03:55.790 --> 03:57.790
And we supplied both tools here.

03:57.790 --> 04:02.230
And we see we got the answer that we should invoke the search tool here.

04:02.230 --> 04:06.670
And we should invoke the search tool with the current temperature in Tokyo.

04:07.230 --> 04:12.390
So let's go and check out now the second node we should continue.

04:12.630 --> 04:14.750
So the should continue is actually not a node.

04:14.790 --> 04:16.790
It's the conditional edge function.

04:16.950 --> 04:19.710
And right over here we can see that this is the input it gets.

04:19.950 --> 04:24.110
It checks the last message which is going to be an AI tool call.

04:24.110 --> 04:26.470
And besides it should go to the Act node.

04:26.950 --> 04:36.230
So then the graph goes to execute the node where it invokes then executes the search function.

04:36.550 --> 04:38.390
So we can see it right over here.

04:38.630 --> 04:41.150
And the input is the current temperature in Tokyo.

04:41.430 --> 04:44.590
And here we got the result here.

04:44.790 --> 04:50.510
And notice that in this search query the content that we get doesn't really contain the temperature

04:50.510 --> 04:51.150
in Tokyo.

04:51.590 --> 04:57.070
So and this is really a non-helpful search result.

04:57.510 --> 05:02.710
So what happens then because we have an edge from the node to the agent region.

05:02.750 --> 05:06.430
We're then going to give the agent this result of this tool.

05:06.430 --> 05:11.430
And it's going to figure out whether it can return the answer or it needs to do something else.

05:11.790 --> 05:19.190
So we can see here we are giving also the tool result to the reasoning engine to the reasoning node.

05:19.390 --> 05:25.550
And then it decides that it needs to run another search with the current temperature in Tokyo.

05:25.550 --> 05:29.550
And this time we can see we have here an included domain here.

05:30.230 --> 05:37.590
So we can see here that after it goes to, the should continue conditional edge, and it decides that

05:37.590 --> 05:40.750
it needs now to go and do the Act node.

05:40.750 --> 05:43.910
Let me go and open that.

05:44.110 --> 05:45.430
You can see it's right over here.

05:45.470 --> 05:49.870
Act and let's go now to the second search result.

05:50.270 --> 05:51.510
Let's go for that.

05:56.230 --> 05:56.910
All right.

05:56.910 --> 06:05.910
So here we can see that in the content of the search query we have that we have 15°C which is much better

06:05.910 --> 06:06.670
than before.

06:07.270 --> 06:11.270
So now we need to go to the node.

06:11.270 --> 06:14.950
And now the agent reason is going to have the valid search here.

06:15.430 --> 06:22.750
And we can see now that it decides that it should call the triple function with the input num to be

06:22.790 --> 06:25.950
15, which is extracted from the previous tool call.

06:26.230 --> 06:29.550
So this is exactly what we wanted to happen.

06:29.870 --> 06:34.630
It then goes and executes the triple tool in the tool node.

06:34.630 --> 06:37.150
So it's going to receive the input of 15.

06:37.190 --> 06:39.420
Then the result is going to be 45.

06:39.700 --> 06:41.660
And I'm not going to go over it.

06:41.660 --> 06:42.660
It's pretty trivial.

06:42.660 --> 06:47.580
And I'm attaching to this video's resources, this trace, which I'm going to make public.

06:47.700 --> 06:48.300
Right.

06:48.340 --> 06:54.420
So at the end, the final node that is going to be execute is going to be the agent reason.

06:54.420 --> 06:57.540
And then it decides that it doesn't need to do anything right now.

06:57.540 --> 06:58.620
So it should finish.

06:59.820 --> 07:00.260
All right.

07:00.260 --> 07:04.300
So let me go and let me go and commit this code here.

07:04.740 --> 07:12.060
So let me add the files and let me commit now and let me call this commit graph.

07:12.820 --> 07:14.260
Going to push it to the repo.

07:16.140 --> 07:19.020
And you can find the code for this section.

07:19.060 --> 07:20.140
Let me go here.

07:21.820 --> 07:25.820
So this is the graph commit with all the code that we just wrote.

07:28.820 --> 07:30.180
I hope you enjoyed this section.

07:30.180 --> 07:36.300
And the entire goal of this section was to show you how easy it is to implement the react agent with

07:36.540 --> 07:37.100
graph.

07:37.100 --> 07:40.980
So not only are you using graph here, but we leverage function calling.

07:41.020 --> 07:45.820
And this actually gives us a lot of stability and better performance for our react agent.
