Welcome to this video on Build Effective AI Tools for Advanced LLMs.
In this video, you'll learn how to define structured tools with complex inputs and outputs,
set up agents for real-time decision making, and experiment with different large-language
models or LLMs for dynamic tool integration.
You'll also discover how to orchestrate complex workflows combining multiple tools
for smarter, context-aware responses.
To set the stage, start by understanding the difference between a standard LLM and a full-fledged
agent.
An LLM understands human language, but an agent takes it a step further.
In this video, you'll focus on one key aspect — an agent's ability to use tools.
A tool is a function that enables an LLM to move beyond simple text prediction and interact
with the real world.
Tools allow the LLM to access live data, like recent news, perform actions like sending
emails, ensure mathematical and logical precision, retrieve private or enterprise-specific data,
enhance multi-step reasoning.
These capabilities transform a passive language model into an active, goal-driven system – an
agent.
A tool has a clear purpose to do one job well.
A tool in LangChain is a Python function, but debugging is more art than science.
LangChain evolves rapidly, so version control is essential.
LLMs and agents differ in how they handle inputs and outputs, and certain combinations
might require specific formats to function reliably.
Let's take a moment to learn more about the LLM's response.
Here's an example of an add tool to illustrate the core idea behind tool calling in an agent.
The user inputs a query.
For example, what is 3 plus 2?
The LLM extracts the parameters for the tool – in this case, 3 and 2.
It also determines which tool to call – in this case, a tool that adds a set of numbers.
The LLM then passes the extracted inputs as structured arguments to the selected tool.
The tool is applied to the data.
In this case, we get the total of the two numbers, 5.
This example tool adds numbers.
Inputs should include the following components.
First, tools use a descriptive name.
Use intuitive names like add_numbers to reflect the function's intent.
Next, tools include standardized inputs that are easy to parse.
Since inputs will come from an LLM, they are typically text strings.
Though structured JSON is also common.
The input should specify the type of data passed to it.
Tools should also include comprehensive documentation that describes what they do, the expected
inputs and outputs, and known limitations.
Tools must include a function body.
In this example, the function body processes the input string by filtering for digits,
converting the digits to integers, and then calculating their sum.
And finally, tools must produce consistent output.
Tools return their results in a predictable format, usually a dictionary.
Here is a better example of docstring.
A docstring helps the LLM select the right tool.
It includes a brief description of the tool's purpose.
The parameters section defines the expected input and output.
Examples show both input formats and expected output, making the tool easier to understand
and test.
You can use the tool class in LangChain to wrap regular Python functions into agent-compatible
tools.
By specifying the tool's name, function, and a short description, the tool becomes
callable by agents in response to LLM prompts.
You can use the invoke method to call the tool directly.
For example, given the input, what is the sum of 10, 20, and 30?
The tool returns 60.
Since the tool is just a regular Python function, it uses methods like "is digit" to extract numbers.
So if you replace 10 with the word 10, the tool won't recognize it and will only sum
20 and 30, returning 50.
The tool decorator defines tools in modern LangChain applications.
It creates a tool similar to the tool class, but with cleaner syntax.
In this example, the function add_numbers processes input using regular expressions.
The same logic could be implemented using the tool class, but the key difference is
that the tool decorator wraps it as a structured tool, allowing the LLM to handle more complex
inputs, including named arguments and dictionaries, which improves flexibility and integration
with function calling models.
For a structured tool, the input can be more complex.
The tool has several data attributes that provide metadata for describing and interfacing
with it.
Name is the tool's name, usually derived from the function name.
Description is a brief explanation of what the tool does, typically extracted from the
function's docstring.
Args defines the expected input schema, including the names and types of parameters.
In the basic example, the tool takes a single input called inputs of type strings, but this
can be extended to support multiple named inputs of different types for more complex
tools.
Structured tools allow multiple typed inputs to be passed together, and these inputs don't
have to be strings as long as they are JSON-serializable.
Import the list type from Python's typing module to define a list of floats as an input
type.
The tool accepts two parameters, a list of floats, numbers, and a boolean flag, absolute,
to control whether to sum absolute values.
The docstring should clearly describe each parameter and the expected output.
The tool returns a float, as some LLMs may fail to parse complex output formats when
used with certain agents.
However, some LLMs may not support multiple input fields even if they can handle structured
tools, so testing is important.
Let's compare the arguments for add_numbers_with_options
and add_numbers structured tools.
They each include an input field.
Add_numbers uses inputs, a string, and only performs basic numeric extraction
and summation from a string input.
Contrast, add_numbers_with_options uses numbers, a list
of floats, and includes an extra parameter, that is absolute and type boolean with a default
value of false.
This parameter supports optional behavior, allowing the tool to sum absolute values.
You can call the tool using a dictionary as input, where each key corresponds to a parameter
name and the value is the input for that parameter.
For example, to control whether the numbers are summed normally or as absolute values,
you can set the absolute flag to false or true.
This results in minus 6.2 and 6.2 respectively.
You can define tools that return more complex or variable outputs depending on the situation.
For example, consider this function, which returns either a numeric sum or an error message
string if no numbers are found in the input.
Let's take a closer look at how the input is structured.
You can use Python's typing module, including Dict and Union, to specify the return type.
This informs the tool framework that the output will be a dictionary where the key is a string,
for example, result.
The value can either be a float, if summation succeeds, or a string if there's an error.
The union type allows the value to be one or the other.
A tool in LangChain is essentially a Python function, but debugging it can be more art
than science.
LangChain evolves rapidly, making version control essential.
LLMs and agents differ in how they handle inputs and outputs, and certain combinations
may require specific formats to function reliably.
A tool is a callable function that performs a specific task, usually triggered by an LLM.
In this video, you learned to distinguish LLMs from agents by exploring the critical
role of tools in enabling real-world interactions.
Extend LLM capabilities by integrating tools for data access, precise calculations, and
multi-step reasoning.
Design effective tool interfaces with clear inputs, outputs, and descriptions to enhance
agent responses.
Build structured tools for flexible, context-aware interactions, supporting complex inputs and
robust data handling.