Skip to main content
Taught by Tech Leads

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

DataScientist.fr
Image de Create a ReAct Agent with LangGraph
Artificial Intelligence
Python

Create a ReAct Agent with LangGraph

Photo de Romain DE LA SOUCHÈRE

Tech Lead, CTO AXI Technologies

Published on 18 avril 2025 · 10 min of reading

In 2025, artificial intelligence (AI) reaches a new decisive milestone with the advent of autonomous agents. According to Gartner, these agents represent the main strategic technology trend of the year, radically transforming the way we interact with technology. Among these innovations, ReAct agents stand out for their ability to combine reasoning and action, thus offering unprecedented and powerful solutions. This new generation of AI does not just create content; it acts, plans, and collaborates autonomously, redefining the standards of efficiency and innovation across all sectors. Let’s dive into this revolution to discover how ReAct agents embody the future of generative AI.
In this article, we will explore in depth how ReAct agents work, these AI systems that combine reasoning and action to solve complex problems. We will see how they alternate between thinking and action phases, using external tools to gather information or perform tasks, while being inspired by human thought processes. Through concrete examples, we will illustrate their ability to analyze queries, develop plans, and execute precise actions, all within an iterative loop that adapts in real time to user needs. Finally, we will examine the implications of this technology for the future, both for businesses and individuals, and how it could transform our daily lives.

What is a ReAct agent?

A ReAct agent (Reasoning + Acting) is an AI system that combines two essential capabilities:
  • Reasoning: analyzing a problem and determining the best approach
  • Action: using external tools to gather information or perform tasks
This approach allows the agent to solve complex problems by alternating between reasoning and action, similar to how humans solve problems.
Fonctionnement Agent ReAct
A ReAct agent operates by alternating between two main phases: reasoning and action. During the reasoning phase, the agent analyzes the user's query, evaluates the available information, and develops an action plan. Then, it executes this plan using external tools to gather information or perform specific tasks. After each action, the agent observes the results, integrates them into its knowledge base, and decides whether to continue or adjust its plan. This iterative cycle continues until the agent determines that it has enough information to respond to the initial query.

What is LangGraph?

LangGraph is an emerging technology in the field of natural language processing (NLP) that simplifies complex interactions between humans and AI agents. It allows for the construction of AI agents in the form of graphs, thus facilitating the creation of systems capable of managing complex multi-turn conversations and executing specific tasks autonomously. LangGraph is distinguished by its hierarchical approach to information retrieval and generation, integrating Augmented Retrieval by Generation (RAG) techniques to improve the quality of responses and manage large amounts of data. Used by companies such as Replit, Uber, LinkedIn, and GitLab, LangGraph offers a flexible framework for orchestrating AI agents, with tools for state management, visual debugging, and various deployment options.

Creating a ReAct Agent with LangGraph

Let’s continue by exploring how to develop a ReAct agent with the help of LangGraph. This technology offers built-in features that significantly simplify the process of creating sophisticated AI agents. With LangGraph, even developers with limited programming knowledge can set up robust and efficient systems in just a few steps. You will be guided through the essential steps to configure a LangGraph agent, showing you how to use pre-developed tools to maximize the efficiency and accuracy of your agent. This process will demonstrate that it is possible to design an AI agent capable of handling complex queries and providing relevant answers in a short amount of time and with minimal code.
We will need an API key for Tavily; you will need to sign up and retrieve an API key.
python

Code explanation

To better understand the code provided in the previous section, let’s examine each part of the script and explain its role in creating a ReAct agent with LangGraph.

API key configuration

We define the API key needed to interact with Tavily:
python
It is crucial to replace <your_openai_key> with your own Tavily API key to ensure secure access to services.

Creating the model and tools

The language model is initialized with the model llama-3.3-70b-versatile, and the Tavily tools are configured to limit search results to five:
python
These lines allow specifying the model and tools that the agent will use to process queries.

Creating the ReAct agent

The agent is created using the create_react_agent function, which takes into account the configured model and tools:
python
This step links the language model to the necessary tools for performing external actions.

Defining the user question

The question posed to the agent is defined:
python
This query guides the reasoning and actions that the agent will execute.

Display function and execution

Finally, a print_stream function is defined to process and display the agent's messages. The script then executes the conversation stream and prints the agent's response:
python
This section demonstrates how the code uses LangGraph to interact with a ReAct agent, providing a response based on search data and reasoning capabilities.

Conclusion

In conclusion, using LangGraph to create a ReAct agent demonstrates the power and flexibility of this technology in the field of natural language processing. By integrating advanced language models and research tools, developers can design systems capable of handling complex queries and interacting smoothly with users.

Main advantages

One of the main advantages of LangGraph is its ability to simplify the creation of AI agents. The framework offers pre-developed tools and an intuitive approach that reduces the need to code complex algorithms. This allows developers to focus on enhancing user experience and customizing interactions rather than on the technical details of data processing.

Practical applications

The applications of this technology are vast. Whether for customer service, personal assistants, or automated information systems, ReAct agents built with LangGraph can effectively meet the needs of various industrial sectors. They offer robust solutions that combine reasoning and action, allowing for natural and relevant interactions with users.

Future prospects

As natural language processing technologies continue to evolve, tools like LangGraph will play a crucial role in enhancing the capabilities of AI agents. By integrating increasingly sophisticated language models and optimizing information retrieval and generation processes, LangGraph has the potential to transform how businesses interact with their customers and manage their operations.
In summary, the combination of LangGraph with ReAct agents paves the way for intelligent systems capable of adapting to the changing needs of users while offering increased performance and efficiency. Developers and businesses now have a powerful tool at their disposal to innovate and stand out in an ever-evolving 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