1
00:00:00,000 --> 00:00:08,260
Welcome to this video on Build LLM Agents with Tools.

2
00:00:08,260 --> 00:00:12,939
In this video, you will learn the first steps in manual tool calling. You'll begin by

3
00:00:12,939 --> 00:00:18,360
initializing the chat model for tool interactions. You'll then define and bind custom tools

4
00:00:18,360 --> 00:00:23,659
to the LLM and add more tools for expanded functionality. Finally, you will use mapping

5
00:00:23,659 --> 00:00:27,219
dictionaries for dynamic function calls.

6
00:00:27,219 --> 00:00:32,259
In this video, you will enable an LLM to manually call a tool. This is a key building block

7
00:00:32,259 --> 00:00:36,939
for transforming a basic model into a real, interactive agent capable of engaging with

8
00:00:36,939 --> 00:00:39,380
the real world.

9
00:00:39,380 --> 00:00:43,380
First begin by building an agent that can do simple arithmetic operations using tools

10
00:00:43,380 --> 00:00:48,619
for addition, subtraction, and multiplication. In this case, you'll take an LLM and give

11
00:00:48,619 --> 00:00:54,259
it access to a set of tools. For example, if the input query is, what is 3 plus 2? The

12
00:00:54,259 --> 00:00:58,740
LLM will first extract the parameters, which are 3 and 2, and determine which tool to

13
00:00:58,740 --> 00:01:04,059
call. Next, the parameters are fed into the selected tool, which then processes the input

14
00:01:04,059 --> 00:01:08,779
and generates the output. Finally, the result is returned to the LLM, which combines this

15
00:01:08,779 --> 00:01:14,819
information to produce the final response. The addition of 3 and 2 is 5.

16
00:01:14,819 --> 00:01:20,220
Let's initialize the chat model to set up the LLM for tool interactions. First, import

17
00:01:20,220 --> 00:01:26,779
initChatModel from LangChain's ChatModels module. This function handles all the setup

18
00:01:26,779 --> 00:01:33,339
needed to connect to a chat model. Next, load GPT 4.0 mini with model underscore provider

19
00:01:33,339 --> 00:01:39,099
equals openAI, creating an object that can send and receive messages. Store this object

20
00:01:39,099 --> 00:01:44,819
in a variable called LLM. From this point on, whenever you see LLM dot invoke, it means

21
00:01:44,819 --> 00:01:50,099
you're interacting with the same model instance. In the diagram, the LLM box represents this

22
00:01:50,099 --> 00:01:55,699
LLM object, the central hub for all tool calls and user queries.

23
00:01:55,699 --> 00:02:00,860
With the model now live, the next step is to define a custom tool that the LLM can call.

24
00:02:00,860 --> 00:02:06,339
First, enable the model to perform basic arithmetic by providing it with a simple addition tool.

25
00:02:06,339 --> 00:02:11,619
Second, import the atTool decorator. This tells LangChain that the function can be called

26
00:02:11,619 --> 00:02:15,740
by the model. Next, define a function named add that takes

27
00:02:15,740 --> 00:02:21,699
two integers a and b and returns their sum. The doc string add a and b is what the model

28
00:02:21,699 --> 00:02:27,619
uses to determine when to use this tool. At this point, the tool is defined and ready,

29
00:02:27,619 --> 00:02:30,500
but it hasn't been connected to the model yet.

30
00:02:30,500 --> 00:02:36,220
Next, connect the add function to the model so it recognizes it as a callable tool. To

31
00:02:36,220 --> 00:02:41,339
do this, first place the add function in a list of tools. Then, bind this list to the

32
00:02:41,339 --> 00:02:45,899
chat model, creating a new object called LLMWithTools.

33
00:02:45,899 --> 00:02:49,740
This wraps the original LLM in a way that makes it aware of every function in the tools

34
00:02:49,740 --> 00:02:54,860
list. From this point on, whenever the call is invoked, the model will recognize and use

35
00:02:54,860 --> 00:02:59,059
the add tool whenever it needs to compute a sum.

36
00:02:59,059 --> 00:03:04,979
Let's add more tools to the LLM. First, create a subtract tool for basic subtraction. Similarly,

37
00:03:04,979 --> 00:03:10,899
create a multiplication tool to handle multiplication. Later on, you will need to call a function

38
00:03:10,899 --> 00:03:15,699
dynamically using its name. To achieve this, first create a mapping dictionary that links

39
00:03:15,699 --> 00:03:19,660
tool names as strings to their corresponding tool functions.

40
00:03:19,660 --> 00:03:25,059
Next, define the input arguments as a dictionary, where the keys match the function's parameter

41
00:03:25,059 --> 00:03:30,699
names. For example, a equals 1 and b equals 2. Then, call the function by using the tool

42
00:03:30,699 --> 00:03:36,380
name as the key, for example add, to access the function from the mapping dictionary.

43
00:03:36,380 --> 00:03:41,100
Finally, use invoke(Input) to call the function which automatically matches the dictionary

44
00:03:41,100 --> 00:03:45,699
keys a and b to the function's parameters and executes the tool.

45
00:03:45,699 --> 00:03:51,500
Next, create a list of tools that includes the add, subtract, and multiply functions.

46
00:03:51,500 --> 00:03:56,100
You can then bind this list to the model, allowing the LLM to recognize and use these

47
00:03:56,100 --> 00:03:58,539
tools as needed.

48
00:03:58,539 --> 00:04:03,380
In this video, you learned how to transform LLMs into interactive agents by integrating

49
00:04:03,380 --> 00:04:07,500
custom tools, enabling more context-aware responses.

50
00:04:07,500 --> 00:04:13,860
Set up chat models to handle real-world inputs, allowing the LLM to process user queries accurately.

51
00:04:13,860 --> 00:04:17,579
Create and connect tools such as addition, subtraction, and multiplication functions

52
00:04:17,579 --> 00:04:20,079
for dynamic calculations.

53
00:04:20,079 --> 00:04:25,619
Use mapping dictionaries for flexible, name-based function execution, expanding the LLM's

54
00:04:25,619 --> 00:04:26,619
capabilities.

55
00:04:26,619 --> 00:04:32,260
Understand how LLMs identify the right tool and manage parameter inputs for precise outputs.

56
00:04:32,260 --> 00:04:37,619
You can manage chat history, preserving conversation context for more accurate, personalized responses.