1
00:00:00,160 --> 00:00:03,520
And a very warm welcome to week four, day three.

2
00:00:03,560 --> 00:00:04,200
Here we are.

3
00:00:04,240 --> 00:00:09,280
This is going to be the time that Landgraf is going to start to pay dividends.

4
00:00:09,280 --> 00:00:13,560
The investment that we've made in understanding the new terminology is going to come together, and

5
00:00:13,560 --> 00:00:15,240
we're going to see some real value.

6
00:00:15,480 --> 00:00:18,960
But first, as always, I have to give you a quick recap.

7
00:00:19,000 --> 00:00:22,720
Again, I'm going to get bored of it, but it's better that you get bored of it and you understand it.

8
00:00:22,840 --> 00:00:29,880
So before you can call Graph Invoke, which is how you kick off your graph, you have to define it.

9
00:00:29,920 --> 00:00:33,240
And defining it is these five steps to find your state class.

10
00:00:33,240 --> 00:00:34,240
The graph Builder.

11
00:00:34,240 --> 00:00:37,240
Create a node edges and compile the graph.

12
00:00:37,440 --> 00:00:38,840
Just a quick refresher.

13
00:00:38,840 --> 00:00:41,080
I'm sure you've got this all committed to memory now.

14
00:00:41,400 --> 00:00:43,440
Okay, so what are we actually going to cover today?

15
00:00:43,560 --> 00:00:48,160
Well, there's going to be a few ways we're going to go deeper into the world of graph.

16
00:00:48,200 --> 00:00:52,920
First of all, we're going to look at Lang Smith and have a moment of understanding how information

17
00:00:52,920 --> 00:00:54,360
gets logged there.

18
00:00:54,600 --> 00:00:59,240
We're then going to look at tools tool calling something that we've done many times now using the out

19
00:00:59,280 --> 00:01:02,000
of the box tools that come with Lang graph.

20
00:01:02,160 --> 00:01:05,680
And then we're going to build a custom tool again as we've done many times.

21
00:01:05,680 --> 00:01:07,000
So we'll see that working.

22
00:01:07,200 --> 00:01:12,610
And we'll finally end with checkpointing which is a very important part of it.

23
00:01:12,650 --> 00:01:13,290
Indeed.

24
00:01:13,770 --> 00:01:18,170
And to to tee that up to motivate checkpointing.

25
00:01:18,170 --> 00:01:21,290
I want to talk for a moment about something called the super step.

26
00:01:21,410 --> 00:01:23,050
So what's a super step?

27
00:01:23,290 --> 00:01:24,650
Well, a super step.

28
00:01:24,690 --> 00:01:25,770
Start with a docs.

29
00:01:25,810 --> 00:01:26,370
A super step.

30
00:01:26,370 --> 00:01:30,290
They define as a single iteration over the graph nodes.

31
00:01:30,290 --> 00:01:33,290
Nodes that run in parallel a part of the same super step.

32
00:01:33,410 --> 00:01:36,690
Nodes that run sequentially belong to a separate super step.

33
00:01:37,090 --> 00:01:38,770
So what does that mean exactly?

34
00:01:38,810 --> 00:01:40,690
Now this is super, super important.

35
00:01:40,730 --> 00:01:42,370
Super steps are super important.

36
00:01:42,370 --> 00:01:44,410
And it's something which you have to get your head around.

37
00:01:44,410 --> 00:01:48,770
And it's it's a it's a definitely may not be what you're expecting.

38
00:01:49,570 --> 00:01:59,610
So a graph defines one set of interactions between like agents and their use of tools and perhaps delegating

39
00:01:59,650 --> 00:02:00,930
to other agents.

40
00:02:00,930 --> 00:02:05,810
If you think back to the handoff of, uh, OpenAI agents SDK.

41
00:02:06,330 --> 00:02:10,450
So one invocation of the graph is just one kind of step.

42
00:02:10,450 --> 00:02:17,370
It's like when the user says one message, putting that message to our LLM, that is one invocation

43
00:02:17,370 --> 00:02:23,250
of the entire graph all the way through from top to bottom, and if then it comes back to the user with

44
00:02:23,250 --> 00:02:25,770
a response and the user types in another message.

45
00:02:25,770 --> 00:02:28,210
That's another invocation of the whole graph.

46
00:02:28,210 --> 00:02:32,090
And each of these invocations is a superstep.

47
00:02:32,130 --> 00:02:35,210
Every time you invoke the graph, that is a superstep.

48
00:02:35,450 --> 00:02:39,970
And so yeah, it's important to get your head around it, because you might initially think that maybe

49
00:02:39,970 --> 00:02:45,170
you could imagine that a node is like a human and a node is a chatbot, and that a graph is human and

50
00:02:45,170 --> 00:02:46,890
chatbot going backwards and forwards.

51
00:02:46,890 --> 00:02:51,330
But no, every time that there is that kind of human interaction, you should think of that as a whole

52
00:02:51,330 --> 00:02:52,650
invocation of the graph.

53
00:02:52,650 --> 00:02:57,850
Or in some situations, you might be resuming the graph from one point if it was paused for for a human

54
00:02:57,850 --> 00:02:58,570
to respond.

55
00:02:58,650 --> 00:03:04,690
So there's various ways of doing it, but each of these interactions is considered an entire superstep

56
00:03:04,890 --> 00:03:06,290
within a superstep.

57
00:03:06,330 --> 00:03:13,250
One one invocation of the graph belongs to to activities which happen in parallel as part of that step.

58
00:03:14,130 --> 00:03:20,730
So this is a bit repetitive, but yeah, the graph describes one full superstep an interaction between

59
00:03:20,730 --> 00:03:25,490
agents and tools and potentially multiple agents to achieve an outcome.

60
00:03:26,250 --> 00:03:28,170
Every user interaction.

61
00:03:28,380 --> 00:03:30,700
It's a fresh invoke call.

62
00:03:30,700 --> 00:03:33,460
It's a fresh time that you're calling Graph Invoke.

63
00:03:33,500 --> 00:03:35,220
There's also a graph resume.

64
00:03:35,220 --> 00:03:36,380
But but the point remains.

65
00:03:36,380 --> 00:03:37,780
It's a fresh call.

66
00:03:38,420 --> 00:03:44,460
And the reducer that I talked about, the thing that is able to combine the state that comes out of

67
00:03:44,460 --> 00:03:50,460
a call with the original state that applies during carrying out a single super step.

68
00:03:50,460 --> 00:03:53,180
That is how state is managed across the graph.

69
00:03:53,220 --> 00:03:57,740
That's how if multiple nodes update the same state state, it gets combined at the end.

70
00:03:58,020 --> 00:04:00,020
That's what the reducer is handling.

71
00:04:00,020 --> 00:04:06,780
But the reducer doesn't handle, uh, the separate super steps a separate super step is an entirely

72
00:04:06,780 --> 00:04:09,740
fresh invocation of the graph.

73
00:04:10,740 --> 00:04:13,740
So that's going to be a bit confusing.

74
00:04:13,740 --> 00:04:16,620
So what does that mean to show that visually.

75
00:04:16,660 --> 00:04:18,540
Next I want to draw you a diagram.

76
00:04:18,540 --> 00:04:24,620
So with this diagram it's now all going to become crystal clear I'm confident it all begins with defining

77
00:04:24,620 --> 00:04:25,180
the graph.

78
00:04:25,180 --> 00:04:30,460
As I keep saying this is the five things you got to do, including defining the nodes, the edges,

79
00:04:30,460 --> 00:04:31,780
and compiling the graph.

80
00:04:31,780 --> 00:04:32,900
And then you're set.

81
00:04:33,460 --> 00:04:39,100
The next thing you do is perhaps the user has a question, and that question is what you then use to

82
00:04:39,140 --> 00:04:40,780
invoke the graph.

83
00:04:40,940 --> 00:04:41,500
There you go.

84
00:04:41,500 --> 00:04:43,220
And that is called a super step.

85
00:04:43,260 --> 00:04:48,900
And out pops some kind of an answer after the agents and tools have done their thing, and then the

86
00:04:48,900 --> 00:04:51,540
user says something, a follow up question, they have something else.

87
00:04:51,540 --> 00:04:53,500
And that would be another super step.

88
00:04:54,060 --> 00:04:58,460
And then that might happen again with another follow up or with another external activity.

89
00:04:58,620 --> 00:05:03,220
Each of these are super steps, complete invocations of the graph.

90
00:05:03,420 --> 00:05:07,940
So just to make that really obvious, I'm putting a little picture of a graph by each one.

91
00:05:07,940 --> 00:05:11,420
The whole graph is is invoked each time.

92
00:05:11,900 --> 00:05:14,300
And that is what it means to have a super step.

93
00:05:14,500 --> 00:05:16,020
And why am I going on about this?

94
00:05:16,020 --> 00:05:22,140
Because when it comes to memory, when it comes to preserving context between these different calls,

95
00:05:22,660 --> 00:05:28,220
we need to involve something called checkpointing, which is something that landgraaf makes available

96
00:05:28,220 --> 00:05:35,900
to us to be able to keep track, to sort of freeze a record of the state after each super step.

97
00:05:35,900 --> 00:05:42,020
So we've got that tracked, and then next time we call a super step, it can recall the state exactly

98
00:05:42,020 --> 00:05:43,260
as it was Checkpointed.

99
00:05:43,580 --> 00:05:47,500
And that is one of the things that we're going to be doing in the lab right now.