To Data & Beyond

To Data & Beyond

Share this post

To Data & Beyond
To Data & Beyond
Building Smarter Agents with LangGraph: Tools, Memory & Workflows

Building Smarter Agents with LangGraph: Tools, Memory & Workflows

A quick guide to using tools and memory in your agent workflows

Rajneesh Jha's avatar
Rajneesh Jha
Jun 04, 2025
∙ Paid
12

Share this post

To Data & Beyond
To Data & Beyond
Building Smarter Agents with LangGraph: Tools, Memory & Workflows
2
Share

Get 50% off for 1 year

In my recent articles, I’ve been diving into various tools and libraries for developing multi-agent systems.

We started with the OpenAI Agent SDK, where I shared how to build your own Deep Research Agent:
🔗 Build Your Own Deep Research Agent using OpenAI’s Agent SDK

Then we explored CrewAI, a powerful framework for creating collaborative AI agents:
🔗 Build Your First AI Coding Buddy with CrewAI

Today, let’s take a look at another exciting and widely adopted framework — LangGraph. This graph-based library is designed for building complex, structured agent workflows with ease. In the next few minutes, we’ll see how to use tools and memory with LangGraph.

Image Source: https://realpython.com/langgraph-python/

1. What is LangGraph ?

LangGraph is a stateful, graph-based framework designed to build complex, multi-agent applications using LLMs. Unlike traditional linear workflows, LangGraph leverages directed graphs where each node represents an agent or task, and edges define their interactions. This structure facilitates dynamic, iterative, and memory-aware agentic systems.

Core Features of LangGraph:

  • Graph-Oriented Workflow: Design flexible, branching workflows with loops and conditionals, enabling complex agent interactions.

  • Stateful Execution: Automatically persist agent states at each step, allowing for error recovery, time travel, and human-in-the-loop interventions.

  • Integrated Memory: Support for both short-term (session-based) and long-term (persistent across sessions) memory, enabling agents to recall and adapt to user interactions.

  • Human-in-the-Loop Control: Pause execution to seek human approval or modification before proceeding, enhancing oversight and control .

  • Seamless Integration with LangChain: While built on LangChain, LangGraph can function independently, offering flexibility in deployment.

  • Open-Source and Extensible: Released under the MIT license, LangGraph is free to use and can be extended to meet specific needs.

2. Key Terminology in LangGraph:

  1. The State serves as the central data structure in LangGraph, encapsulating all relevant information during the execution of the workflow. It can be as simple as a dictionary or a more structured model using tools like Pydantic. Each node in the graph receives and updates this state, ensuring continuity and context throughout the process.
    When defining the state in LangGraph, two important concepts from LangChain play a crucial role:

  • Annotated from Python’s typing the module is used to attach metadata to type hints. This metadata usually specifies a reducer function, which dictates how updates to a particular state field should be merged with existing data.

  • Reducers are functions responsible for determining how updates to individual state fields are applied. Each field can have its own reducer, allowing for customized merging behaviour. If no reducer is specified, the default behaviour is to overwrite the existing value with the new update.

from typing import Annotated
from typing_extensions import TypedDict
from operator import add

class State(TypedDict):
    messages: Annotated[list[str], add]

In this example, the messages field is a list of strings, and the add function from the operator the module is used as a reducer. This means that when new messages are added, they will be concatenated to the existing list rather than replacing it.

2. Nodes are the fundamental units of computation within LangGraph. Each node represents a specific task or action, such as:

  • Processing user input

  • Interacting with external APIs

  • Making decisions based on conditions

  • Generating responses using LLMs

Nodes are typically implemented as Python functions that accept the current state as input and return an updated state.

3. Edges define the flow of execution between nodes, determining the sequence in which tasks are performed. There are different types of edges:

  • Normal Edges: Establish a straightforward, unidirectional connection between nodes.

  • Conditional Edges: Introduce decision-making into the workflow, directing the flow based on specific conditions or logic.

These edges enable the creation of complex workflows with branching logic and loops.

4. Unlike traditional DAGs, LangGraph supports cycles, allowing nodes to revisit previous steps. This feature is particularly useful for tasks that require iterative refinement or repeated evaluation, such as debates between agents or recursive problem-solving.

5. LangGraph provides built-in persistence mechanisms to save the state of the workflow at various points. This capability enables:

  • Checkpointing: Saving snapshots of the graph’s state to resume execution later.

  • Human-in-the-Loop Interactions: Allowing manual intervention during the workflow.

  • Fault Tolerance: Recovering from errors by restoring to a previous state.

Persistence is achieved through check pointers and storage systems that manage state across different threads and sessions.

6. In LangGraph, a thread represents an individual session or conversation. Each thread maintains its own state, enabling personalized interactions and context retention across multiple sessions. This is particularly beneficial for applications like chatbots or virtual assistants that require memory of past interactions.

7. LangGraph includes a storage system that allows for the saving and retrieval of data across different threads. This feature supports:

  • Cross-Thread Persistence: Maintaining information across multiple sessions.

  • Flexible Name spacing: Organizing data for different users or contexts.

  • Document Storage: Saving data in JSON format for easy manipulation and retrieval.

The storage system facilitates the creation of long-term memories and knowledge bases.

In the next few sections, let’s create some tools and integrate with agents.

3. Tool Creation:

Serper Web-Search Tool: Serper is a web search API tool that provides real-time, Google-like search results. It’s often used in AI and agent frameworks like LangGraph to allow language models to access up-to-date information from the web.

Explore more here: https://serper.dev/

This post is for paid subscribers

Already a paid subscriber? Sign in
A guest post by
Rajneesh Jha
Interested in solving business problems using Machine Learning and AI. https://www.linkedin.com/in/rajneesh407/
Subscribe to Rajneesh
© 2025 Youssef Hosni
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share