Skip to main content
Taught by Tech Leads

Master pipelines, cloud & AI to become an operational Data Engineer.

DataScientist.fr
Image de Practical Guide to Using Tools with LangChain
Artificial Intelligence
LLM

Practical Guide to Using Tools with LangChain

Photo de Romain DE LA SOUCHÈRE

Tech Lead, CTO AXI Technologies

Published on 15 avril 2025 · 5 min of reading

LangChain is a powerful library that enables the creation of natural language-based applications using advanced language models. One of the most interesting aspects of LangChain is its ability to integrate various tools to enrich the functionality of applications. In this article, we will explore the concepts of tools and tool calls in LangChain, supported by concrete examples to illustrate their use.

What is a tool in LangChain?

In the context of LangChain, a tool is a feature or external service that the language model can use to accomplish specific tasks. These tools can include APIs, databases, computing services, or even other language models. Integrating these tools extends the capabilities of the base model, allowing it to perform tasks it could not accomplish alone.
LangChain Tool calling

Why use tools?

Using tools in LangChain has several advantages:
Enhancement of Capabilities: Tools allow the language model to access real-time information, perform complex calculations, or interact with other systems.
Improvement of Accuracy: By using specialized tools, the model can provide more accurate and relevant responses.
Task Automation: Tools can automate repetitive tasks, freeing up time for more complex activities.

Creating a tool

To create tools, it is advisable to use the decorator @tool. Designed to facilitate tool creation, this decorator is suitable for most situations. Once you have defined your function, apply the @tool decorator to generate a tool that complies with the Tool Interface.
python

Tool integration

Large Language Models (LLMs) can be enhanced by integrating external tools, extending their capabilities beyond simple text generation. By using standardized interfaces like the one proposed by LangChain, it is possible to connect various tools to LLMs.

It is important to note that not all LLMs are necessarily compatible with tool calling; a prior evaluation of the LLM may be necessary to ensure compatibility with the tool calling feature.

The method <code>.bind_tools() allows you to define the tools that a model will be able to use.
python
First call to the LLM: When the user sends the message "Hello world!", the model responds without using the tool, as the request does not require any computation.
Second call to the LLM: When the user asks "What is 2 multiplied by 3?", the model detects that it needs to use the tool <code>multiply. It generates a call to the tool with the appropriate arguments (<code class="inline-code">a=2, <code class="inline-code">b=3).
LangChain Tool calling integration

Integrating results into the LLM

Integrating the results from tools into a language model is crucial for ensuring a smooth and relevant response. When the LLM calls a tool, it must be able to interpret and incorporate the results obtained into its overall response to the user.

Integration process

  1. Tool call: The model evaluates the user request and decides if the use of a tool is necessary. If so, it generates a call to the tool with the required parameters.
  2. Obtaining the result: The tool returns the result after executing the requested task. This result is then passed back to the language model.
  3. Synthesis of the response: The model integrates the result of the tool into its response. The generated text may include explanations about the process or simply provide the expected result.

Example of integration

Let’s imagine that the user asks: "What is the result of 5 multiplied by 7?" The model calls the multiplication tool, receives the result (35), and integrates this number into a response like: "The result of 5 multiplied by 7 is 35." This allows for a natural and informative conversation.
python

Best practices

To design tools usable by a model, here are some recommendations:
  • Models with dedicated tool call APIs are more efficient than non-optimized models.
  • Tools should have clear names and descriptions for better performance.
  • Simple and specialized tools are easier to use than complex tools.
  • Avoid asking the model to choose from a long list of tools; this can be difficult for it.

Conclusion

By integrating tools into LangChain, we have discovered how to enhance the capabilities of language models, make them more accurate, and automate certain tasks. Creating custom tools and integrating them into the system allows for extending functionalities and effectively meeting user needs. Best practices, such as clarity in tool descriptions and optimization of APIs, ensure smooth usage and better performance of models.
The proper use of tools and their integration into LLM responses offers an enriched user experience, enabling the management of complex queries with ease. Thus, the user benefits from a more natural and relevant interaction, where the results of calculations or queries are seamlessly integrated.
By adopting these methods and practices, LangChain positions itself as a powerful tool for developing intelligent applications, optimizing the interaction between users and language models. Future prospects include a deeper exploration of available tools and continuous improvement of their integration to meet the evolving needs of the market.

Want to go further?

This topic is part of our Generative AI for Developers course. Browse the full programme, or get it by email.

Share with

Photo de Romain DE LA SOUCHÈRE

Romain DE LA SOUCHÈRE

Tech Lead, CTO AXI Technologies

Expert Data Engineering et Cloud, Romain affiche plus de 11 ans d'expérience, dont plusieurs années comme Lead Developer sur des solutions Smart Building haute performance. Il y a conçu et mis en production des moteurs de traitement capables d'absorber des centaines de milliers de données de capteurs par minute, ainsi que des bases clusterisées gérant plus de 10 millions de données dynamiques. Certifié Microsoft Azure DevOps Engineer Expert, il maîtrise aussi bien le développement back-end (Python, C#) que le DevOps (Docker, Kubernetes, Terraform) et les agents LLM. Formateur en Python, cloud, DevOps et IA générative appliquée, il forme avec une obsession : Amener chaque apprenant à concevoir et déployer des architectures réellement scalables en production.

» Learn More

Associated trainings

All our trainings
Image de la formation Generative AI for Developers
Generative AI for Developers
50 hours
Intermediate
Guarantee

Associated articles

See all our articles
Image de l'article Prompt Template Guide with LangChain

avril 15, 2025

Prompt Template Guide with LangChain

Reading time: 10 min

Image de l'article Output Parsers in LangChain

avril 15, 2025

Output Parsers in LangChain

Reading time: 5 min