1
00:00:00,080 --> 00:00:01,680
Well, fancy seeing you again.

2
00:00:02,160 --> 00:00:07,280
I realize for you, this is just like the very next video along from videos you're already watching.

3
00:00:07,280 --> 00:00:14,160
But for me, this is me coming back like four months later to give you a latest update from the front

4
00:00:14,200 --> 00:00:20,120
lines to show you something super interesting that fits perfectly at this point in the course.

5
00:00:20,120 --> 00:00:24,760
So I'm slipping this extra in to show you something really cool.

6
00:00:24,800 --> 00:00:31,080
During week one, I explained that there's no standard definition of the word agents, and it can really

7
00:00:31,080 --> 00:00:32,960
mean whatever you want it to mean.

8
00:00:32,960 --> 00:00:36,880
But there are some hallmarks of common agent solutions.

9
00:00:37,160 --> 00:00:43,120
But I will say that over the course of the last few months, there has become a kind of evolving and

10
00:00:43,120 --> 00:00:48,200
somewhat solidifying definition of agents that people are using more and more in the field.

11
00:00:48,200 --> 00:00:50,000
And so I did want to get that across.

12
00:00:50,000 --> 00:00:53,240
And then I wanted to show you something to make it feel real.

13
00:00:53,240 --> 00:00:59,520
In the early days of agents, Sam Altman and OpenAI would sometimes describe them as AI systems that

14
00:00:59,520 --> 00:01:01,720
can do work for you independently.

15
00:01:01,760 --> 00:01:07,060
Thinking a bit about the GPT operator now called the GPT agent kind of paradigm.

16
00:01:07,420 --> 00:01:15,380
And then in early 2025, there became this consensus that came from Anthropic's seminal post and from

17
00:01:15,380 --> 00:01:23,140
Hugging face, that the right way to define a genetic AI was AI systems where an LLM controls the workflow.

18
00:01:23,300 --> 00:01:28,460
And that's been the sort of solidifying definition for most of 2025.

19
00:01:29,020 --> 00:01:35,100
But now there's a new evolving definition that has really taken hold in 2026.

20
00:01:35,100 --> 00:01:36,620
And that's what I want to explain.

21
00:01:36,620 --> 00:01:44,500
As of 2026, the most common definition of a genetic AI is it's where you have an LLM that's equipped

22
00:01:44,500 --> 00:01:50,220
with tools, and it runs those tools in a loop to achieve a goal.

23
00:01:50,380 --> 00:01:54,500
An LLM that runs tools in a loop to achieve a goal.

24
00:01:54,660 --> 00:01:57,860
And it's one of these things that you know it when you see it.

25
00:01:58,620 --> 00:02:03,860
And I highly recommend the tech writer Simon Willison, who has a terrific blog.

26
00:02:03,980 --> 00:02:07,190
And this is one of the points that he makes very clearly there.

27
00:02:07,190 --> 00:02:12,230
And when you're running such an agent system in a loop, this is what it feels like.

28
00:02:12,270 --> 00:02:18,070
You write some software it calls the LM, and then the LM is off in its loop.

29
00:02:18,270 --> 00:02:23,310
Calling, running, calling tools, calling tools until it's done and back comes the answer.

30
00:02:23,590 --> 00:02:28,790
It's always important, as an AI engineer, to keep in the back of your mind that even though it feels

31
00:02:28,790 --> 00:02:33,030
this way, this is the experience that you have as it's off doing its thing.

32
00:02:33,230 --> 00:02:38,830
What's actually happening is, of course, this what's actually happening is that you've written some

33
00:02:38,830 --> 00:02:43,870
software that is repeatedly calling an LM, and when they're stopping, reason is tool calls.

34
00:02:43,870 --> 00:02:46,310
You're calling the tool, you're calling the LM.

35
00:02:46,310 --> 00:02:50,510
Again, the LM is just something that generates likely tokens.

36
00:02:50,670 --> 00:02:56,750
And you are interpreting those tokens and using them to make tool calls and giving this kind of illusion

37
00:02:56,750 --> 00:03:02,590
that there is something out there that has the ability to be using these tools and keeping on going

38
00:03:02,630 --> 00:03:04,950
until it's satisfied that it's done the job.

39
00:03:04,950 --> 00:03:07,170
And so with that, let's see it in action.

40
00:03:07,170 --> 00:03:12,570
Let's go to cursor and build ourselves an LLM with tools in a loop to achieve a goal.

41
00:03:12,610 --> 00:03:14,170
Okay, here I am in cursor.

42
00:03:14,210 --> 00:03:16,530
I'm going into week one foundations.

43
00:03:16,530 --> 00:03:22,570
I'm going to the new five extra and extra addition to week one.

44
00:03:22,610 --> 00:03:31,930
The unreasonable effectiveness of the agent loop a little recap on what an agent is and making it real.

45
00:03:32,250 --> 00:03:38,370
I'm going to start with some imports and I'm loading Am and I trust at this point you are pros with

46
00:03:38,610 --> 00:03:39,010
EMV.

47
00:03:39,050 --> 00:03:40,410
I don't need to talk about that.

48
00:03:40,570 --> 00:03:44,690
I'm also importing this thing called Rich console, which is just a nice little library that lets you

49
00:03:44,730 --> 00:03:50,290
print to a terminal output and still have some colors in an easy way because that's going to look nice.

50
00:03:50,330 --> 00:03:50,610
All right.

51
00:03:50,610 --> 00:03:54,370
And in fact, so the way you do that is you call something called console dot print.

52
00:03:54,570 --> 00:03:59,290
And just just so that I can handle if that ever throws an exception or anything, I've just made this

53
00:03:59,330 --> 00:04:03,170
little utility show which tries to do a console dot print.

54
00:04:03,210 --> 00:04:07,210
Otherwise it just prints just a little simple way to show anything.

55
00:04:07,580 --> 00:04:08,500
Um, okay.

56
00:04:08,660 --> 00:04:11,580
And then the usual OpenAI's OpenAI that you know.

57
00:04:11,580 --> 00:04:12,020
Well.

58
00:04:12,340 --> 00:04:14,900
And now let me tell you about to dos.

59
00:04:15,020 --> 00:04:16,900
This is super simple.

60
00:04:16,900 --> 00:04:18,620
I've got two lists.

61
00:04:18,780 --> 00:04:22,220
One is called to dos and one is called completed to dos.

62
00:04:22,220 --> 00:04:26,580
We'll just have a list of strings of things I need to do, and completed will be trues and falses.

63
00:04:26,580 --> 00:04:27,660
If it's been done.

64
00:04:28,180 --> 00:04:33,460
And I've got a little function here, get to do report and it just prints out what's in that to dos

65
00:04:33,460 --> 00:04:33,740
list.

66
00:04:33,740 --> 00:04:36,580
So if I run that, it prints nothing.

67
00:04:37,060 --> 00:04:37,660
Okay.

68
00:04:38,100 --> 00:04:39,660
Nothing clever so far.

69
00:04:39,860 --> 00:04:40,620
Bear with me.

70
00:04:40,620 --> 00:04:41,900
This is going to deliver.

71
00:04:42,340 --> 00:04:44,940
Here is a function create to dos.

72
00:04:45,140 --> 00:04:50,580
It takes a set of descriptions a list of strings, and it adds them to the to dos.

73
00:04:50,580 --> 00:04:54,740
And it puts false in in the completed so that they're all not completed.

74
00:04:54,740 --> 00:04:57,380
And then it gets the report okay.

75
00:04:57,780 --> 00:04:59,260
And then another little function.

76
00:04:59,260 --> 00:05:06,100
The last of these called Mark completed, which takes an index and some notes on how it's being completed.

77
00:05:06,100 --> 00:05:08,060
And it just prints out what's happened.

78
00:05:08,300 --> 00:05:10,720
So let's see this in action again.

79
00:05:10,760 --> 00:05:14,360
We will empty to dos and completed and we will create some to dos.

80
00:05:14,560 --> 00:05:18,480
Buy groceries, finish extra lab, eat banana.

81
00:05:18,840 --> 00:05:20,200
I run that and look.

82
00:05:20,240 --> 00:05:24,120
It prints out this nice little to do list and formatted text to do.

83
00:05:24,120 --> 00:05:25,160
One is to buy groceries.

84
00:05:25,160 --> 00:05:27,400
To do two is finish the extra lab.

85
00:05:27,600 --> 00:05:30,920
And shockingly, three is to eat the banana.

86
00:05:31,360 --> 00:05:31,960
Okay.

87
00:05:32,200 --> 00:05:37,560
And now I am going to try marking complete the first item there.

88
00:05:37,600 --> 00:05:39,640
As with the comment of bought.

89
00:05:39,840 --> 00:05:41,320
Let's see what happens if I do that.

90
00:05:41,520 --> 00:05:45,560
Well bam, it prints out and you can see I've been a bit fancy with my formatting.

91
00:05:45,760 --> 00:05:52,160
It puts a strike a strike through the buy groceries and but the other two items are still there.

92
00:05:52,440 --> 00:05:53,720
It works great.

93
00:05:53,760 --> 00:05:55,200
Nothing about AI here.

94
00:05:55,200 --> 00:05:57,480
This is just like vanilla python.

95
00:05:57,480 --> 00:06:01,760
Just doing something to manage a to do list with two functions.

96
00:06:01,760 --> 00:06:03,240
That's all we've done.

97
00:06:03,920 --> 00:06:10,120
But we're going to give that as tools to an agent and put it in a loop.

98
00:06:10,160 --> 00:06:11,370
Well, you know the scoop.

99
00:06:11,370 --> 00:06:13,410
We have to come up with janky JSON.

100
00:06:13,450 --> 00:06:16,290
Here is JSON for create to do's.

101
00:06:16,330 --> 00:06:18,210
It simply describes that function.

102
00:06:18,250 --> 00:06:20,250
Add to do's from a list of descriptions.

103
00:06:20,370 --> 00:06:22,290
It describes the kind of data it needs.

104
00:06:22,290 --> 00:06:24,730
It's the JSON that's same as we use before.

105
00:06:25,130 --> 00:06:27,490
And this is the mark complete JSON.

106
00:06:27,970 --> 00:06:32,170
Feel free to take a look at it, but it says Mark completed to do at the position and return the full

107
00:06:32,170 --> 00:06:32,690
list.

108
00:06:33,010 --> 00:06:37,130
That's the description of each of the different fields it needs to provide.

109
00:06:37,330 --> 00:06:37,930
Done.

110
00:06:37,930 --> 00:06:40,650
And now we put that into one list of tools.

111
00:06:40,770 --> 00:06:43,930
Exactly as we did for the career conversation.

112
00:06:44,050 --> 00:06:44,890
That's it.

113
00:06:45,050 --> 00:06:47,890
Now time for running the tools in a loop.

114
00:06:47,930 --> 00:06:48,530
Okay.

115
00:06:48,810 --> 00:06:50,290
Handle tool calls.

116
00:06:50,490 --> 00:06:56,050
This function is exactly the same as the function from from the career conversation.

117
00:06:56,050 --> 00:06:59,450
And the reason I know it's exactly the same is I copied and pasted it in here.

118
00:06:59,610 --> 00:07:02,050
I think I might have taken out one thing that wasn't needed.

119
00:07:02,050 --> 00:07:04,490
And we probably don't need this this print statement here.

120
00:07:04,690 --> 00:07:06,210
That's not going to we don't need that.

121
00:07:06,210 --> 00:07:09,770
We can keep this as short and sharp as we can handle tool calls.

122
00:07:09,770 --> 00:07:11,370
That just iterates through.

123
00:07:11,370 --> 00:07:14,710
And you can see here it calls that that globals trick.

124
00:07:14,750 --> 00:07:18,630
That makes this a nice short and sharp pythonic function.

125
00:07:18,990 --> 00:07:20,790
And look at this function here.

126
00:07:20,790 --> 00:07:23,310
This is a function whose name is a loop.

127
00:07:23,310 --> 00:07:24,630
So we probably better look at it.

128
00:07:24,630 --> 00:07:30,350
I am saying while not done, while you're not finished, it's a while loop just like the other while

129
00:07:30,350 --> 00:07:30,710
loop.

130
00:07:31,190 --> 00:07:35,750
It then calls OpenAI create.

131
00:07:35,870 --> 00:07:39,790
I'm using what is for me right now the latest model, GPT 5.2.

132
00:07:39,830 --> 00:07:44,430
You can pick whatever model you want, might have different behavior, but but as you wish, it's going

133
00:07:44,430 --> 00:07:45,870
to pass in the messages.

134
00:07:46,110 --> 00:07:49,630
I'm going to take the tools that we've just created up here.

135
00:07:49,630 --> 00:07:54,910
And I'm saying reasoning effort is none for these latest reasoning models.

136
00:07:54,950 --> 00:07:57,550
We want it to be nice and quick for this to work well.

137
00:07:57,550 --> 00:08:03,070
So I don't want it to be going off and thinking and making extra tokens to describe a process.

138
00:08:03,590 --> 00:08:05,950
And then this is something that you're familiar with.

139
00:08:05,990 --> 00:08:15,240
We do finish reason is response reason, and if it wants to call a tool then we go ahead and call the

140
00:08:15,240 --> 00:08:17,120
tool and record the output.

141
00:08:17,120 --> 00:08:23,800
If it's decided it does not want to call a tool, then we say the loop is done because it's in a loop

142
00:08:23,800 --> 00:08:29,960
calling tools until it's done, and then we will print the results using that show thing that I wrote

143
00:08:29,960 --> 00:08:30,440
before.

144
00:08:30,560 --> 00:08:33,280
That just shows it in a formatted way or just prints it.

145
00:08:33,280 --> 00:08:35,400
Normally that is a loop.

146
00:08:35,600 --> 00:08:38,120
It's a very simple loop, a simple while loop.

147
00:08:38,200 --> 00:08:39,040
Let's try it.

148
00:08:39,040 --> 00:08:40,520
Let me give you a system message.

149
00:08:40,920 --> 00:08:46,560
You have a problem to solve using your to do tools to plan out the steps and then carrying out each

150
00:08:46,560 --> 00:08:49,200
step in turn, blah blah blah blah blah blah.

151
00:08:49,240 --> 00:08:51,600
Provide your solution in rich console markup.

152
00:08:51,640 --> 00:08:53,880
Do not ask the user questions, blah blah blah.

153
00:08:54,400 --> 00:09:00,320
Then the user message A train leaves Boston at 2 p.m. traveling 60 miles an hour.

154
00:09:00,360 --> 00:09:05,720
Another train leaves New York at 3 p.m., traveling 80 miles an hour towards Boston.

155
00:09:05,720 --> 00:09:07,040
When do they meet?

156
00:09:07,440 --> 00:09:13,240
That is what we're putting in messages that the system message and the user message and the usual list

157
00:09:13,240 --> 00:09:14,400
of dicts.

158
00:09:14,640 --> 00:09:15,640
I've done that.

159
00:09:15,940 --> 00:09:16,660
And now.

160
00:09:17,380 --> 00:09:21,300
And now I'm emptying out my to do's and completed.

161
00:09:21,300 --> 00:09:25,020
And I'm just gonna call this loop with those messages.

162
00:09:25,020 --> 00:09:26,540
That's all I'm doing.

163
00:09:26,540 --> 00:09:30,980
I'm just calling this loop with this set of messages right here.

164
00:09:31,140 --> 00:09:34,580
And it's equipped with those very simple to do tools.

165
00:09:35,020 --> 00:09:36,020
Let's see what happens.

166
00:09:36,020 --> 00:09:36,660
Here we go.

167
00:09:37,860 --> 00:09:38,700
Off it goes.

168
00:09:39,300 --> 00:09:40,300
Oh what's that.

169
00:09:40,580 --> 00:09:42,580
It's printed out a few things it wants to do.

170
00:09:43,180 --> 00:09:44,340
Interpret the problem.

171
00:09:44,340 --> 00:09:45,740
Set up variables.

172
00:09:46,060 --> 00:09:47,580
Estimate any missing quantity.

173
00:09:47,620 --> 00:09:48,260
Compute.

174
00:09:48,500 --> 00:09:49,460
Oh look at that.

175
00:09:49,780 --> 00:09:52,300
It's just doing things and I'm not touching it.

176
00:09:52,340 --> 00:09:53,140
It's doing things.

177
00:09:53,140 --> 00:09:54,420
It's crossing them off the list.

178
00:09:54,460 --> 00:09:55,420
Things are printing out.

179
00:09:55,420 --> 00:09:57,780
It's done all four to do's and bam!

180
00:09:57,780 --> 00:10:05,860
There's the answer that that is an LM in a loop with tools to achieve a goal.

181
00:10:05,860 --> 00:10:10,940
Now, of course, this isn't big news for you because you've seen things like Claude Code do this.

182
00:10:10,940 --> 00:10:14,020
And in fact, Claude code, if you've seen it looks very like this.

183
00:10:14,060 --> 00:10:19,830
It has to do's because I sort of cribbed the idea of having a to do list from Claud code.

184
00:10:20,270 --> 00:10:22,670
The thing that might be be news to you.

185
00:10:22,670 --> 00:10:28,830
The thing that you should recognize is how insanely easy it was to build this, how basic it was.

186
00:10:28,830 --> 00:10:30,950
We just built this from first principles.

187
00:10:30,950 --> 00:10:37,590
We just have an LLM that generates tokens, and we turned it into this thing that gives us the impression

188
00:10:37,590 --> 00:10:42,750
that there's there's something out there that's busy working and thinking and planning and tracking

189
00:10:42,750 --> 00:10:44,110
and crossing things off the list.

190
00:10:44,110 --> 00:10:50,310
But in fact, it is simply calling an LLM repeatedly in a while loop and giving it tools and letting

191
00:10:50,310 --> 00:10:52,710
it use the tools to make progress.

192
00:10:52,870 --> 00:10:58,310
And so that that is hopefully really solidifies it really makes it real for you, makes it concrete

193
00:10:58,310 --> 00:11:04,870
that you see that it's very easy to build an agent loop from first principles.

194
00:11:04,870 --> 00:11:09,910
And the other point to make, of course, is that it turns out that using these kinds of techniques

195
00:11:09,950 --> 00:11:12,190
results in better outcomes.

196
00:11:12,190 --> 00:11:17,270
It's kind of obvious in some ways, but it still it needs to be thought about a bit, just simply getting

197
00:11:17,270 --> 00:11:20,890
an LLM to generate tokens as the answer doesn't perform.

198
00:11:20,890 --> 00:11:27,170
As well as using these sorts of agentic techniques that causes it to take longer to work through and

199
00:11:27,170 --> 00:11:30,010
reason its way through a difficult problem.

200
00:11:30,010 --> 00:11:31,570
And that's why it's so powerful.

201
00:11:31,850 --> 00:11:36,690
But also, of course, if using these tools is actually doing something like creating a file or running

202
00:11:36,690 --> 00:11:42,770
something or calculating something, and you can add those sorts of tools in here and see it get better

203
00:11:42,770 --> 00:11:44,170
and better at what it's doing.

204
00:11:44,450 --> 00:11:44,970
Okay.

205
00:11:45,010 --> 00:11:49,410
But with that, that's a wrap on this great simple example.

206
00:11:49,530 --> 00:11:51,970
And there is of course, an exercise for you.

207
00:11:51,970 --> 00:11:53,250
And here's the exercise.

208
00:11:53,250 --> 00:11:59,170
You know, I'm not a fan of typing things in from scratch, from nothing, or trying to memorize things

209
00:11:59,170 --> 00:12:01,810
because it's just not the way that it works anymore.

210
00:12:01,930 --> 00:12:08,130
Ides and Llms can help autocomplete code so fast, it's more important to understand what's happening

211
00:12:08,170 --> 00:12:11,090
than to be able to memorize and type things out by rote.

212
00:12:11,330 --> 00:12:12,970
But here's an exception.

213
00:12:13,210 --> 00:12:13,730
Perhaps.

214
00:12:13,970 --> 00:12:21,940
I do think that it's incredibly beneficial for everybody to have had one crack at writing a simple agent

215
00:12:21,940 --> 00:12:28,180
loop from first principles, just using the OpenAI library and creating basically doing what I just

216
00:12:28,180 --> 00:12:28,900
did there.

217
00:12:29,060 --> 00:12:36,060
It's it's both very, very rewarding and satisfying, but it's also very instructive to see that coming

218
00:12:36,100 --> 00:12:38,340
together and really understand the nuts and bolts.

219
00:12:38,340 --> 00:12:42,620
So I challenge you now to start a new fresh Python notebook.

220
00:12:42,660 --> 00:12:47,580
Go through it and try and create your own agent loop from scratch.

221
00:12:47,580 --> 00:12:49,620
And of course refer back to this one.

222
00:12:49,660 --> 00:12:53,980
And from time to time, I mean, I copied and pasted that some of this, like the handle tool calls.

223
00:12:53,980 --> 00:12:58,180
I couldn't be bothered to write that again and nor should you, but there are parts of it like just

224
00:12:58,180 --> 00:12:59,780
the to do's and the completed.

225
00:12:59,780 --> 00:13:06,100
It's so interesting and fun to build that from scratch and then run it and see it come to life.

226
00:13:06,100 --> 00:13:11,900
And then think of some interesting different problems that you can give your LLM to see it reason its

227
00:13:11,940 --> 00:13:17,060
way through, and maybe add in some extra tools while you're doing it and have fun with it.

228
00:13:17,060 --> 00:13:23,420
And I hope you found this both interesting and revealing and hopefully also very satisfying.