Home / Function/ add_subgraph() — langchain Function Reference

add_subgraph() — langchain Function Reference

Architecture documentation for the add_subgraph() function in graph_png.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  6d25c928_1947_3d19_99bb_13bb0058b41d["add_subgraph()"]
  5a670bac_6993_ecfd_ad71_f79187c3df76["PngDrawer"]
  6d25c928_1947_3d19_99bb_13bb0058b41d -->|defined in| 5a670bac_6993_ecfd_ad71_f79187c3df76
  80a735b5_4997_c6b1_cea7_cd7a0638ba48["draw()"]
  80a735b5_4997_c6b1_cea7_cd7a0638ba48 -->|calls| 6d25c928_1947_3d19_99bb_13bb0058b41d
  style 6d25c928_1947_3d19_99bb_13bb0058b41d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/runnables/graph_png.py lines 166–190

    def add_subgraph(
        self,
        viz: Any,
        nodes: list[list[str]],
        parent_prefix: list[str] | None = None,
    ) -> None:
        """Add subgraphs to the graph.

        Args:
            viz: The graphviz object.
            nodes: The nodes to add.
            parent_prefix: The prefix of the parent subgraph.
        """
        for prefix, grouped in groupby(
            [node[:] for node in sorted(nodes)],
            key=lambda x: x.pop(0),
        ):
            current_prefix = (parent_prefix or []) + [prefix]
            grouped_nodes = list(grouped)
            if len(grouped_nodes) > 1:
                subgraph = viz.add_subgraph(
                    [":".join(current_prefix + node) for node in grouped_nodes],
                    name="cluster_" + ":".join(current_prefix),
                )
                self.add_subgraph(subgraph, grouped_nodes, current_prefix)

Domain

Subdomains

Called By

Frequently Asked Questions

What does add_subgraph() do?
add_subgraph() is a function in the langchain codebase, defined in libs/core/langchain_core/runnables/graph_png.py.
Where is add_subgraph() defined?
add_subgraph() is defined in libs/core/langchain_core/runnables/graph_png.py at line 166.
What calls add_subgraph()?
add_subgraph() is called by 1 function(s): draw.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free