tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Agentic AI > LangGraph > LangGraph Subgraphs and Modular Agent Design

LangGraph Subgraphs and Modular Agent Design

Author: Venkata Sudhakar

LangGraph subgraphs let you decompose a complex agent into self-contained modules, each with its own state and nodes. The parent graph treats each subgraph as a single node, calling it as a black box. For ShopMax India, you might build separate subgraphs for order lookup, product recommendation, and complaint handling, then wire them together in a routing parent graph.

A subgraph is simply a compiled StateGraph that is added to the parent graph using add_node. The parent passes its state into the subgraph, which processes it and returns an updated state. The key requirement is that the subgraph's input and output state schema must be compatible with the parent's state schema - shared keys are passed through automatically.

The following example shows a parent graph with two subgraphs: one that looks up order status and one that handles refund requests for ShopMax India customers.


It gives the following output,

Order SM-99021 is out for delivery in Bangalore. ETA: 2 hours.
Refund of Rs 2,499 initiated. It will reflect in your account within 5-7 business days.

Subgraphs are reusable - you can include the same compiled subgraph in multiple parent graphs. Each subgraph can also have its own checkpointer for independent persistence. This modular design makes ShopMax India's agent system easier to test in isolation, update independently, and scale by running subgraphs in parallel when needed.


 
  


  
bl  br