Skip to main content
Taught by Tech Leads

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

DataScientist.fr
Image de Create a LangGraph agent capable of using external tools.
Artificial Intelligence
LLM
Python

Create a LangGraph agent capable of using external tools.

Photo de Romain DE LA SOUCHÈRE

Tech Lead, CTO AXI Technologies

Published on 16 mai 2025 · 10 min of reading

LangGraph is a powerful extension of the LangChain library, specially designed to orchestrate complex and dynamic workflows involving LLM agents. Among its most innovative features is the integration of external tools such as search engines, which allows a conversational agent to enrich itself and adapt to the specific needs of users.
In this article, we will guide you step-by-step in creating a LangGraph agent capable of using a search tool like Tavily to perform real-time web queries, enabling it to answer questions well beyond its pre-trained internal capabilities.

Why add tools to your LangGraph agent?

Agents based on large language models (LLMs) are powerful but inherently limited by their training corpus. They can hardly access very recent facts or up-to-date data. This is where the addition of tools makes perfect sense. These tools allow the agent to:
  • Access up-to-date information via search engines like Tavily or SerpAPI.

  • Connect to third-party APIs to execute actions or retrieve specific data.

  • Perform calculations, text processing, or any other business logic.

In other words, tools enable the agent to extend its capabilities far beyond its static knowledge base, making it more responsive, adaptive, and useful in various contexts.

Prerequisites

Before getting started, ensure you have the following:
A Tavily API key: you will need to sign up and retrieve an API key and then import your key into the code.
python
The necessary dependencies installed in your Python environment:
shell

Step 1: Create the Tavily tool

Start by creating an instance of the Tavily tool that the agent can invoke to perform searches.
python

Step 2: Initialize the LLM with tool support

Next, initialize the language model by associating it with the list of tools you want to enable.
python

Step 3: Define the conversation state and graph

LangGraph relies on a state graph model. Each step of the dialogue is stored in a typed state variable.
python
-> For advanced use, using memory with LangGraph is recommended.

Step 4: Add graph nodes

Start by adding the main node, which represents the chatbot that analyzes messages and decides whether to invoke a tool.
python
Then add the node that will actually execute the tool calls.
python

Step 5: Add conditional routing logic

This routing allows LangGraph to dynamically decide whether to execute a tool or close the response.
python
You can visualize the graph using the method <code>get_graph:
python
graph visualisation

Step 6: Compile and run the graph

Once all nodes are defined and connected, compile the graph and use it in your application.
python
-> When running the graph, you can also stream events to get a real-time response from the agent.

Complete Code

Here is the complete code compiled for a full and standalone implementation (be sure to replace the Tavily key in the code) :
python

Conclusion

Adding tools to a LangGraph agent fundamentally transforms its capabilities. It is no longer just a static chatbot but an adaptive agent capable of exploring the web, reacting to real-time data, and interacting with external systems. LangGraph provides a robust and flexible infrastructure for developing these augmented agents. Once you have grasped this foundation, you can go further by integrating custom tools, adding conversational memory, or managing more complex interaction cycles. It is a true toolkit for building the intelligent agents of tomorrow.

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