Home / Function/ get_graph() — langchain Function Reference

get_graph() — langchain Function Reference

Architecture documentation for the get_graph() function in base.py from the langchain codebase.

Function python LangChainCore Runnables calls 3 called by 2

Entity Profile

Dependency Diagram

graph TD
  4b92cace_dc70_6808_9c96_2880d0125ea4["get_graph()"]
  c6a370e4_a02a_c56a_38eb_7ca734dcbfea["RunnableLambda"]
  4b92cace_dc70_6808_9c96_2880d0125ea4 -->|defined in| c6a370e4_a02a_c56a_38eb_7ca734dcbfea
  dd68934b_b24b_922a_dfc2_d96ad2d88349["get_graph()"]
  dd68934b_b24b_922a_dfc2_d96ad2d88349 -->|calls| 4b92cace_dc70_6808_9c96_2880d0125ea4
  02aad921_a64b_2634_7ea3_1d94d9918fc3["get_graph()"]
  02aad921_a64b_2634_7ea3_1d94d9918fc3 -->|calls| 4b92cace_dc70_6808_9c96_2880d0125ea4
  7866ea60_3af0_a9b8_ebab_618c759e89c8["get_input_schema()"]
  4b92cace_dc70_6808_9c96_2880d0125ea4 -->|calls| 7866ea60_3af0_a9b8_ebab_618c759e89c8
  1ca1316b_add2_5905_2c2a_ffd20e4c42c7["get_output_schema()"]
  4b92cace_dc70_6808_9c96_2880d0125ea4 -->|calls| 1ca1316b_add2_5905_2c2a_ffd20e4c42c7
  3fc77054_a9db_4f51_31ed_c1057170c9d7["get_graph()"]
  4b92cace_dc70_6808_9c96_2880d0125ea4 -->|calls| 3fc77054_a9db_4f51_31ed_c1057170c9d7
  style 4b92cace_dc70_6808_9c96_2880d0125ea4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/runnables/base.py lines 4795–4822

    def get_graph(self, config: RunnableConfig | None = None) -> Graph:
        if deps := self.deps:
            # Import locally to prevent circular import
            from langchain_core.runnables.graph import Graph  # noqa: PLC0415

            graph = Graph()
            input_node = graph.add_node(self.get_input_schema(config))
            output_node = graph.add_node(self.get_output_schema(config))
            for dep in deps:
                dep_graph = dep.get_graph()
                dep_graph.trim_first_node()
                dep_graph.trim_last_node()
                if not dep_graph:
                    graph.add_edge(input_node, output_node)
                else:
                    dep_first_node, dep_last_node = graph.extend(dep_graph)
                    if not dep_first_node:
                        msg = f"Runnable {dep} has no first node"
                        raise ValueError(msg)
                    if not dep_last_node:
                        msg = f"Runnable {dep} has no last node"
                        raise ValueError(msg)
                    graph.add_edge(input_node, dep_first_node)
                    graph.add_edge(dep_last_node, output_node)
        else:
            graph = super().get_graph(config)

        return graph

Domain

Subdomains

Frequently Asked Questions

What does get_graph() do?
get_graph() is a function in the langchain codebase, defined in libs/core/langchain_core/runnables/base.py.
Where is get_graph() defined?
get_graph() is defined in libs/core/langchain_core/runnables/base.py at line 4795.
What does get_graph() call?
get_graph() calls 3 function(s): get_graph, get_input_schema, get_output_schema.
What calls get_graph()?
get_graph() is called by 2 function(s): get_graph, get_graph.

Analyze Your Own Codebase

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

Try Supermodel Free