1
00:00:03,000 --> 00:00:08,720
Welcome to this video on Build Effective AI Tools for Advanced LLMs.

2
00:00:08,720 --> 00:00:14,039
In this video, you'll learn how to define structured tools with complex inputs and outputs,

3
00:00:14,039 --> 00:00:18,120
set up agents for real-time decision making, and experiment with different large-language

4
00:00:18,120 --> 00:00:21,200
models or LLMs for dynamic tool integration.

5
00:00:21,200 --> 00:00:26,079
You'll also discover how to orchestrate complex workflows combining multiple tools

6
00:00:26,079 --> 00:00:29,899
for smarter, context-aware responses.

7
00:00:29,899 --> 00:00:35,040
To set the stage, start by understanding the difference between a standard LLM and a full-fledged

8
00:00:35,040 --> 00:00:36,040
agent.

9
00:00:36,040 --> 00:00:41,520
An LLM understands human language, but an agent takes it a step further.

10
00:00:41,520 --> 00:00:47,619
In this video, you'll focus on one key aspect — an agent's ability to use tools.

11
00:00:47,619 --> 00:00:52,500
A tool is a function that enables an LLM to move beyond simple text prediction and interact

12
00:00:52,500 --> 00:00:54,439
with the real world.

13
00:00:54,439 --> 00:00:59,819
Tools allow the LLM to access live data, like recent news, perform actions like sending

14
00:00:59,819 --> 00:01:07,860
emails, ensure mathematical and logical precision, retrieve private or enterprise-specific data,

15
00:01:07,860 --> 00:01:10,419
enhance multi-step reasoning.

16
00:01:10,419 --> 00:01:15,739
These capabilities transform a passive language model into an active, goal-driven system – an

17
00:01:15,739 --> 00:01:17,180
agent.

18
00:01:17,180 --> 00:01:20,339
A tool has a clear purpose to do one job well.

19
00:01:20,339 --> 00:01:26,120
A tool in LangChain is a Python function, but debugging is more art than science.

20
00:01:26,120 --> 00:01:29,519
LangChain evolves rapidly, so version control is essential.

21
00:01:29,519 --> 00:01:34,519
LLMs and agents differ in how they handle inputs and outputs, and certain combinations

22
00:01:34,519 --> 00:01:37,639
might require specific formats to function reliably.

23
00:01:37,639 --> 00:01:41,080
Let's take a moment to learn more about the LLM's response.

24
00:01:41,080 --> 00:01:46,760
Here's an example of an add tool to illustrate the core idea behind tool calling in an agent.

25
00:01:46,779 --> 00:01:48,419
The user inputs a query.

26
00:01:48,419 --> 00:01:51,180
For example, what is 3 plus 2?

27
00:01:51,180 --> 00:01:55,940
The LLM extracts the parameters for the tool – in this case, 3 and 2.

28
00:01:55,940 --> 00:02:01,980
It also determines which tool to call – in this case, a tool that adds a set of numbers.

29
00:02:01,980 --> 00:02:07,580
The LLM then passes the extracted inputs as structured arguments to the selected tool.

30
00:02:07,580 --> 00:02:09,419
The tool is applied to the data.

31
00:02:09,419 --> 00:02:13,559
In this case, we get the total of the two numbers, 5.

32
00:02:13,559 --> 00:02:16,179
This example tool adds numbers.

33
00:02:16,179 --> 00:02:18,559
Inputs should include the following components.

34
00:02:18,559 --> 00:02:21,559
First, tools use a descriptive name.

35
00:02:21,559 --> 00:02:26,639
Use intuitive names like add_numbers to reflect the function's intent.

36
00:02:26,639 --> 00:02:30,800
Next, tools include standardized inputs that are easy to parse.

37
00:02:30,800 --> 00:02:35,080
Since inputs will come from an LLM, they are typically text strings.

38
00:02:35,080 --> 00:02:37,559
Though structured JSON is also common.

39
00:02:37,559 --> 00:02:41,279
The input should specify the type of data passed to it.

40
00:02:41,279 --> 00:02:45,759
Tools should also include comprehensive documentation that describes what they do, the expected

41
00:02:45,759 --> 00:02:49,360
inputs and outputs, and known limitations.

42
00:02:49,360 --> 00:02:51,360
Tools must include a function body.

43
00:02:51,360 --> 00:02:56,720
In this example, the function body processes the input string by filtering for digits,

44
00:02:56,720 --> 00:03:00,720
converting the digits to integers, and then calculating their sum.

45
00:03:00,720 --> 00:03:04,199
And finally, tools must produce consistent output.

46
00:03:04,199 --> 00:03:08,199
Tools return their results in a predictable format, usually a dictionary.

47
00:03:08,199 --> 00:03:10,360
Here is a better example of docstring.

48
00:03:10,360 --> 00:03:13,720
A docstring helps the LLM select the right tool.

49
00:03:13,720 --> 00:03:16,559
It includes a brief description of the tool's purpose.

50
00:03:16,559 --> 00:03:20,880
The parameters section defines the expected input and output.

51
00:03:20,880 --> 00:03:25,360
Examples show both input formats and expected output, making the tool easier to understand

52
00:03:25,360 --> 00:03:26,559
and test.

53
00:03:26,559 --> 00:03:31,479
You can use the tool class in LangChain to wrap regular Python functions into agent-compatible

54
00:03:31,479 --> 00:03:32,479
tools.

55
00:03:32,479 --> 00:03:36,639
By specifying the tool's name, function, and a short description, the tool becomes

56
00:03:36,639 --> 00:03:40,500
callable by agents in response to LLM prompts.

57
00:03:40,500 --> 00:03:43,479
You can use the invoke method to call the tool directly.

58
00:03:43,479 --> 00:03:48,039
For example, given the input, what is the sum of 10, 20, and 30?

59
00:03:48,039 --> 00:03:49,800
The tool returns 60.

60
00:03:49,800 --> 00:03:55,960
Since the tool is just a regular Python function, it uses methods like "is digit" to extract numbers.

61
00:03:55,960 --> 00:04:00,639
So if you replace 10 with the word 10, the tool won't recognize it and will only sum

62
00:04:00,639 --> 00:04:03,679
20 and 30, returning 50.

63
00:04:03,679 --> 00:04:07,679
The tool decorator defines tools in modern LangChain applications.

64
00:04:07,679 --> 00:04:11,839
It creates a tool similar to the tool class, but with cleaner syntax.

65
00:04:11,839 --> 00:04:17,959
In this example, the function add_numbers processes input using regular expressions.

66
00:04:17,959 --> 00:04:22,179
The same logic could be implemented using the tool class, but the key difference is

67
00:04:22,179 --> 00:04:27,100
that the tool decorator wraps it as a structured tool, allowing the LLM to handle more complex

68
00:04:27,100 --> 00:04:32,519
inputs, including named arguments and dictionaries, which improves flexibility and integration

69
00:04:32,519 --> 00:04:34,640
with function calling models.

70
00:04:34,640 --> 00:04:38,000
For a structured tool, the input can be more complex.

71
00:04:38,000 --> 00:04:42,019
The tool has several data attributes that provide metadata for describing and interfacing

72
00:04:42,019 --> 00:04:43,519
with it.

73
00:04:43,519 --> 00:04:47,839
Name is the tool's name, usually derived from the function name.

74
00:04:47,839 --> 00:04:51,559
Description is a brief explanation of what the tool does, typically extracted from the

75
00:04:51,559 --> 00:04:53,640
function's docstring.

76
00:04:53,640 --> 00:04:58,380
Args defines the expected input schema, including the names and types of parameters.

77
00:04:58,380 --> 00:05:03,600
In the basic example, the tool takes a single input called inputs of type strings, but this

78
00:05:03,679 --> 00:05:07,760
can be extended to support multiple named inputs of different types for more complex

79
00:05:07,760 --> 00:05:09,000
tools.

80
00:05:09,000 --> 00:05:13,679
Structured tools allow multiple typed inputs to be passed together, and these inputs don't

81
00:05:13,679 --> 00:05:17,519
have to be strings as long as they are JSON-serializable.

82
00:05:17,519 --> 00:05:21,799
Import the list type from Python's typing module to define a list of floats as an input

83
00:05:21,799 --> 00:05:23,119
type.

84
00:05:23,119 --> 00:05:29,239
The tool accepts two parameters, a list of floats, numbers, and a boolean flag, absolute,

85
00:05:29,239 --> 00:05:32,119
to control whether to sum absolute values.

86
00:05:32,119 --> 00:05:36,519
The docstring should clearly describe each parameter and the expected output.

87
00:05:36,519 --> 00:05:41,239
The tool returns a float, as some LLMs may fail to parse complex output formats when

88
00:05:41,239 --> 00:05:43,040
used with certain agents.

89
00:05:43,040 --> 00:05:47,920
However, some LLMs may not support multiple input fields even if they can handle structured

90
00:05:47,920 --> 00:05:50,279
tools, so testing is important.

91
00:05:50,279 --> 00:05:56,640
Let's compare the arguments for add_numbers_with_options

92
00:05:56,640 --> 00:05:59,959
and add_numbers structured tools.

93
00:05:59,959 --> 00:06:02,359
They each include an input field.

94
00:06:02,359 --> 00:06:07,839
Add_numbers uses inputs, a string, and only performs basic numeric extraction

95
00:06:07,839 --> 00:06:10,519
and summation from a string input.

96
00:06:10,519 --> 00:06:17,320
Contrast, add_numbers_with_options uses numbers, a list

97
00:06:17,320 --> 00:06:23,660
of floats, and includes an extra parameter, that is absolute and type boolean with a default

98
00:06:23,660 --> 00:06:25,480
value of false.

99
00:06:25,480 --> 00:06:30,679
This parameter supports optional behavior, allowing the tool to sum absolute values.

100
00:06:30,679 --> 00:06:35,720
You can call the tool using a dictionary as input, where each key corresponds to a parameter

101
00:06:35,720 --> 00:06:38,940
name and the value is the input for that parameter.

102
00:06:38,940 --> 00:06:43,720
For example, to control whether the numbers are summed normally or as absolute values,

103
00:06:43,720 --> 00:06:46,720
you can set the absolute flag to false or true.

104
00:06:46,720 --> 00:06:51,100
This results in minus 6.2 and 6.2 respectively.

105
00:06:51,100 --> 00:06:57,179
You can define tools that return more complex or variable outputs depending on the situation.

106
00:06:57,179 --> 00:07:02,220
For example, consider this function, which returns either a numeric sum or an error message

107
00:07:02,220 --> 00:07:05,220
string if no numbers are found in the input.

108
00:07:05,220 --> 00:07:08,119
Let's take a closer look at how the input is structured.

109
00:07:08,119 --> 00:07:14,559
You can use Python's typing module, including Dict and Union, to specify the return type.

110
00:07:14,559 --> 00:07:20,100
This informs the tool framework that the output will be a dictionary where the key is a string,

111
00:07:20,100 --> 00:07:22,059
for example, result.

112
00:07:22,059 --> 00:07:27,260
The value can either be a float, if summation succeeds, or a string if there's an error.

113
00:07:27,260 --> 00:07:30,739
The union type allows the value to be one or the other.

114
00:07:30,739 --> 00:07:35,820
A tool in LangChain is essentially a Python function, but debugging it can be more art

115
00:07:35,820 --> 00:07:37,459
than science.

116
00:07:37,459 --> 00:07:41,019
LangChain evolves rapidly, making version control essential.

117
00:07:41,019 --> 00:07:46,420
LLMs and agents differ in how they handle inputs and outputs, and certain combinations

118
00:07:46,420 --> 00:07:49,820
may require specific formats to function reliably.

119
00:07:49,820 --> 00:07:55,779
A tool is a callable function that performs a specific task, usually triggered by an LLM.

120
00:07:55,779 --> 00:08:00,459
In this video, you learned to distinguish LLMs from agents by exploring the critical

121
00:08:00,459 --> 00:08:04,579
role of tools in enabling real-world interactions.

122
00:08:04,579 --> 00:08:09,940
Extend LLM capabilities by integrating tools for data access, precise calculations, and

123
00:08:09,940 --> 00:08:11,839
multi-step reasoning.

124
00:08:11,839 --> 00:08:16,220
Design effective tool interfaces with clear inputs, outputs, and descriptions to enhance

125
00:08:16,220 --> 00:08:18,059
agent responses.

126
00:08:18,059 --> 00:08:23,339
Build structured tools for flexible, context-aware interactions, supporting complex inputs and

127
00:08:23,339 --> 00:08:24,619
robust data handling.