LangGraph — Part 1

Gunjan
3 min readSep 2, 2024

--

LangGraph

LangGraph is a library that enables building and managing directed acyclic graphs (DAGs) in the context of natural language processing (NLP). It is designed to help in constructing complex workflows where each node in the graph represents a computational step, often involving language models or other NLP-related tasks.

How is different from Langchain ?

  • LangGraph allows for the creation of both linear and cyclic workflows, offering greater flexibility for complex or iterative processes.
  • LangChain (with LCEL) is more suited for linear workflows or state machines, where each step follows a sequential path without revisiting previous steps, making it less suited for workflows that require cycles.

Core Components

Nodes

Nodes in LangGraph are individual tasks or steps within a workflow, each representing a specific computation or operation that processes data. They are connected by edges, which define dependencies, allowing for the sequential or parallel execution of tasks based on the graph’s structure.

Edges

Edges in LangGraph represent the dependencies between nodes, defining the order in which tasks should be executed. They ensure that a node only processes data after its prerequisite nodes have completed, allowing for controlled, sequential, or parallel execution within the workflow.

Conditional Edges

Conditional edges in LangGraph are specialized edges that dictate the execution of a node based on the outcome or conditions of its preceding nodes. They enable dynamic workflows, where a node only executes if specific criteria or conditions are met, allowing for more flexible and adaptive processing.

State Schemas

State Schemas in LangGraph define the possible states a node or process can be in during its execution, along with the transitions between these states based on specific conditions or events. They help manage the flow of a workflow by outlining how and when a node can move from one state to another, ensuring structured and controlled execution within the graph.

Reducers

Reducers in LangGraph are functions that aggregate or combine data from multiple nodes or steps in a workflow. They are used to process and condense the output from various sources into a single result, often playing a crucial role in summarizing or merging data as it moves through the workflow.

Cyclic Graph

A cyclic graph in LangGraph refers to a graph structure where nodes are connected in such a way that it’s possible to return to the starting node, creating loops or cycles. This allows for iterative processes or repeated execution of certain tasks within the workflow, enabling more complex and dynamic behavior compared to a standard directed acyclic graph (DAG).

Human in the loop

“Human in the loop” refers to a process where human input, oversight, or intervention is integrated into automated workflows or decision-making systems. It ensures that critical decisions, particularly those involving complex or nuanced tasks, are guided or validated by human judgment, combining the strengths of both human expertise and machine efficiency.

Persistence

Persistence in LangGraph refers to the capability of saving the state and progress of a workflow, allowing the graph and its data to be stored and later resumed or analyzed. This ensures that workflows can be paused, recovered, or revisited, maintaining continuity and reliability across sessions or executions.

Now that we have listed some of the core concepts of LangGraph, we should be ready to delve into some of the details in the next parts.

--

--