1
00:00:02,990 --> 00:00:08,600
So in this chapter, we are going to talk a little bit more about agents in long Chain.

2
00:00:09,470 --> 00:00:14,330
For me, the most important thing of this chapter is a.

3
00:00:15,370 --> 00:00:19,990
To tell you a few warnings regarding agents.

4
00:00:20,140 --> 00:00:30,130
So it is important for you to be aware that agents are not still a mature functionality in launching.

5
00:00:30,940 --> 00:00:38,740
So they are still in in a experimental phase, and until they improve, it is not advisable to use them

6
00:00:38,740 --> 00:00:40,960
in a professional application.

7
00:00:40,960 --> 00:00:43,810
So they are very popular.

8
00:00:43,810 --> 00:00:51,700
They created a lot of excitement at the beginning, but now we are seeing that in many occasions they

9
00:00:51,700 --> 00:00:56,080
are failing when we are trying to do serious things with them.

10
00:00:56,080 --> 00:01:05,200
So one thing is like, you know, like a toy application, like a game application, like a non serious

11
00:01:05,200 --> 00:01:08,500
application and like a hobby application.

12
00:01:08,500 --> 00:01:15,850
Another thing is a professional application where a customer is paying you to develop it or whatever,

13
00:01:15,850 --> 00:01:17,770
right, or for your startup or whatever.

14
00:01:17,770 --> 00:01:26,770
So careful with agents are appealing, are interesting, but they are still not 100% mature.

15
00:01:27,840 --> 00:01:33,600
Maybe they will soon, but at this time they are still not 100% mature.

16
00:01:33,600 --> 00:01:41,280
So using agents A also is relatively expensive in terms of OpenAI.

17
00:01:41,310 --> 00:01:50,430
This is another thing you need to be aware of, uh, when you, uh, make a different operations with

18
00:01:50,430 --> 00:01:57,480
agents in OpenAI, with ChatGPT, this is going to be more expensive than usual operations.

19
00:01:57,840 --> 00:02:07,020
A and finally, agents tend to break or get lost in infinite loops if they are not ask a question related

20
00:02:07,020 --> 00:02:09,810
to the tools they have access to.

21
00:02:09,810 --> 00:02:12,420
We are going to see an example now.

22
00:02:12,600 --> 00:02:15,360
But this is very important because.

23
00:02:16,140 --> 00:02:24,900
If your application goes into an infinite loop and you have this application connected to OpenAI or

24
00:02:24,900 --> 00:02:30,240
any other private LM model, that is going to cause you a lot of money.

25
00:02:30,240 --> 00:02:32,490
So you have to be extremely careful with that.

26
00:02:32,490 --> 00:02:39,690
And every time you work with agents, you need to limit the maximum number of iterations.

27
00:02:39,690 --> 00:02:47,100
We are going to see that in the example that they can make in order to prevent a possible disasters,

28
00:02:47,100 --> 00:02:49,380
like the one I told you.

29
00:02:49,380 --> 00:02:56,790
So in the exercise of today, A, we are going to play around a little bit with agents.

30
00:02:56,790 --> 00:03:04,380
Again, we want to create an LM application that autonomously autonomous, autonomously decides which

31
00:03:04,380 --> 00:03:08,310
tool it will use to solve the problem we present to to it.

32
00:03:08,310 --> 00:03:12,480
So this is the keyword autonomously okay.

33
00:03:12,720 --> 00:03:17,040
So we are going to use a long chain agents.

34
00:03:17,040 --> 00:03:22,260
Initially we are going to create a very simple one very similar to one you already know.

35
00:03:22,260 --> 00:03:29,430
And then we will create a customized agent based on a very simple drag application.

36
00:03:29,430 --> 00:03:38,430
So in the right side of the screen first you have our classic, you know, a m file connection.

37
00:03:38,430 --> 00:03:44,850
So we can, uh, communicate with the OpenAI API and use ChatGPT.

38
00:03:44,970 --> 00:03:50,730
The initial part of this exercise is just a very simple drag application.

39
00:03:51,240 --> 00:03:53,460
So you are already familiar with it.

40
00:03:53,730 --> 00:03:57,180
Uh, we we create the instance of the LM model.

41
00:03:57,480 --> 00:04:02,940
We load a text file, which is going to be our private document.

42
00:04:03,030 --> 00:04:09,690
We divide this document into small chunks with a text splitter.

43
00:04:09,690 --> 00:04:19,769
And finally we are going to load these, uh, chunks of text converted into numbers to embeddings.

44
00:04:19,769 --> 00:04:23,070
We are going to load the embeddings into a vector database.

45
00:04:23,920 --> 00:04:25,030
So.

46
00:04:27,220 --> 00:04:32,470
Once we have that here, you have our typical chain.

47
00:04:33,230 --> 00:04:39,500
The retrieval QA chain in order to make questions to to this private document.

48
00:04:39,500 --> 00:04:40,310
Okay.

49
00:04:40,970 --> 00:04:50,330
So now we are going to see how we can do that with an agent instead of using the default chain we were

50
00:04:50,330 --> 00:04:51,140
using before.

51
00:04:51,980 --> 00:04:57,560
Before doing that, we are going to create a simple agent.

52
00:04:57,590 --> 00:05:06,470
So in order to one of them, the most popular uses of agents, if you remember, is that we provide

53
00:05:06,590 --> 00:05:15,860
the agent with a number of tools, and the agent is going to decide, uh, which tool it will use depending

54
00:05:15,860 --> 00:05:18,080
on the question we make.

55
00:05:18,780 --> 00:05:26,580
So in this case, to simplify that to the maximum level, we are going to provide just one tool.

56
00:05:26,580 --> 00:05:31,950
So our tool is going to be the LM math which is like a math calculator tool.

57
00:05:31,950 --> 00:05:38,700
In order to to to be able to play with it, you need to install this, uh, plugin before.

58
00:05:38,700 --> 00:05:43,110
And once you have it, you know, you just define the, the tools.

59
00:05:43,110 --> 00:05:49,230
And once you have defined the tools, you can initialize the agent, as you remember with the LM, the

60
00:05:49,230 --> 00:05:56,220
tools, the LM model, etc., etc., etc. the agent type is going to be the most popular, one is going

61
00:05:56,220 --> 00:05:56,790
to be true.

62
00:05:56,790 --> 00:06:01,590
So we can see what is happening in the background and we are going to set.

63
00:06:02,230 --> 00:06:08,230
Max iterations to three, so we are preventing possible loops.

64
00:06:08,740 --> 00:06:10,810
So you will see one loop here.

65
00:06:10,810 --> 00:06:16,720
So first we are going to check this agent with a math question.

66
00:06:16,930 --> 00:06:20,260
If we make a math question the agent doesn't have any problem.

67
00:06:20,260 --> 00:06:23,110
Immediately is going to use the tool.

68
00:06:23,110 --> 00:06:31,090
You know the calculator is going to provide a good response in a very fast a way.

69
00:06:31,570 --> 00:06:37,780
But what happens if we make a question that is not related with math?

70
00:06:38,740 --> 00:06:46,570
So the agent is going to try to find a tool able to respond.

71
00:06:46,570 --> 00:06:48,790
Our question he is trying.

72
00:06:48,790 --> 00:06:55,540
If you see here he's trying to use the Google tool, but Google tool is not installed for this agent.

73
00:06:55,540 --> 00:07:02,320
So he's, you know, hitting errors, but you see that he's hitting error and trying again and trying

74
00:07:02,320 --> 00:07:02,830
again.

75
00:07:02,830 --> 00:07:12,280
And he will continue until the infinite if we haven't, uh, configured the max iteration number to

76
00:07:12,280 --> 00:07:12,580
three.

77
00:07:12,580 --> 00:07:17,110
So once it hits the third, uh, iteration, it stop.

78
00:07:17,350 --> 00:07:17,800
Okay.

79
00:07:17,800 --> 00:07:24,070
So here you have the error message agent stop due to iteration limit okay.

80
00:07:25,330 --> 00:07:31,810
So after this very simple example, just a reminder of how agents work.

81
00:07:31,900 --> 00:07:36,250
We are going to create a custom agent that is going to.

82
00:07:37,130 --> 00:07:47,270
A work as our, uh, default chain in the in the in the beginning of this, uh, exercise.

83
00:07:47,330 --> 00:07:55,760
So I am not going into the details, but the only point you need to keep in mind is that our tool,

84
00:07:55,760 --> 00:08:02,690
we are creating a custom tool here, this custom tool, what it does is it is going to search, you

85
00:08:02,690 --> 00:08:05,630
know, through our private document.

86
00:08:05,630 --> 00:08:12,560
And the most important thing to to keep in mind is that it is making use of our vector database.

87
00:08:12,560 --> 00:08:18,710
This store embeddings is the vector database we have created.

88
00:08:19,940 --> 00:08:23,330
Here in our rug application.

89
00:08:23,630 --> 00:08:27,050
So if we a.

90
00:08:28,610 --> 00:08:29,600
Uh, proceed.

91
00:08:29,600 --> 00:08:33,169
We define the agent, you know, with initialize agent.

92
00:08:33,200 --> 00:08:40,370
Uh, now, and we are using the tools with with the custom tool we have provided.

93
00:08:40,370 --> 00:08:43,940
So a maximum iteration three.

94
00:08:43,940 --> 00:08:56,630
If we ask a question, this, uh, agent is going to make use of the, uh, article search tool, which

95
00:08:56,630 --> 00:09:05,420
is the name of our custom tool and is going to find the answer we are looking for, which is a summary

96
00:09:05,420 --> 00:09:06,740
of this article.

97
00:09:07,040 --> 00:09:14,840
So apart from having this, uh, working code for you to play around and to experiment, the most important

98
00:09:14,840 --> 00:09:20,990
thing of this chapter is to remember the warnings around agents.

99
00:09:20,990 --> 00:09:29,480
So careful with agents are very interesting, a very appealing to most developers until you find out

100
00:09:29,480 --> 00:09:32,990
that in a production environment they can fail.

101
00:09:32,990 --> 00:09:35,150
So careful with them right now.

