LangGraph Introduced SubGraphs

Recently LangChain introduced LangGraph for creating & managing state. A natural progression is the creation of sub-graphs for more complex scenarios.

Cobus Greyling
4 min readJul 30, 2024

--

Introduction

From a conversational UI design and development perspective, we have come to know the approach of representing conversation flows as graph data, with nodes and edges. Even-though a graph approach is commonly used, the underlying principles might not be that well known; read more about it here.

The image below illustrates the typical design and development user interface (UI) for creating dialog and process flows in a Conversational UI.

This design interface comprises two main components: nodes and edges.

Nodes, also known as assets, are the blocks seen on the design canvas. In the image, there are five nodes.

Edges, the links between nodes, indicate the possible destination nodes, showing the flow from one node to another.

SubDialogs

The idea of sub-dialogs have been around for quite a while; VoiceXML 2.1 introduced the idea of sub-dialogs in VXML as a routine which can be called and state returned to the node from where the sub-dialog was invoked.

LangGraph SubGraphs

The scenario given by LangChain in the documentation, is one where a system accepts logs and performs two separate sub-tasks.

First, it summarises the logs.

Second, it summarises any failure modes captured in the logs.

These two operations are performed in different sub-graphs.

The key aspect is the information transfer between the graphs:

  1. The Entry Graph serves as the parent,
  2. With each sub-graph defined as a node within it.
  3. Both sub-graphs inherit state from the parent Entry Graph, allowing access to documents in each sub-graph by specifying them in the sub-graph state.
  4. Each sub-graph can also maintain its own private state. Any values that need to be propagated back to the parent Entry Graph (for final reporting) are defined in the Entry Graph state (e.g., summary report and failure report).

Conclusion

The implementation of LangGraph by LangChain is an approach were the node and edge structure are created by means of code.

The node and edge structure can be visualised once defined in the code. The code cannot be updated by making changes to the visual representation.

Via LangGraph Studio the visual representation of the graph can be viewed & manipulated by moving the nodes and setting break points.

The sub-graph functionality of langGraph is not to be confused with the parallel execution feature.

LangGraph is framework-agnostic, with each node functioning as a regular Python function.

It extends the core Runnable API (a shared interface for streaming, async, and batch calls) to facilitate:

  1. Seamless state management across multiple conversation turns or tool usages.
  2. Flexible routing between nodes based on dynamic criteria
  3. Smooth transitions between LLMs and human intervention
  4. Persistence for long-running, multi-session applications

✨ ✨Follow me on LinkedIn for updates on Large Language Models

I’m currently the Chief Evangelist @ Kore AI. I explore & write about all things at the intersection of AI & language; ranging from LLMs, Chatbots, Voicebots, Development Frameworks, Data-Centric latent spaces & more.

LinkedIn

--

--

Cobus Greyling
Cobus Greyling

Written by Cobus Greyling

I’m passionate about exploring the intersection of AI & language. www.cobusgreyling.com

No responses yet