1
00:00:04,000 --> 00:00:08,500
Welcome to this video on Build Interactive LLM Agents.

2
00:00:08,500 --> 00:00:13,000
In this video, you'll learn how to extract tool names and arguments for precise function

3
00:00:13,000 --> 00:00:14,000
calls.

4
00:00:14,000 --> 00:00:18,059
You'll learn how to build agent classes that manage the entire tool-calling process

5
00:00:18,059 --> 00:00:21,780
for smarter, context-aware responses.

6
00:00:21,780 --> 00:00:26,600
Now that you've built a foundation in setting up LLMs with basic tool integrations, it's

7
00:00:26,600 --> 00:00:28,920
time to take things a step further.

8
00:00:28,920 --> 00:00:32,360
Begin by setting up the actual question you want the model to answer.

9
00:00:32,360 --> 00:00:34,159
"What is 3 plus 2?"

10
00:00:34,159 --> 00:00:38,200
First, insert the user's question into the chat history so the model can see it as a

11
00:00:38,200 --> 00:00:40,659
part of the conversation context.

12
00:00:40,659 --> 00:00:44,520
Convert the plain text question into a HumanMessage, which is a symbol wrapper that tells

13
00:00:44,520 --> 00:00:47,659
LangChain, This text came from the user."

14
00:00:47,659 --> 00:00:52,259
It carries the user's input and marks it appropriately for the model during the conversation.

15
00:00:52,259 --> 00:00:55,840
To do this, import HumanMessage from LangChain core messages.

16
00:00:55,840 --> 00:00:58,419
Next, build the chat history.

17
00:00:58,419 --> 00:01:03,099
Take the query string, wrap it in a HumanMessage, and place it into a list called chat

18
00:01:03,099 --> 00:01:04,379
history.

19
00:01:04,379 --> 00:01:10,059
This list will hold all messages exchanged during the conversation, including user inputs,

20
00:01:10,059 --> 00:01:15,540
tool outputs, and model responses, ensuring that the model has complete context at every

21
00:01:15,540 --> 00:01:16,540
step.

22
00:01:16,540 --> 00:01:18,660
It's time to run the tool-enabled model.

23
00:01:18,660 --> 00:01:23,980
First, pass the complete chat history, which contains the user's question, into LLM with

24
00:01:23,980 --> 00:01:24,980
tools.

25
00:01:24,980 --> 00:01:30,260
At this point, the model reviews the conversation context, identifies the available tools, select

26
00:01:30,260 --> 00:01:34,580
the appropriate one, such as add function, and extract the parameters.

27
00:01:34,580 --> 00:01:36,180
Notice the model's output.

28
00:01:36,180 --> 00:01:41,379
Instead of a plain text response, an AIMessage is received containing a tool calls array.

29
00:01:41,379 --> 00:01:44,779
Focus only on the part of the message related to tool usage.

30
00:01:44,779 --> 00:01:48,940
This is the model's way of saying, "I want to call this function with these arguments."

31
00:01:48,940 --> 00:01:53,739
Next, extract the details of the tool call and manually execute the addition ourselves.

32
00:01:53,900 --> 00:01:58,819
Finally, append the AIMessage, including the tool call instruction, into chat_history

33
00:01:58,819 --> 00:02:04,660
so the next model invocation has access to both the user's original query and the

34
00:02:04,660 --> 00:02:06,800
model's previous output.

35
00:02:06,800 --> 00:02:09,339
Response1 is an AIMessage object.

36
00:02:09,339 --> 00:02:11,619
Let's take a quick look at its key details.

37
00:02:11,619 --> 00:02:13,740
Here's the tool call parameters.

38
00:02:13,740 --> 00:02:16,399
"Add" is the name of the tool the model wants to call.

39
00:02:16,399 --> 00:02:21,460
The function arguments are a JSON string that specifies the inputs to pass into the tool.

40
00:02:21,460 --> 00:02:24,779
For example, "A equals 3 and B equals 2."

41
00:02:24,779 --> 00:02:27,300
Here is a unique identifier for this tool call.

42
00:02:27,300 --> 00:02:30,500
It's used to link the response back to the request.

43
00:02:30,500 --> 00:02:32,860
This is if more than one tool is called.

44
00:02:32,860 --> 00:02:37,699
The type field specifies that this is a tool call, not a text or other output type.

45
00:02:37,699 --> 00:02:42,139
Now parse the tool parameters, execute the tool manually, and then send the result back

46
00:02:42,139 --> 00:02:44,660
to the LLM as part of the conversation.

47
00:02:44,660 --> 00:02:50,419
First, parse the add tool with arguments "A equals 3 and B equals 2" and feed them into

48
00:02:50,419 --> 00:02:51,899
the function.

49
00:02:51,899 --> 00:02:55,360
Then extract the model's tool-call instructions into a variable.

50
00:02:55,360 --> 00:03:00,539
You will get a list showing exactly which tools the LLM selected and with what arguments,

51
00:03:00,539 --> 00:03:03,380
ready to be inspected and manually invoked.

52
00:03:03,380 --> 00:03:07,619
Next you will extract the tool's name from the first entry by running this command.

53
00:03:07,619 --> 00:03:12,539
You will then pull out "AddTool," telling exactly which function to call next.

54
00:03:12,539 --> 00:03:18,300
Extract the parameters to pass the function using the args key, for example "A3 and B2."

55
00:03:18,300 --> 00:03:20,660
Finally extract the tool call "ID."

56
00:03:20,660 --> 00:03:25,259
This ID links the tool's result back to the model's original request, so the LLM

57
00:03:25,259 --> 00:03:28,380
knows which tool call the response belongs to.

58
00:03:28,380 --> 00:03:32,339
This is especially important when multiple tools are called at once.

59
00:03:32,339 --> 00:03:35,619
Use the tool map created earlier to call the function you need.

60
00:03:35,619 --> 00:03:39,820
The key is the tool name determined by the LLM stored in tool_1_name.

61
00:03:39,820 --> 00:03:45,380
In addition, use the tool parameters provided by the LLM stored in tool_1_args.

62
00:03:45,380 --> 00:03:50,139
The tool map returns the output generated via the tool, in this case "2 plus 3 equals

63
00:03:50,139 --> 00:03:51,139
5."

64
00:03:51,139 --> 00:03:55,699
Finally, wrap the tool's output in a Tool Message by creating a Tool Message object.

65
00:03:55,699 --> 00:04:00,699
Finally, update the chat history by appending the new tool message to the chat history list.

66
00:04:00,699 --> 00:04:05,860
The history now contains the original HumanMessage, the AIMessage from the model, and

67
00:04:05,860 --> 00:04:08,380
the new ToolMessage with the tool's result.

68
00:04:08,380 --> 00:04:14,059
Begin by passing the updated chat history to the LLM with tools using the invoke method.

69
00:04:14,059 --> 00:04:19,239
The LLM will generate a final response using the tool's output, but format the answer

70
00:04:19,239 --> 00:04:21,619
naturally as a part of the conversation.

71
00:04:21,619 --> 00:04:25,540
You can create an agent class that encapsulates everything you did above.

72
00:04:25,540 --> 00:04:32,220
This class, ToolCallingAgent, binds tools to the LLM, manages chat history, extracts

73
00:04:32,220 --> 00:04:35,619
tool names and arguments, and handles tool calls.

74
00:04:35,619 --> 00:04:40,720
This structure captures the entire agentic process, from receiving a user query to returning

75
00:04:40,720 --> 00:04:42,459
the final response.

76
00:04:42,459 --> 00:04:47,459
Update the ToolCallingAgent object to handle the full tool-calling process automatically.

77
00:04:47,459 --> 00:04:51,839
The LLM parses the input text and determines the appropriate tool to call.

78
00:04:51,839 --> 00:04:54,380
The user input doesn't need to be perfect.

79
00:04:54,380 --> 00:04:58,000
Even imprecise queries such as "1 minus 2" can be understood.

80
00:04:58,000 --> 00:05:02,059
The agent identifies and executes the correct tool based on intent.

81
00:05:02,059 --> 00:05:07,220
In this video, you learned to structure user interactions for real-time, context-aware

82
00:05:07,220 --> 00:05:11,100
conversations by adding queries to the chat history.

83
00:05:11,260 --> 00:05:16,260
Extract tool names and arguments to precisely match user intent with the right tool calls.

84
00:05:16,260 --> 00:05:21,320
Parse complex tool instructions, including handling multiple tool calls and linking responses

85
00:05:21,320 --> 00:05:23,459
for seamless execution.

86
00:05:23,459 --> 00:05:28,100
Build and refine agent classes to automate the entire tool calling process, enabling

87
00:05:28,100 --> 00:05:32,519
LLMs to function as responsive, multi-step agents.

88
00:05:32,519 --> 00:05:36,940
Understand how these components work together to transform LLMs from passive responders

89
00:05:36,940 --> 00:05:41,179
into intelligent agents capable of making decisions and interacting with real-world data.