Home / Class/ RouterChain Class — langchain Architecture

RouterChain Class — langchain Architecture

Architecture documentation for the RouterChain class in base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  8c933306_16e9_7f72_a392_80e52d7a7371["RouterChain"]
  f3cef70e_11b0_61c9_7ec0_7308f4b45056["Chain"]
  8c933306_16e9_7f72_a392_80e52d7a7371 -->|extends| f3cef70e_11b0_61c9_7ec0_7308f4b45056
  3d5ca688_b19a_893f_4a6b_4798a6f7566d["base.py"]
  8c933306_16e9_7f72_a392_80e52d7a7371 -->|defined in| 3d5ca688_b19a_893f_4a6b_4798a6f7566d
  892a0ff8_2d4b_e003_39e3_763ec6dffbdc["output_keys()"]
  8c933306_16e9_7f72_a392_80e52d7a7371 -->|method| 892a0ff8_2d4b_e003_39e3_763ec6dffbdc
  5d25b120_ec51_3b5f_5c80_bc6802d11e97["route()"]
  8c933306_16e9_7f72_a392_80e52d7a7371 -->|method| 5d25b120_ec51_3b5f_5c80_bc6802d11e97
  bd76877b_841c_bc52_2869_3c7d3fa3da4c["aroute()"]
  8c933306_16e9_7f72_a392_80e52d7a7371 -->|method| bd76877b_841c_bc52_2869_3c7d3fa3da4c

Relationship Graph

Source Code

libs/langchain/langchain_classic/chains/router/base.py lines 27–63

class RouterChain(Chain, ABC):
    """Chain that outputs the name of a destination chain and the inputs to it."""

    @property
    @override
    def output_keys(self) -> list[str]:
        return ["destination", "next_inputs"]

    def route(self, inputs: dict[str, Any], callbacks: Callbacks = None) -> Route:
        """Route inputs to a destination chain.

        Args:
            inputs: inputs to the chain
            callbacks: callbacks to use for the chain

        Returns:
            a Route object
        """
        result = self(inputs, callbacks=callbacks)
        return Route(result["destination"], result["next_inputs"])

    async def aroute(
        self,
        inputs: dict[str, Any],
        callbacks: Callbacks = None,
    ) -> Route:
        """Route inputs to a destination chain.

        Args:
            inputs: inputs to the chain
            callbacks: callbacks to use for the chain

        Returns:
            a Route object
        """
        result = await self.acall(inputs, callbacks=callbacks)
        return Route(result["destination"], result["next_inputs"])

Extends

Frequently Asked Questions

What is the RouterChain class?
RouterChain is a class in the langchain codebase, defined in libs/langchain/langchain_classic/chains/router/base.py.
Where is RouterChain defined?
RouterChain is defined in libs/langchain/langchain_classic/chains/router/base.py at line 27.
What does RouterChain extend?
RouterChain extends Chain.

Analyze Your Own Codebase

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

Try Supermodel Free